[opencms-dev] Problems with form-based login
JasDA at web.de
JasDA at web.de
Mon Dec 10 15:49:41 CET 2007
Hi,
I want to switch the authentication method of my OpenCMS installation to a form based login. Within the CMS one default site is created.
The admin area is called with:
http://servername:8080/opencms/opencms/system/login/index.html
The default site with:
http://servername:8080/opencms/opencms/
To switch to a form based login I changed the opencms-system.xml to:
<http-authentication>
<browser-based>false</browser-based>
<form-based>/system/login/index.html</form-based>
</http-authentication>
This index.html looks like:
<%@
page session="true"
import="org.opencms.main.*, org.opencms.jsp.*,org.opencms.file.*, java.lang.String"
%>
<%
CmsJspActionElement cms = new CmsJspActionElement(pageContext,request,response);
String user = request.getParameter("user");
String password = request.getParameter("password");
String url = request.getParameter("url");
if(url==null || url.length()==0 || url.equalsIgnoreCase("null")) url = "";
boolean loginFailed = false;
//form was submitted => try to log in and redirect to given URl
if((user != null) && (user.length() != 0)) {
try{
CmsObject cmsObject = cms.getCmsObject();
cmsObject.loginUser(user, password);
CmsProject cmsproject = cmsObject.readProject("Offline");
cmsObject.getRequestContext().setCurrentProject(cmsproject);
cmsObject.getRequestContext().setSiteRoot("/sites/default/");
//login successful - redirect to given URL
response.sendRedirect(url);
} catch ( CmsException e ) {
loginFailed = true;
}
}
%>
<%
//no user submitted or login failed => show login form
if(user==null || user.length()==0 || loginFailed) {
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<title>Frontend login</title>
</head>
<body onload="document.forms[0].elements[0].focus()">
<%
if (loginFailed) {
%>
<em>Login failed!</em>
<%
}
%>
<h1>please login:</h1>
<form method="post" action="<%=cms.info("opencms.url")%>">
<input type="hidden" name="url" value="<%=url%>" />
<p>username: <input name="user" /></p>
<p>password: <input name="password" type="password" /></p>
<p><input type="submit" /></p>
</form>
</body>
</html>
<%
}
%>
If I try this version I get an browser error, that the request could not be finished. Can anyone please help me?
Regards,
Jason
_______________________________________________________________________
Jetzt neu! Schützen Sie Ihren PC mit McAfee und WEB.DE. 3 Monate
kostenlos testen. http://www.pc-sicherheit.web.de/startseite/?mc=022220
More information about the opencms-dev
mailing list