Implement the Serviceable interface. It forces you to implement the
service() method, where you get a ServiceManager instance passed. You
can store this in an instance var:

Public class MyAuthenticator implements Authenticator, Serviceable {

  Private ServiceManager manager;

...
  public void service(ServiceManager manager) throws ServiceException {
    this.manager = manager;
  }
}

Between instantiation of your authenticator, and calling one of the
Authenticator's interface methods, the "Cocoon system" will call the
service() method. Take a look at the
org.apache.cocoon.webapps.authentication.components.PipelineAuthenticato
r class for example.

Bart.
> -----Original Message-----
> From: Martin Rusnak [mailto:[EMAIL PROTECTED]
> Sent: Tuesday, September 21, 2004 3:32 PM
> To: [EMAIL PROTECTED]
> Subject: Re: Database connection from custom Authenticator class
> 
> > Do a lookup with a service manager:
> >
> >
manager.lookup(org.apache.avalon.excalibur.datasource.DataSourceComponen
> > t.ROLE + "Selector");
> 
> But I don't have a reference to the service manager, at least I don't
know
> how to get it. Here is MyAuthenticator class code:
> 
> public class MyAuthenticator implements Authenticator {
> 
>       public AuthenticationResult authenticate(
>               HandlerConfiguration configuration, SourceParameters
> parameters)
>       throws ProcessingException {
> 
>               String userID = parameters.getParameter("userid");
>               String password = parameters.getParameter("password");
>               Connection conn = null;
>               CallableStatement cstmt = null;
>               ResultSet rs = null;
> 
>               try {
>                       // here comes the SQL query
>                       if( /* wrong credentials */ )
>                               return new AuthenticationResult(false,
null);
>               } finally {
>                       try{
>                               if(rs != null)rs.close();
>                               if(cstmt != null)cstmt.close();
>                               if(conn != null)conn.close();
>                       } catch(Exception e) {
>                               // getLogger().error("Could not close DB
> connection", e);
>                       }
>               }
> 
> 
>               // Create authentication XML tree
>               Document doc = DOMUtil.createDocument();
>               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) {
>       }
> }
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to