[opencms-dev] form based auth

Jeff Greer jgreer at fdusa.com
Mon Apr 26 16:34:00 CEST 2004


Jan,

Here is my login.jsp that I include as a standard include in my commonly shared page template.




<%@ page session="true" %>
<%@ page import="java.util.*,com.opencms.core.*,org.opencms.jsp.*,org.opencms.file.*" %>
<%@ taglib prefix="cms" uri="http://www.opencms.org/taglib/cms" %>

<%
	CmsJspActionElement cms = new CmsJspActionElement(pageContext, request, response);
	CmsObject cmso = cms.getCmsObject();

	String username = request.getParameter("username");
	String password = request.getParameter("password");
	String logout = request.getParameter("logout");
	String login = request.getParameter("login");

	if("logout".equals(logout))
	{
		session.invalidate();
		cmso.loginUser("Guest", "");
		cms = new CmsJspActionElement(pageContext, request, response);
	}
	else if("login".equals(login))
	{
		try
		{
			cmso.loginUser(username, password);
			cms = new CmsJspActionElement(pageContext, request, response);
		}
		catch(org.opencms.security.CmsSecurityException e)
		{
			out.println("login failed<br>" + e.getMessage());
		}
	}

	out.println("<p align=\"center\" class=\"login\">User: " + cms.user("name") + "</p>");

	String form = "<form method=\"POST\">";

	if(cms.user("name").equals("Guest"))
	{
		form += "<table class=\"login\"><tr><td align=\"right\">" +
			"<label for=\"username\">User:</label><br>" +
			"<input type=\"text\" id=\"username\" name=\"username\" size=\"9\"><br>" +
			"<label for=\"username\">Password:</label><br>" +
			"<input type=\"password\" id=\"password\" name=\"password\" size=\"9\">" +
			"</td></tr><tr><td align=\"right\">" +
			"<input type=\"submit\" name=\"login\" value=\"login\"></td></tr></table>";
	}
	else
	{
		form += "<input type=\"submit\" name=\"logout\" value=\"logout\">";
	}
	form += "</form>";
	out.println(form);
%>


Jan Heise said:
> hi again,
>
> somehow the NPE disappeared and the auth-page is shown but now
> the question remains: where do i post the form to and how are the
> parameters named?
>
> tia,
>
> jan
>
> Am 18.04.2004 um 19:07 schrieb Jan Heise:
>
>> hi all,
>>
>> i'm trying to set up form based auth with opencms. i secured a page and got basic auth working. after changing the
>> conf in opencms.properties   to
>> use form based auth, all i get is a NPE:
>>
>> com.opencms.core.CmsException: 0 Unknown exception. Detailed error:   [com.opencms.file.mySql.CmsDbAccess].
>> root cause was java.lang.NullPointerException
>> 	at
>> com.opencms.file.genericSql.CmsDbAccess.readUser(CmsDbAccess.java:  10307)
>> 	at
>> com.opencms.file.genericSql.CmsResourceBroker.loginWebUser(CmsResourceB  roker.java:4502)
>> 	at com.opencms.file.CmsObject.loginWebUser(CmsObject.java:2342) at
>> com.opencms.core.OpenCmsHttpServlet.initUser(OpenCmsHttpServlet.java:  571)
>> 	at
>> com.opencms.core.OpenCmsHttpServlet.doGet(OpenCmsHttpServlet.java:304)
>> 	at javax.servlet.http.HttpServlet.service(HttpServlet.java:740) at
>> javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
>>
>> my auth.html is _not_shown. it looks like opencms is trying to log in   a user
>> even before showing the auth.html. i also did not find any info on how   i have
>> to write the auth.html (how do i have to name the fields? where do i   have to
>> post the form to?)
>>
>> tia, jan


-- 
Jeff Greer
Technical Support Consultant
Fretwell-Downing, Inc.
Phone: (913) 239-1214

The information transmitted in this electronic mail message may contain
confidential and or privileged materials.  For full details and restrictions
see http://www.fdgroup.com/emaildisclaimer.html






More information about the opencms-dev mailing list