You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by cz...@apache.org on 2003/05/01 11:49:14 UTC

cvs commit: cocoon-2.1/src/blocks/authentication-fw/java/org/apache/cocoon/webapps/authentication AuthenticationManager.java

cziegeler    2003/05/01 02:49:14

  Modified:    src/blocks/authentication-fw/java/org/apache/cocoon/webapps/authentication/user
                        UserHandler.java
               src/blocks/authentication-fw/java/org/apache/cocoon/webapps/authentication/context
                        AuthenticationContext.java
                        AuthenticationContextProvider.java
               src/blocks/authentication-fw/java/org/apache/cocoon/webapps/authentication/components
                        Manager.java DefaultAuthenticationManager.java
                        Authenticator.java
               src/blocks/authentication-fw/java/org/apache/cocoon/webapps/authentication/acting
                        NewLoggedInAction.java NewLoginAction.java
  Removed:     src/blocks/authentication-fw/java/org/apache/cocoon/webapps/authentication
                        AuthenticationManager.java
  Log:
  Bug fixes for refactored authentication framework
  
  Revision  Changes    Path
  1.3       +2 -2      cocoon-2.1/src/blocks/authentication-fw/java/org/apache/cocoon/webapps/authentication/user/UserHandler.java
  
  Index: UserHandler.java
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/blocks/authentication-fw/java/org/apache/cocoon/webapps/authentication/user/UserHandler.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- UserHandler.java	27 Apr 2003 14:45:03 -0000	1.2
  +++ UserHandler.java	1 May 2003 09:49:14 -0000	1.3
  @@ -103,7 +103,7 @@
       }
   
       public AuthenticationContext createContext() {
  -        this.context = new AuthenticationContext();
  +        this.context = new AuthenticationContext(this);
           return this.context;                                                  
       }
       
  
  
  
  1.3       +19 -8     cocoon-2.1/src/blocks/authentication-fw/java/org/apache/cocoon/webapps/authentication/context/AuthenticationContext.java
  
  Index: AuthenticationContext.java
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/blocks/authentication-fw/java/org/apache/cocoon/webapps/authentication/context/AuthenticationContext.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- AuthenticationContext.java	27 Apr 2003 14:45:03 -0000	1.2
  +++ AuthenticationContext.java	1 May 2003 09:49:14 -0000	1.3
  @@ -61,13 +61,13 @@
   import org.apache.cocoon.components.source.SourceUtil;
   import org.apache.cocoon.webapps.authentication.AuthenticationConstants;
   import org.apache.cocoon.webapps.authentication.configuration.ApplicationConfiguration;
  -import org.apache.cocoon.webapps.authentication.user.RequestState;
   import org.apache.cocoon.webapps.authentication.user.UserHandler;
   import org.apache.cocoon.webapps.session.context.SessionContext;
   import org.apache.cocoon.webapps.session.context.SimpleSessionContext;
   import org.apache.cocoon.xml.dom.DOMUtil;
   import org.apache.excalibur.source.SourceParameters;
   import org.apache.excalibur.source.SourceResolver;
  +import org.w3c.dom.Document;
   import org.w3c.dom.DocumentFragment;
   import org.w3c.dom.Node;
   import org.w3c.dom.NodeList;
  @@ -90,21 +90,32 @@
       private SessionContext  authContext;
       private String          handlerName;
       private String          applicationName;
  -
  -    public AuthenticationContext() {
  +    private boolean        initialized;
  +    
  +    public AuthenticationContext(UserHandler handler) {
           this.name = AuthenticationConstants.SESSION_CONTEXT_NAME;
   
  -        RequestState state = RequestState.getState();
  -        this.handler = state.getHandler();
  +        this.handler = handler;
           this.handlerName = this.handler.getHandlerName();
  -        this.applicationName = state.getApplicationName();
           try {
               this.authContext = new SimpleSessionContext();
           } catch (ProcessingException pe) {
               throw new CascadingRuntimeException("Unable to create simple context.", pe);
           }
       }
  -
  +    
  +    public void setApplicationName(String name) {
  +        this.applicationName = name;
  +    }
  +    
  +    public void init(Document doc) 
  +    throws ProcessingException {
  +        if ( initialized ) {
  +            throw new ProcessingException("The context can only be initialized once.");
  +        }
  +        this.authContext.setNode("/", doc.getFirstChild());
  +    }
  +    
       /** Set the name of the context.
        *  This method must be invoked in the init phase.
        *  In addition a load and a save resource can be provided.
  
  
  
  1.2       +3 -3      cocoon-2.1/src/blocks/authentication-fw/java/org/apache/cocoon/webapps/authentication/context/AuthenticationContextProvider.java
  
  Index: AuthenticationContextProvider.java
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/blocks/authentication-fw/java/org/apache/cocoon/webapps/authentication/context/AuthenticationContextProvider.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- AuthenticationContextProvider.java	27 Apr 2003 12:52:53 -0000	1.1
  +++ AuthenticationContextProvider.java	1 May 2003 09:49:14 -0000	1.2
  @@ -84,14 +84,14 @@
                                               SourceResolver   resolver,
                                               ComponentManager manager)
       throws ProcessingException {
  -        SessionContext context = null;
  +        AuthenticationContext context = null;
           if (name.equals(org.apache.cocoon.webapps.authentication.AuthenticationConstants.SESSION_CONTEXT_NAME) ) {
               RequestState state = RequestState.getState();
               if ( null != state ) {
                   UserHandler handler = state.getHandler();
                   if ( handler != null ) {
                       context = handler.getContext();
  -                }
  +                    context.setApplicationName(state.getApplicationName());                }
               }
           }
           return context;
  
  
  
  1.5       +9 -8      cocoon-2.1/src/blocks/authentication-fw/java/org/apache/cocoon/webapps/authentication/components/Manager.java
  
  Index: Manager.java
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/blocks/authentication-fw/java/org/apache/cocoon/webapps/authentication/components/Manager.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- Manager.java	27 Apr 2003 12:52:53 -0000	1.4
  +++ Manager.java	1 May 2003 09:49:14 -0000	1.5
  @@ -54,6 +54,7 @@
   
   import org.apache.cocoon.ProcessingException;
   import org.apache.cocoon.environment.Redirector;
  +import org.apache.cocoon.webapps.authentication.user.UserHandler;
   import org.apache.excalibur.source.SourceParameters;
   
   
  @@ -74,9 +75,9 @@
   
       /**
        * Is the current user authenticated for the given handler?
  -     * @return Returns true of the user is authenticated.
  +     * @return Returns the corresponding handler if the user is authenticated.
        */
  -    boolean isAuthenticated(String handlerName)
  +    UserHandler isAuthenticated(String handlerName)
       throws ProcessingException;
   
       /**
  @@ -91,12 +92,12 @@
   
       /**
        * Try to login the user.
  -     * If the authentication is successful, <code>true</code> is returned.
  -     * If not, <code>false</code> is returned.
  +     * If the authentication is successful, the user handler is returned.
  +     * If not, <code>null</code> is returned.
        */
  -    boolean login(String              handlerName,
  -                   String              applicationName,
  -                   SourceParameters    parameters)
  +    UserHandler login(String              handlerName,
  +                      String              applicationName,
  +                      SourceParameters    parameters)
       throws ProcessingException;
   
       /**
  
  
  
  1.7       +11 -9     cocoon-2.1/src/blocks/authentication-fw/java/org/apache/cocoon/webapps/authentication/components/DefaultAuthenticationManager.java
  
  Index: DefaultAuthenticationManager.java
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/blocks/authentication-fw/java/org/apache/cocoon/webapps/authentication/components/DefaultAuthenticationManager.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- DefaultAuthenticationManager.java	27 Apr 2003 14:45:04 -0000	1.6
  +++ DefaultAuthenticationManager.java	1 May 2003 09:49:14 -0000	1.7
  @@ -111,8 +111,8 @@
       static {
           // add the provider for the authentication context
           AuthenticationContextProvider contextProvider = new AuthenticationContextProvider();
  -        // TODO
  -/*        try {
  +        // FIXME - TODO
  +   /*     try {
               // FIXME - this is static!!!
               SessionManager.addSessionContextProvider(contextProvider, AuthenticationConstants.SESSION_CONTEXT_NAME);
           } catch (ProcessingException local) {
  @@ -213,9 +213,9 @@
   	/* (non-Javadoc)
   	 * @see org.apache.cocoon.webapps.authentication.components.Manager#authenticate(java.lang.String, java.lang.String, org.apache.excalibur.source.SourceParameters)
   	 */
  -	public boolean login(String handlerName,
  -                           String applicationName,
  -                           SourceParameters parameters)
  +	public UserHandler login(String handlerName,
  +                             String applicationName,
  +                             SourceParameters parameters)
       throws ProcessingException {
           HandlerConfiguration config = this.getHandlerConfiguration( handlerName );
           if ( config == null ) {
  @@ -240,9 +240,11 @@
               // update RequestState
               RequestState state = new RequestState( handler, applicationName, this.resolver );
               RequestState.setState( state );
  +            
  +            handler.getContext().setApplicationName( applicationName );
           }
           
  - 		return (handler != null);
  + 		return handler;
   	}
   
   	/* (non-Javadoc)
  @@ -284,9 +286,9 @@
   	/* (non-Javadoc)
   	 * @see org.apache.cocoon.webapps.authentication.components.Manager#isAuthenticated(java.lang.String)
   	 */
  -	public boolean isAuthenticated(String handlerName)
  +	public UserHandler isAuthenticated(String handlerName)
       throws ProcessingException {
  -        return ( this.getUserHandler( handlerName ) != null);
  +        return this.getUserHandler( handlerName  );
   	}
   
   	/* (non-Javadoc)
  
  
  
  1.4       +4 -3      cocoon-2.1/src/blocks/authentication-fw/java/org/apache/cocoon/webapps/authentication/components/Authenticator.java
  
  Index: Authenticator.java
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/blocks/authentication-fw/java/org/apache/cocoon/webapps/authentication/components/Authenticator.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- Authenticator.java	27 Apr 2003 14:45:04 -0000	1.3
  +++ Authenticator.java	1 May 2003 09:49:14 -0000	1.4
  @@ -63,6 +63,7 @@
   import org.apache.cocoon.webapps.authentication.MediaManager;
   import org.apache.cocoon.webapps.authentication.configuration.ApplicationConfiguration;
   import org.apache.cocoon.webapps.authentication.configuration.HandlerConfiguration;
  +import org.apache.cocoon.webapps.authentication.context.AuthenticationContext;
   import org.apache.cocoon.webapps.authentication.user.UserHandler;
   import org.apache.cocoon.webapps.session.SessionConstants;
   import org.apache.cocoon.webapps.session.components.SessionManager;
  @@ -216,7 +217,7 @@
                   
                   handler = new UserHandler(configuration);
                   
  -                SessionContext context = handler.getContext();
  +                AuthenticationContext context = handler.createContext();
   
                   MediaManager mediaManager = null;
                   String mediaType;
  @@ -248,7 +249,7 @@
                       authNode.appendChild(specialElement);
   
                       // store the authentication data in the context
  -                    context.setNode("/" + configuration.getName(), doc);
  +                    context.init(doc);
   
                       // And now load applications
                       boolean loaded = true;
  
  
  
  1.2       +5 -5      cocoon-2.1/src/blocks/authentication-fw/java/org/apache/cocoon/webapps/authentication/acting/NewLoggedInAction.java
  
  Index: NewLoggedInAction.java
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/blocks/authentication-fw/java/org/apache/cocoon/webapps/authentication/acting/NewLoggedInAction.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- NewLoggedInAction.java	27 Apr 2003 14:45:03 -0000	1.1
  +++ NewLoggedInAction.java	1 May 2003 09:49:14 -0000	1.2
  @@ -59,7 +59,7 @@
   import org.apache.cocoon.environment.Redirector;
   import org.apache.cocoon.environment.SourceResolver;
   import org.apache.cocoon.webapps.authentication.components.Manager;
  -import org.apache.cocoon.webapps.authentication.user.RequestState;
  +import org.apache.cocoon.webapps.authentication.user.UserHandler;
   
   /**
    *  This action tests if the user is logged in for a given handler.
  @@ -90,9 +90,9 @@
   
           try {
               authManager = (Manager) this.manager.lookup(Manager.ROLE);
  -            if (authManager.isAuthenticated(handlerName) ) {
  -                RequestState state = RequestState.getState();
  -                map = state.getHandler().getContext().getContextInfo();
  +            UserHandler handler = authManager.isAuthenticated(handlerName);
  +            if ( handler != null ) {
  +                map = handler.getContext().getContextInfo();
               }
           } finally {
               this.manager.release( (Component)authManager);
  
  
  
  1.2       +7 -7      cocoon-2.1/src/blocks/authentication-fw/java/org/apache/cocoon/webapps/authentication/acting/NewLoginAction.java
  
  Index: NewLoginAction.java
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/blocks/authentication-fw/java/org/apache/cocoon/webapps/authentication/acting/NewLoginAction.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- NewLoginAction.java	27 Apr 2003 14:45:03 -0000	1.1
  +++ NewLoginAction.java	1 May 2003 09:49:14 -0000	1.2
  @@ -60,7 +60,7 @@
   import org.apache.cocoon.environment.Redirector;
   import org.apache.cocoon.environment.SourceResolver;
   import org.apache.cocoon.webapps.authentication.components.Manager;
  -import org.apache.cocoon.webapps.authentication.user.RequestState;
  +import org.apache.cocoon.webapps.authentication.user.UserHandler;
   import org.apache.excalibur.source.SourceParameters;
   
   /**
  @@ -115,12 +115,12 @@
           Manager authManager = null;
           try {
               authManager = (Manager) this.manager.lookup(Manager.ROLE);
  -            if ( authManager.login( handlerName, 
  -                                    par.getParameter("application", null),
  -                                    authenticationParameters)) {
  +            UserHandler handler = authManager.login( handlerName, 
  +                                       par.getParameter("application", null),
  +                                       authenticationParameters);
  +            if ( handler != null) {
                   // success
  -                RequestState state = RequestState.getState();
  -                map = state.getHandler().getContext().getContextInfo();
  +                map = handler.getContext().getContextInfo();
   
               }
           } finally {