You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by Jonny Pony <jo...@hotmail.com> on 2004/10/21 13:50:06 UTC
Question on Authenticator
Hi,
I want to implemtent my own authentication-class, based on the
Authenticator-class.
I alway get a NullPointerException.
Here my code so far:
...
public class MyAuthenticator implements Authenticator, Serviceable {
private ServiceManager serviceManager;
public void service(ServiceManager manager) throws ServiceException {
this.serviceManager = manager;
}
public AuthenticationResult authenticate(
HandlerConfiguration configuration, SourceParameters parameters)
throws ProcessingException {
String userID = parameters.getParameter("userid");
String password = parameters.getParameter("password");
Connection conn = null;
Statement stmt = null;
ResultSet rs = null;
try {
ServiceSelector dbselector = (ServiceSelector) this.serviceManager
.lookup(DataSourceComponent.ROLE + "Selector");
DataSourceComponent ds = (DataSourceComponent) dbselector
.select("mysql-pool");
Connection con = ds.getConnection();
stmt = con.createStatement();
...
// some sql
stmt.close();
con.close();
if (!success)
return new AuthenticationResult(false, null);
} catch (Exception e) {
} finally {
...
// close everything
}
// since I don't know how to build an XML-tree I copied something I found.
// Create authentication XML tree
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
try {
this.builder = factory.newDocumentBuilder();
} catch (Exception e) {
}
Document doc = builder.newDocument();
Element authElement = doc.createElementNS(null, "authentication");
Element idElement = doc.createElementNS(null, "ID");
Text text = doc.createTextNode(userID);
idElement.appendChild(text);
authElement.appendChild(idElement);
doc.appendChild(authElement);
return new AuthenticationResult(true, doc);
}
public void logout(UserHandler userHandler) {
}
The error message:
java.lang.NullPointerException
cause: java.lang.NullPointerException
stacktrace[hide]
java.lang.NullPointerException
at org.apache.xerces.dom.ElementImpl.normalize(Unknown Source)
at
org.apache.cocoon.webapps.authentication.context.AuthenticationContext.addParametersFromAuthenticationXML(AuthenticationContext.java:716)
at
org.apache.cocoon.webapps.authentication.context.AuthenticationContext.createParameters(AuthenticationContext.java:683)
at
org.apache.cocoon.webapps.authentication.context.AuthenticationContext.getContextInfo(AuthenticationContext.java:746)
at
org.apache.cocoon.webapps.authentication.acting.LoginAction.act(LoginAction.java:87)
at
org.apache.cocoon.components.treeprocessor.sitemap.ActTypeNode.invoke(ActTypeNode.java:119)
at
org.apache.cocoon.components.treeprocessor.AbstractParentProcessingNode.invokeNodes(AbstractParentProcessingNode.java:49)
at
org.apache.cocoon.components.treeprocessor.sitemap.PreparableMatchNode.invoke(PreparableMatchNode.java:130)
at
org.apache.cocoon.components.treeprocessor.AbstractParentProcessingNode.invokeNodes(AbstractParentProcessingNode.java:72)
at
org.apache.cocoon.components.treeprocessor.sitemap.PipelineNode.invoke(PipelineNode.java:126)
...
My guess that the Document I pass is invalid or something like that. Must
the passed xml follow a certain schema?
Is this the right way to produce the xml anyway (and how would it go)?
Other mistakes?
Cheers
jonny
_________________________________________________________________
Nicht lange suchen finden! MSN Suche. http://search.msn.de/ Jetzt testen!
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org
Re: Question on Authenticator
Posted by Scott Yeadon <sc...@anu.edu.au>.
I haven't seen this error before, but here's the code I used (the
PipelineAuthenticator class was what I used as an example, from memory)
- I used the Cocoon DOMUtil to create the auth response, hope it's of
some use :
public class SimpleAuthenticator implements Authenticator, Contextualizable
{
....
....
public AuthenticationResult authenticate(HandlerConfiguration configuration,
SourceParameters parameters)
throws ProcessingException
{
...
....
Document doc = DOMUtil.createDocument();
final Element root = doc.createElementNS(null, "authentication");
AuthenticationResult result;
if (loggedIn == true)
{
doc.appendChild(root);
Element element = doc.createElementNS(null, "ID");
root.appendChild(element);
Text text = doc.createTextNode(userID);
element.appendChild(text);
element = doc.createElementNS(null, "data");
root.appendChild(element);
text = doc.createTextNode("Successful login");
element.appendChild(text);
result = new AuthenticationResult(true, doc);
}
else
{
doc.appendChild(root);
Element element = doc.createElementNS(null, "data");
root.appendChild(element);
Text text = doc.createTextNode("Invalid userid password combination");
element.appendChild(text);
result = new AuthenticationResult(false, doc);
}
return result;
}
...
...
}
Jonny Pony wrote:
> Hi,
>
> I want to implemtent my own authentication-class, based on the
> Authenticator-class.
> I alway get a NullPointerException.
>
> Here my code so far:
>
> ...
> public class MyAuthenticator implements Authenticator, Serviceable {
>
> private ServiceManager serviceManager;
>
> public void service(ServiceManager manager) throws ServiceException {
> this.serviceManager = manager;
> }
>
> public AuthenticationResult authenticate(
> HandlerConfiguration configuration, SourceParameters parameters)
> throws ProcessingException {
>
> String userID = parameters.getParameter("userid");
> String password = parameters.getParameter("password");
> Connection conn = null;
> Statement stmt = null;
> ResultSet rs = null;
>
> try {
>
> ServiceSelector dbselector = (ServiceSelector) this.serviceManager
> .lookup(DataSourceComponent.ROLE + "Selector");
> DataSourceComponent ds = (DataSourceComponent) dbselector
> .select("mysql-pool");
> Connection con = ds.getConnection();
>
> stmt = con.createStatement();
>
> ...
> // some sql
>
> stmt.close();
> con.close();
>
> if (!success)
> return new AuthenticationResult(false, null);
> } catch (Exception e) {
>
> } finally {
> ...
> // close everything
> }
>
> // since I don't know how to build an XML-tree I copied something I
> found.
> // Create authentication XML tree
>
> DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
> try {
> this.builder = factory.newDocumentBuilder();
> } catch (Exception e) {
> }
> Document doc = builder.newDocument();
> Element authElement = doc.createElementNS(null, "authentication");
> Element idElement = doc.createElementNS(null, "ID");
> Text text = doc.createTextNode(userID);
> idElement.appendChild(text);
> authElement.appendChild(idElement);
> doc.appendChild(authElement);
>
> return new AuthenticationResult(true, doc);
> }
>
> public void logout(UserHandler userHandler) {
> }
>
> The error message:
>
>
> java.lang.NullPointerException
>
> cause: java.lang.NullPointerException
>
> stacktrace[hide]
>
> java.lang.NullPointerException
> at org.apache.xerces.dom.ElementImpl.normalize(Unknown Source)
> at
> org.apache.cocoon.webapps.authentication.context.AuthenticationContext.addParametersFromAuthenticationXML(AuthenticationContext.java:716)
>
> at
> org.apache.cocoon.webapps.authentication.context.AuthenticationContext.createParameters(AuthenticationContext.java:683)
>
> at
> org.apache.cocoon.webapps.authentication.context.AuthenticationContext.getContextInfo(AuthenticationContext.java:746)
>
> at
> org.apache.cocoon.webapps.authentication.acting.LoginAction.act(LoginAction.java:87)
>
> at
> org.apache.cocoon.components.treeprocessor.sitemap.ActTypeNode.invoke(ActTypeNode.java:119)
>
> at
> org.apache.cocoon.components.treeprocessor.AbstractParentProcessingNode.invokeNodes(AbstractParentProcessingNode.java:49)
>
> at
> org.apache.cocoon.components.treeprocessor.sitemap.PreparableMatchNode.invoke(PreparableMatchNode.java:130)
>
> at
> org.apache.cocoon.components.treeprocessor.AbstractParentProcessingNode.invokeNodes(AbstractParentProcessingNode.java:72)
>
> at
> org.apache.cocoon.components.treeprocessor.sitemap.PipelineNode.invoke(PipelineNode.java:126)
>
> ...
>
>
> My guess that the Document I pass is invalid or something like that.
> Must the passed xml follow a certain schema?
> Is this the right way to produce the xml anyway (and how would it go)?
> Other mistakes?
>
>
> Cheers
> jonny
>
> _________________________________________________________________
> Nicht lange suchen – finden! MSN Suche. http://search.msn.de/ Jetzt
> testen!
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
> For additional commands, e-mail: users-help@cocoon.apache.org
>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org