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/04/21 21:26:16 UTC

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

cziegeler    2003/04/21 12:26:15

  Modified:    src/blocks/authentication-fw/java/org/apache/cocoon/webapps/authentication/components
                        DefaultHandlerManager.java Manager.java
                        DefaultAuthenticationManager.java
  Added:       src/blocks/authentication-fw/java/org/apache/cocoon/webapps/authentication/components
                        HandlerConfiguration.java Status.java
                        DefaultMediaManager.java
                        ApplicationConfiguration.java UserHandler.java
                        UserStatus.java
               src/blocks/authentication-fw/java/org/apache/cocoon/webapps/authentication
                        MediaManager.java AuthenticationManager.java
  Log:
  Start of refactoring the authentication framework
  
  Revision  Changes    Path
  1.2       +52 -158   cocoon-2.1/src/blocks/authentication-fw/java/org/apache/cocoon/webapps/authentication/components/DefaultHandlerManager.java
  
  Index: DefaultHandlerManager.java
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/blocks/authentication-fw/java/org/apache/cocoon/webapps/authentication/components/DefaultHandlerManager.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- DefaultHandlerManager.java	20 Mar 2003 15:27:05 -0000	1.1
  +++ DefaultHandlerManager.java	21 Apr 2003 19:26:14 -0000	1.2
  @@ -50,6 +50,7 @@
   */
   package org.apache.cocoon.webapps.authentication.components;
   
  +import java.util.Collections;
   import java.util.HashMap;
   import java.util.Map;
   
  @@ -59,107 +60,95 @@
   import org.apache.cocoon.components.ChainedConfiguration;
   import org.apache.cocoon.components.SitemapConfigurationHolder;
   import org.apache.cocoon.environment.ObjectModelHelper;
  -import org.apache.cocoon.environment.Request;
  -import org.apache.cocoon.environment.Session;
   import org.apache.excalibur.source.SourceResolver;
   
   
   /**
    *  This is a utility class managing the authentication handlers
    *
  - * @author <a href="mailto:cziegeler@s-und-n.de">Carsten Ziegeler</a>
  + * @author <a href="mailto:cziegeler@apache.org">Carsten Ziegeler</a>
    * @version CVS $Id$
   */
   public final class DefaultHandlerManager {
   
  -    /** The name of the session attribute storing the handler configuration */
  -    private final static String SESSION_ATTRIBUTE_HANDLERS = "org.apache.cocoon.webapps.authentication.Handlers";
  -
  -    /** Sitemap configuration holder */
  -    private SitemapConfigurationHolder holder;
  -    
  -    /** SourceResolver */
  -    private SourceResolver resolver;
  -    
  -    /** Request */
  -    private Request request;
  -    
  -    /** The handlers of the current user */
  -    private Map userHandlers;
  -
  -    /**
  -     * Constructor
  -     */
  -    public DefaultHandlerManager(SitemapConfigurationHolder holder) {
  -        this.holder = holder;
  -    }
  -
  -    public void setup(SourceResolver resolver,
  -                        Map           objectModel) {
  -        this.resolver = resolver;
  -        this.request = ObjectModelHelper.getRequest( objectModel );
  -    }
  -
       /**
  -     * Return a list of handlers
  +     * Get the current handler configuration
        */
  -    private Map currentHandlers() 
  +    static public Map prepareHandlerConfiguration(SourceResolver resolver,
  +                                                       Map            objectModel,
  +                                                       SitemapConfigurationHolder holder)
       throws ConfigurationException {
  -        Map handlers = (Map)this.holder.getPreparedConfiguration();
  -        if ( null == handlers ) {
  -            ChainedConfiguration conf = this.holder.getConfiguration();
  -            if ( null != conf ) {
  -                handlers = new HashMap(5);
  -                this.prepare(conf, handlers);
  -                this.holder.setPreparedConfiguration( conf, handlers );
  -            }
  +        Map configs = (Map)holder.getPreparedConfiguration();
  +        if ( null == configs ) {
  +            ChainedConfiguration chainedConfig = holder.getConfiguration();
  +            configs = prepare( resolver, objectModel, holder, chainedConfig );
           }
  -        return handlers;
  +        return configs;
       }
  -    
       /**
        * Prepare the handler configuration
        */
  -    private void prepare(ChainedConfiguration conf, 
  -                           Map values) 
  +    static private Map prepare(SourceResolver resolver,
  +                                 Map            objectModel,
  +                                 SitemapConfigurationHolder holder,
  +                                 ChainedConfiguration conf) 
       throws ConfigurationException {
  -        final ChainedConfiguration parent = conf.getParent();
  -        if ( null != parent ) {
  -            this.prepare( parent, values );
  -        }
           // test for handlers
  +        boolean found = false;
  +        Configuration[] handlers = null;
           Configuration handlersWrapper = conf.getChild("handlers", false);
           if ( null != handlersWrapper ) {
  -            Configuration[] handlers = handlersWrapper.getChildren("handler");
  -            if ( null != handlers ) {
  +            handlers = handlersWrapper.getChildren("handler");
  +            if ( null != handlers && handlers.length > 0) {
  +                found = true;
  +            }
  +        }
   
  -                for(int i=0; i<handlers.length;i++) {
  -                    // check unique name
  -                    final String name = handlers[i].getAttribute("name");
  -                    if ( null != values.get(name) ) {
  -                        throw new ConfigurationException("Handler names must be unique: " + name);
  -                    }
  +        Map values = null;
  +        final ChainedConfiguration parent = conf.getParent();
  +        if ( null != parent ) {
  +            values = prepare( resolver, objectModel, holder, parent );
  +            if ( found ) {
  +                values = new HashMap( values );
  +            }
  +        } else if ( found ){
  +            values = new HashMap(10);
  +        } else {
  +            values = Collections.EMPTY_MAP;
  +        }
   
  -                    this.addHandler( handlers[i], values );
  +        if ( found ) {
  +            for(int i=0; i<handlers.length;i++) {
  +                // check unique name
  +                final String name = handlers[i].getAttribute("name");
  +                if ( null != values.get(name) ) {
  +                    throw new ConfigurationException("Handler names must be unique: " + name);
                   }
  +
  +                addHandler( resolver, objectModel, handlers[i], values );
               }
           }
  +        holder.setPreparedConfiguration( conf, values );
  +        
  +        return values;
       }
   
       /**
        * Add one handler configuration
        */
  -    private void addHandler(Configuration configuration,
  -                              Map            values)
  +    static private void addHandler(SourceResolver resolver,
  +                                     Map            objectModel,
  +                                     Configuration  configuration,
  +                                     Map            values)
       throws ConfigurationException {
           // get handler name
           final String name = configuration.getAttribute("name");
   
           // create handler
  -        Handler currentHandler = new Handler(name);
  +        HandlerConfiguration currentHandler = new HandlerConfiguration(name);
   
           try {
  -            currentHandler.configure(this.resolver, this.request, configuration);
  +            currentHandler.configure(resolver, ObjectModelHelper.getRequest(objectModel), configuration);
           } catch (ProcessingException se) {
               throw new ConfigurationException("Exception during configuration of handler: " + name, se);
           } catch (org.xml.sax.SAXException se) {
  @@ -170,100 +159,5 @@
           values.put( name, currentHandler );
       }
   
  -    /**
  -     * Clear available handlers
  -     */
  -    public void recycle() {
  -        this.userHandlers = null;
  -        this.resolver = null;
  -        this.request = null;
  -    }
  -
  -    /**
  -     * Get the handler of the current user
  -     */
  -    public Handler getHandler(String handlerName) 
  -    throws ConfigurationException {
  -        if ( null == handlerName) return null;
  -        if ( null == this.userHandlers) {
  -            final Session session = this.request.getSession(false);
  -            if ( null != session) {
  -                this.userHandlers = (Map)session.getAttribute(SESSION_ATTRIBUTE_HANDLERS);
  -            }
  -        }
  -        Handler handler = null;
  -        if ( null != this.userHandlers) {
  -            handler = (Handler)this.userHandlers.get(handlerName);
  -        }
  -        if ( null == handler ) {
  -            handler = (Handler)this.currentHandlers().get(handlerName);
  -        }
  -        return handler;
  -    }
  -
  -    /**
  -     * Create a handler copy for the user and return it!
  -     */
  -    public Handler storeUserHandler(Handler handler) {
  -        final Session session = this.request.getSession();
  -        if ( null == this.userHandlers) {
  -            this.userHandlers = (Map)session.getAttribute(SESSION_ATTRIBUTE_HANDLERS);
  -        }
  -        if ( null == this.userHandlers ) {
  -            this.userHandlers = new HashMap(3);
  -        }
  -        handler = handler.copy();
  -        this.userHandlers.put(handler.getName(), handler);
  -        // value did change, update attributes
  -        session.setAttribute(SESSION_ATTRIBUTE_HANDLERS, this.userHandlers);
  -
  -        return handler;
  -    }
  -
  -    /**
  -     * Remove from user handler
  -     */
  -    public void removeUserHandler(Handler handler) {
  -        final Session session = this.request.getSession();
  -        if ( null == this.userHandlers) {
  -            this.userHandlers = (Map)session.getAttribute(SESSION_ATTRIBUTE_HANDLERS);
  -        }
  -        if ( null != this.userHandlers) {
  -            this.userHandlers.remove( handler.getName() );
  -            // value did change, update attributes
  -            session.setAttribute(SESSION_ATTRIBUTE_HANDLERS, this.userHandlers);
  -        }
  -    }
   
  -    /**
  -     * Check, if a user handler is available (= is authenticated)
  -     */
  -    public boolean hasUserHandler(String name) {
  -        if ( null == this.userHandlers) {
  -            final Session session = this.request.getSession(false);
  -            if ( null != session) {
  -                this.userHandlers = (Map)session.getAttribute(SESSION_ATTRIBUTE_HANDLERS);
  -            }
  -        }
  -        if ( null != this.userHandlers) {
  -            return this.userHandlers.containsKey( name );
  -        }
  -        return false;
  -    }
  -    
  -    /**
  -     * Check, if any handler is available
  -     */
  -    public boolean hasAnyUserHandler() {
  -        if ( null == this.userHandlers) {
  -            final Session session = this.request.getSession(false);
  -            if ( null != session) {
  -                this.userHandlers = (Map)session.getAttribute(SESSION_ATTRIBUTE_HANDLERS);
  -            }
  -        }
  -        if ( null != this.userHandlers) {
  -            return !this.userHandlers.isEmpty();
  -        }
  -        return false;
  -    }
   }
  
  
  
  1.3       +15 -33    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.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- Manager.java	21 Mar 2003 08:54:30 -0000	1.2
  +++ Manager.java	21 Apr 2003 19:26:14 -0000	1.3
  @@ -51,9 +51,9 @@
   package org.apache.cocoon.webapps.authentication.components;
   
   import java.io.IOException;
  -import java.util.Map;
   
   import org.apache.cocoon.ProcessingException;
  +import org.apache.cocoon.environment.Redirector;
   import org.apache.excalibur.source.SourceParameters;
   import org.w3c.dom.DocumentFragment;
   
  @@ -62,7 +62,7 @@
   /**
    * This is the basis authentication component.
    *
  - * @author <a href="mailto:cziegeler@s-und-n.de">Carsten Ziegeler</a>
  + * @author <a href="mailto:cziegeler@apache.org">Carsten Ziegeler</a>
    * @version CVS $Id$
   */
   public interface Manager {
  @@ -71,25 +71,18 @@
       public static final String ROLE = Manager.class.getName();
   
       /**
  -     * Test if the media of the current request is the given value
  -     */
  -    boolean testMedia(String value);
  -
  -    /**
  -     * Get all media type names
  -     */
  -    String[] getMediaTypes();
  -
  -    /**
  -     * Return the current media type
  +     * Is the current user authenticated for the given handler?
        */
  -    String getMediaType();
  +    boolean isAuthenticated(String handlerName)
  +    throws ProcessingException;
   
       /**
        * Is the current user authenticated for the given handler?
        */
  -    boolean isAuthenticated(String name)
  -    throws IOException, ProcessingException;
  +    boolean checkAuthentication(Redirector redirector,
  +                                 String     handlerName,
  +                                 String     applicationName)
  +    throws ProcessingException, IOException;
   
       /**
        * Authenticate
  @@ -97,23 +90,12 @@
        * If not an element "failed" is return. If handler specific error
        * information is available this is also returned.
        */
  -    DocumentFragment authenticate(String              loginHandlerName,
  +    DocumentFragment authenticate(String              handlerName,
  +                                  String              applicationName,
                                     SourceParameters    parameters)
  -    throws ProcessingException, IOException;
  -
  -    /**
  -     * Build parameters for loading and saving of application data
  -     */
  -    SourceParameters createParameters(String handler, 
  -                                      String applicationName,
  -                                      String path)
       throws ProcessingException;
  -    
  -    /**
  -     * Create a map for the actions
  -     * The result is cached!
  -     */
  -    Map createMap(String handler, String applicationName)
  +
  +    void logout(String handlerName,
  +                 int mode)
       throws ProcessingException;
  -    
   }
  
  
  
  1.4       +190 -650  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.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- DefaultAuthenticationManager.java	24 Mar 2003 14:33:57 -0000	1.3
  +++ DefaultAuthenticationManager.java	21 Apr 2003 19:26:14 -0000	1.4
  @@ -51,704 +51,244 @@
   package org.apache.cocoon.webapps.authentication.components;
   
   import java.io.IOException;
  -import java.util.Collections;
  -import java.util.HashMap;
  -import java.util.Iterator;
   import java.util.Map;
   
  -import org.apache.avalon.framework.CascadingRuntimeException;
  -import org.apache.avalon.framework.configuration.Configurable;
  -import org.apache.avalon.framework.configuration.Configuration;
   import org.apache.avalon.framework.configuration.ConfigurationException;
  -import org.apache.avalon.framework.parameters.Parameters;
  +import org.apache.avalon.framework.logger.AbstractLogEnabled;
  +import org.apache.avalon.framework.service.ServiceException;
  +import org.apache.avalon.framework.service.ServiceManager;
  +import org.apache.avalon.framework.service.Serviceable;
  +import org.apache.avalon.framework.thread.ThreadSafe;
   import org.apache.cocoon.ProcessingException;
  -import org.apache.cocoon.components.RequestLifecycleComponent;
  +import org.apache.cocoon.components.CocoonComponentManager;
   import org.apache.cocoon.components.SitemapConfigurable;
   import org.apache.cocoon.components.SitemapConfigurationHolder;
  +import org.apache.cocoon.environment.ObjectModelHelper;
  +import org.apache.cocoon.environment.Redirector;
  +import org.apache.cocoon.environment.Request;
   import org.apache.cocoon.environment.Session;
   import org.apache.cocoon.environment.SourceResolver;
  -import org.apache.cocoon.webapps.authentication.AuthenticationConstants;
  -import org.apache.cocoon.webapps.authentication.context.SessionContextImpl;
  -import org.apache.cocoon.webapps.authentication.context.SessionContextProviderImpl;
  -import org.apache.cocoon.webapps.session.components.AbstractSessionComponent;
  -import org.apache.cocoon.webapps.session.components.SessionManager;
  -import org.apache.cocoon.webapps.session.context.SessionContext;
  -import org.apache.cocoon.webapps.session.context.SimpleSessionContext;
  -import org.apache.cocoon.xml.XMLUtils;
  -import org.apache.cocoon.xml.dom.DOMUtil;
  -import org.apache.excalibur.source.Source;
  -import org.apache.excalibur.source.SourceException;
   import org.apache.excalibur.source.SourceParameters;
  -import org.w3c.dom.Document;
  +import org.apache.excalibur.source.SourceUtil;
   import org.w3c.dom.DocumentFragment;
  -import org.w3c.dom.Element;
  -import org.w3c.dom.Node;
  -import org.w3c.dom.NodeList;
  -import org.w3c.dom.Text;
  -import org.xml.sax.SAXException;
   
   /**
    * This is the basis authentication component.
    *
  - * @author <a href="mailto:cziegeler@s-und-n.de">Carsten Ziegeler</a>
  + * @author <a href="mailto:cziegeler@apache.org">Carsten Ziegeler</a>
    * @version CVS $Id$
   */
   public final class DefaultAuthenticationManager
  -extends AbstractSessionComponent
  -implements Manager, Configurable, SitemapConfigurable, RequestLifecycleComponent {
  +extends AbstractLogEnabled
  +implements Manager, SitemapConfigurable, Serviceable, ThreadSafe {
   
  -    /** The media Types */
  -    private PreparedMediaType[] allMediaTypes;
  -    
  -    /** The default media type (usually this is html) */
  -    private String      defaultMediaType;
  -    
  -    /** All media type names */
  -    private String[]    mediaTypeNames;
  +    /** The name of the session attribute storing the user status */
  +    public final static String SESSION_ATTRIBUTE_USER_STATUS = DefaultAuthenticationManager.class.getName() + "/UserStatus";
   
       /** The manager for the authentication handlers */
  -    private DefaultHandlerManager handlerManager;
  +    private SitemapConfigurationHolder holder;
  +    
  +    /** The Service Manager */
  +    private ServiceManager manager;
       
  -    /** The context provider */
  -    private static SessionContextProviderImpl contextProvider;
  -
  -    /** media type */
  -    private String mediaType;
  -
  -    /** Init the class,
  -     *  add the provider for the authentication context
  -     */
  -    static {
  -        // add the provider for the authentication context
  -        contextProvider = new SessionContextProviderImpl();
  -        try {
  -            SessionManager.addSessionContextProvider(contextProvider, AuthenticationConstants.SESSION_CONTEXT_NAME);
  -        } catch (ProcessingException local) {
  -            throw new CascadingRuntimeException("Unable to register provider for authentication context.", local);
  -        }
  -    }
  -
  -    /**
  -     * Configurable interface.
  -     */
  -    public void configure(Configuration myConfiguration)
  -    throws ConfigurationException {
  -        // no sync required
  -        Configuration mediaConf = myConfiguration.getChild("mediatypes", false);
  -        if (mediaConf == null) {
  -            // default configuration
  -            this.defaultMediaType = "html";
  -        } else {
  -            this.defaultMediaType = mediaConf.getAttribute("default", "html");
  -        }
  -        this.mediaTypeNames = new String[1];
  -        this.mediaTypeNames[0] = this.defaultMediaType;
  -        boolean found;
  -        int     i;
  -        String  name;
  -
  -        Configuration[] childs = mediaConf.getChildren("media");
  -        PreparedMediaType[] array = new PreparedMediaType[0];
  -        PreparedMediaType[] copy;
  -        Configuration current;
  -        if (childs != null) {
  -            for(int x = 0; x < childs.length; x++) {
  -                current = childs[x];
  -                copy = new PreparedMediaType[array.length + 1];
  -                System.arraycopy(array, 0, copy, 0, array.length);
  -                array = copy;
  -                name = current.getAttribute("name");
  -                array[array.length-1] = new PreparedMediaType(name, current.getAttribute("useragent"));
  -                found = false;
  -                i = 0;
  -                while ( i < this.mediaTypeNames.length && found == false) {
  -                    found = this.mediaTypeNames[i].equals(name);
  -                    i++;
  -                }
  -                if (found == false) {
  -                    String[] newStrings = new String[this.mediaTypeNames.length + 1];
  -                    System.arraycopy(this.mediaTypeNames, 0, newStrings, 0, this.mediaTypeNames.length);
  -                    newStrings[newStrings.length-1] = name;
  -                    this.mediaTypeNames = newStrings;
  -                }
  -            }
  -        }
  -        this.allMediaTypes = array;
  -    }
  -
       /**
        * Set the sitemap configuration containing the handlers
        */
       public void configure(SitemapConfigurationHolder holder)
       throws ConfigurationException {
  -        if ( null == this.handlerManager ) {
  -            this.handlerManager = new DefaultHandlerManager( holder );
  -        }
  -    }
  -
  -    /**
  -     * Recyclable
  -     */
  -    public void recycle() {
  -        super.recycle();
  -        this.handlerManager.recycle();
  -    }
  -    
  -    /**
  -     * @see org.apache.cocoon.components.RequestLifecycleComponent#setup(org.apache.cocoon.environment.SourceResolver, java.util.Map)
  -     */
  -    public void setup(SourceResolver resolver, Map objectModel)
  -    throws ProcessingException, SAXException, IOException {
  -        super.setup(resolver, objectModel);
  -        this.handlerManager.setup( resolver, objectModel );
  -        // get the media of the current request
  -        String useragent = request.getHeader("User-Agent");
  -        PreparedMediaType media = null;
  -        if (useragent != null) {
  -            int i, l;
  -            i = 0;
  -            l = this.allMediaTypes.length;
  -            while (i < l && media == null) {
  -                if (useragent.indexOf(this.allMediaTypes[i].useragent) == -1) {
  -                    i++;
  -                } else {
  -                    media = this.allMediaTypes[i];
  -                }
  -            }
  -        }
  -        this.mediaType = (media == null ? this.defaultMediaType : media.name);
  -    }
  -
  -    /**
  -     * Test if the media of the current request is the given value
  -     */
  -    public boolean testMedia(String value) {
  -        // synchronized
  -        boolean result = false;
  -
  -        String useragent = this.request.getHeader("User-Agent");
  -        PreparedMediaType theMedia = null;
  -        int i, l;
  -        i = 0;
  -        l = this.allMediaTypes.length;
  -        while (i < l && theMedia == null) {
  -            if (useragent.indexOf(this.allMediaTypes[i].useragent) == -1) {
  -                i++;
  -            } else {
  -                theMedia = this.allMediaTypes[i];
  -            }
  -        }
  -        if (theMedia != null) {
  -            result = theMedia.name.equals(value);
  -        } else {
  -            result = this.defaultMediaType.equals(value);
  -        }
  -
  -        return result;
  -    }
  -
  -    /**
  -     * Get all media type names
  -     */
  -    public String[] getMediaTypes() {
  -        // synchronized
  -        return this.mediaTypeNames;
  -    }
  -
  -    /**
  -     * Return the current media type
  -     */
  -    public String getMediaType() {
  -        // synchronized
  -        return this.mediaType;
  +        this.holder = holder;
       }
   
       /**
  -     * Get the handler
  +     * Get the handler configuration for the current sitemap
        */
  -    private Handler getHandler(String name) 
  +    private Map getHandlerConfigurations() 
       throws ProcessingException {
  -        // synchronized
  -        try {
  -            return this.handlerManager.getHandler( name );
  -        } catch (ConfigurationException ce) {
  -            throw new ProcessingException("Unable to get handler " + name, ce);
  +        Map configs = (Map) this.holder.getPreparedConfiguration();
  +        if ( null == configs ) {
  +            // prepare the configs
  +            SourceResolver resolver = null;
  +            try {       
  +                resolver = (SourceResolver) this.manager.lookup( SourceResolver.ROLE );
  +                configs = DefaultHandlerManager.prepareHandlerConfiguration(resolver, 
  +                                                                            CocoonComponentManager.getCurrentEnvironment().getObjectModel(), 
  +                                                                            this.holder);
  +            } catch (ServiceException se) {
  +                throw new ProcessingException("Unable to lookup source resolver.", se);
  +            } catch (ConfigurationException ce) {
  +                throw new ProcessingException("Configuration error.", ce);
  +            } finally {
  +                this.manager.release( resolver );
  +            }
           }
  +        return configs;
       }
   
       /**
  -     * Is the current user authenticated for the given handler?
  +     * Get the handler configuration
  +     * @param name
  +     * @return
        */
  -    public boolean isAuthenticated(String name)
  -    throws IOException, ProcessingException {
  -        // synchronized
  -        if (this.getLogger().isDebugEnabled() == true) {
  -            this.getLogger().debug("BEGIN isAuthenticated handler=" + name);
  -        }
  -        boolean isAuthenticated = true;
  -
  -        // if no handler: authenticated
  -        if (name != null) {
  -            isAuthenticated = this.handlerManager.hasUserHandler( name );
  +    private HandlerConfiguration getHandlerConfiguration(String name) 
  +    throws ProcessingException {   
  +        final Map configs = this.getHandlerConfigurations();
  +        HandlerConfiguration c = null;
  +        if ( configs != null) {
  +            c = (HandlerConfiguration)configs.get( name ); 
           }
  -
  -        if (this.getLogger().isDebugEnabled() == true) {
  -            this.getLogger().debug("END isAuthenticated authenticated=" + isAuthenticated);
  -        }
  -        return isAuthenticated;
  +        return c;
       }
  -
  -    /**
  -     * Authenticate
  -     * If the authentication is successful, <code>null</code> is returned.
  -     * If not an element "failed" is return. If handler specific error
  -     * information is available this is also returned.
  -     */
  -    public DocumentFragment authenticate(String              loginHandlerName,
  -                                         SourceParameters    parameters)
  -    throws ProcessingException, IOException {
  -        // synchronized
  -        if (this.getLogger().isDebugEnabled() == true) {
  -            this.getLogger().debug("BEGIN authenticate handler=" + loginHandlerName +
  -                                   ", parameters="+parameters);
  -        }
  -
  -        DocumentFragment authenticationFragment = null;
  -        boolean         isValid                = false;
  -
  -        Handler myHandler = this.getHandler(loginHandlerName);
  -        if (this.getLogger().isInfoEnabled() == true) {
  -            this.getLogger().info("AuthenticationManager: Trying to authenticate using handler '" + loginHandlerName +"'");
  -        }
  -        if (myHandler != null) {
  -            String           exceptionMsg     = null;
  -
  -            if (this.getLogger().isDebugEnabled() == true) {
  -                this.getLogger().debug("start authentication");
  -            }
  -
  -            final String   authenticationResourceName = myHandler.getAuthenticationResource();
  -            final SourceParameters authenticationParameters = myHandler.getAuthenticationResourceParameters();
  -            if (parameters != null) {
  -                parameters.add(authenticationParameters);
  -            } else {
  -                parameters = authenticationParameters;
  -            }
  -
  -            try {
  -                if (this.getLogger().isDebugEnabled()) {
  -                    this.getLogger().debug("start invoking auth resource");
  -                }
  -                Source source = null;
  -                try {
  -                    source = org.apache.cocoon.components.source.SourceUtil.getSource(authenticationResourceName, 
  -                                                                                      null, 
  -                                                                                      parameters, 
  -                                                                                      this.resolver);
  -                    
  -                    Document doc = org.apache.cocoon.components.source.SourceUtil.toDOM(source);
  -                    authenticationFragment = doc.createDocumentFragment();
  -                    authenticationFragment.appendChild(doc.getDocumentElement());
  -                } catch (SAXException se) {
  -                    throw new ProcessingException(se);
  -                } catch (SourceException se) {
  -                    throw org.apache.cocoon.components.source.SourceUtil.handle(se);
  -                } finally {
  -                    this.resolver.release(source);
  -                }
  -
  -                if (this.getLogger().isDebugEnabled()) {
  -                    this.getLogger().debug("end invoking auth resource");
  -                }
  -            } catch (ProcessingException local) {
  -                this.getLogger().error("authenticate", local);
  -                exceptionMsg = local.getMessage();
  -            }
  -
  -            // test if authentication was successful
  -            if (authenticationFragment != null) {
  -                isValid = this.isValidAuthenticationFragment(authenticationFragment);
  -
  -                if (isValid == true) {
  -                    if (this.getLogger().isInfoEnabled() == true) {
  -                        this.getLogger().info("AuthenticationManager: User authenticated using handler '" + myHandler.getName()+"'");
  -                    }
  -                    // create session object if necessary, context etc and get it
  -                    if (this.getLogger().isDebugEnabled() == true) {
  -                        this.getLogger().debug("creating session");
  -                    }
  -                    SessionContext context = this.getAuthenticationSessionContext(true);
  -                    if (this.getLogger().isDebugEnabled() == true) {
  -                        this.getLogger().debug("session created");
  -                    }
  -
  -                    myHandler = this.handlerManager.storeUserHandler( myHandler );
  -
  -                    synchronized(context) {
  -                        // add special nodes to the authentication block:
  -                        // useragent, type and media
  -                        Element specialElement;
  -                        Text    specialValue;
  -                        Element authNode;
  -
  -                        authNode = (Element)authenticationFragment.getFirstChild();
  -                        specialElement = authenticationFragment.getOwnerDocument().createElementNS(null, "useragent");
  -                        specialValue = authenticationFragment.getOwnerDocument().createTextNode(request.getHeader("User-Agent"));
  -                        specialElement.appendChild(specialValue);
  -                        authNode.appendChild(specialElement);
  -
  -                        specialElement = authenticationFragment.getOwnerDocument().createElementNS(null, "type");
  -                        specialValue = authenticationFragment.getOwnerDocument().createTextNode("cocoon.authentication");
  -                        specialElement.appendChild(specialValue);
  -                        authNode.appendChild(specialElement);
  -
  -                        specialElement = authenticationFragment.getOwnerDocument().createElementNS(null, "media");
  -                        specialValue = authenticationFragment.getOwnerDocument().createTextNode(this.mediaType);
  -                        specialElement.appendChild(specialValue);
  -                        authNode.appendChild(specialElement);
  -
  -                        // store the authentication data in the context
  -                        context.setXML("/" + myHandler.getName(), authenticationFragment);
  -
  -                        // Now create the return value for this method:
  -                        // <code>null</code>
  -                        authenticationFragment = null;
  -
  -                        // And now load applications
  -                        boolean loaded = true;
  -                        Iterator applications = myHandler.getApplications().values().iterator();
  -                        ApplicationHandler appHandler;
  -
  -                        while (applications.hasNext() == true) {
  -                            appHandler = (ApplicationHandler)applications.next();
  -                            if (appHandler.getLoadOnDemand() == false) {
  -                                this.loadApplicationXML((SessionContextImpl)this.getSessionManager().getContext(AuthenticationConstants.SESSION_CONTEXT_NAME),
  -                                                        appHandler, "/");
  -                            } else {
  -                                loaded = appHandler.getIsLoaded();
  -                            }
  -                        }
  -                        myHandler.setApplicationsLoaded(loaded);
  -
  -                    } // end sync
  -                }
  -            }
  -            if (isValid == false) {
  -                if (this.getLogger().isInfoEnabled() == true) {
  -                    this.getLogger().info("AuthenticationManager: Failed authentication using handler '" +  myHandler.getName()+"'");
  -                }
  -                // get the /authentication/data Node if available
  -                Node data = null;
  -
  -                if (authenticationFragment != null) {
  -                    data = DOMUtil.getFirstNodeFromPath(authenticationFragment, new String[] {"authentication","data"}, false);
  -                }
  -
  -                // now create the following xml:
  -                // <failed/>
  -                // if data is available data is included, otherwise:
  -                // <data>No information</data>
  -                // If exception message contains info, it is included into failed
  -                Document       doc = DOMUtil.createDocument();
  -                authenticationFragment = doc.createDocumentFragment();
  -
  -                Element      element = doc.createElementNS(null, "failed");
  -                authenticationFragment.appendChild(element);
  -
  -                if (exceptionMsg != null) {
  -                    Text text = doc.createTextNode(exceptionMsg);
  -                    element.appendChild(text);
  -                }
  -
  -                if (data == null) {
  -                    element = doc.createElementNS(null, "data");
  -                    authenticationFragment.appendChild(element);
  -                    Text text = doc.createTextNode("No information");
  -                    element.appendChild(text);
  -                } else {
  -                    authenticationFragment.appendChild(doc.importNode(data, true));
  -                }
  -
  -            }
  -            if (this.getLogger().isDebugEnabled() == true) {
  -                this.getLogger().debug("end authentication");
  -            }
  -        }
  -
  -        if (this.getLogger().isDebugEnabled() == true) {
  -            this.getLogger().debug("END authenticate fragment="+authenticationFragment);
  -        }
  -        return authenticationFragment;
  +    
  +    private Request getRequest() {
  +        final Map objectModel = CocoonComponentManager.getCurrentEnvironment().getObjectModel();
  +        return ObjectModelHelper.getRequest( objectModel );
       }
  -
  -    /**
  -     * Check the fragment if it is valid
  -     */
  -    private boolean isValidAuthenticationFragment(DocumentFragment authenticationFragment) 
  -    throws ProcessingException {
  -        // calling method is synced
  -        if (this.getLogger().isDebugEnabled() == true) {
  -            this.getLogger().debug("BEGIN isValidAuthenticationFragment fragment=" + XMLUtils.serializeNodeToXML(authenticationFragment));
  -        }
  -        boolean isValid = false;
  -
  -        // authenticationFragment must only have exactly one child with
  -        // the name authentication
  -        if (authenticationFragment.hasChildNodes() == true
  -            && authenticationFragment.getChildNodes().getLength() == 1) {
  -            Node child = authenticationFragment.getFirstChild();
  -
  -            if (child.getNodeType() == Node.ELEMENT_NODE
  -                && child.getNodeName().equals("authentication") == true) {
  -
  -                // now authentication must have one child ID
  -                if (child.hasChildNodes() == true) {
  -                    NodeList children = child.getChildNodes();
  -                    boolean  found = false;
  -                    int      i = 0;
  -                    int      l = children.getLength();
  -
  -                    while (found == false && i < l) {
  -                        child = children.item(i);
  -                        if (child.getNodeType() == Node.ELEMENT_NODE
  -                            && child.getNodeName().equals("ID") == true) {
  -                            found = true;
  -                        } else {
  -                            i++;
  -                        }
  -                    }
  -
  -                    // now the last check: ID must have a TEXT child
  -                    if (found == true) {
  -                        child.normalize(); // join text nodes
  -                        if (child.hasChildNodes() == true &&
  -                            child.getChildNodes().getLength() == 1 &&
  -                            child.getChildNodes().item(0).getNodeType() == Node.TEXT_NODE) {
  -                            String value = child.getChildNodes().item(0).getNodeValue().trim();
  -                            if (value.length() > 0) isValid = true;
  -                        }
  -                    }
  -                }
  -
  -            }
  -        }
  -        if (this.getLogger().isDebugEnabled() == true) {
  -            this.getLogger().debug("END isValidAuthenticationFragment valid="+isValid);
  -        }
  -        return isValid;
  +    
  +    private Session getSession(boolean create) {        
  +        return this.getRequest().getSession(create);
       }
  -
  -    /**
  -     * Get the private SessionContext
  -     */
  -    private SessionContext getAuthenticationSessionContext(boolean create)
  -    throws ProcessingException {
  -        // synchronized
  -        if (this.getLogger().isDebugEnabled() == true) {
  -            this.getLogger().debug("BEGIN getAuthenticationSessionContext create=" + create);
  -        }
  -        SessionContext context = null;
  -
  -        Session session = this.getSessionManager().getSession(create);
  -        if (session != null) {
  -            synchronized(session) {
  -                context = (SessionContext)session.getAttribute(AuthenticationConstants.SESSION_ATTRIBUTE_CONTEXT_NAME);
  -                if (context == null && create == true) {
  -                    context = new SimpleSessionContext();
  -                    context.setup(AuthenticationConstants.SESSION_CONTEXT_NAME, null, null);
  -                    session.setAttribute(AuthenticationConstants.SESSION_ATTRIBUTE_CONTEXT_NAME, context);
  -                }
  -            }
  -        }
  -
  -        if (this.getLogger().isDebugEnabled() == true) {
  -            this.getLogger().debug("END getAuthenticationSessionContext context=" + context);
  +    
  +    private UserStatus getUserStatus() {
  +        final Session session = this.getSession( false );
  +        UserStatus status = null;
  +        if ( session != null) {
  +            status = (UserStatus) session.getAttribute(SESSION_ATTRIBUTE_USER_STATUS);
  +        }
  +        return status;
  +    }
  +
  +    private UserStatus createUserStatus() {
  +        UserStatus status = this.getUserStatus();
  +        if ( status == null ) {
  +            final Session session = this.getSession(true);
  +            status = new UserStatus();
  +            session.setAttribute(SESSION_ATTRIBUTE_USER_STATUS, status);
           }
  -        return context;
  +        return status;
       }
  -
  -    /**
  -     * Load XML of an application
  -     */
  -    private void loadApplicationXML(SessionContextImpl context,
  -                                    ApplicationHandler appHandler,
  -                                    String path)
  -    throws ProcessingException {
  -        // synchronized
  -        if (this.getLogger().isDebugEnabled() ) {
  -            this.getLogger().debug("BEGIN loadApplicationXML application=" + appHandler.getName() + ", path="+path);
  -        }
  -        Object o = this.getSessionManager().getSession(true);
  -        synchronized(o) {
  -
  -            if (appHandler.getIsLoaded() == false) {
  -
  -                final String   loadResourceName = appHandler.getLoadResource();
  -                SourceParameters parameters = appHandler.getLoadResourceParameters();
  -                if (parameters != null) parameters = (SourceParameters)parameters.clone();
  -                parameters = this.createParameters(parameters,
  -                                                   appHandler.getHandler().getName(),
  -                                                   path,
  -                                                   appHandler.getName());
  -                DocumentFragment fragment;
  -
  -                Source source = null;
  -                try {
  -                    source = org.apache.cocoon.components.source.SourceUtil.getSource(loadResourceName, 
  -                                                                                      null, 
  -                                                                                      parameters, 
  -                                                                                      this.resolver);
  -                    Document doc = org.apache.cocoon.components.source.SourceUtil.toDOM(source);
  -                    fragment = doc.createDocumentFragment();
  -                    fragment.appendChild(doc.getDocumentElement());
  -                } catch (SourceException se) {
  -                    throw org.apache.cocoon.components.source.SourceUtil.handle(se);
  -                } catch (IOException se) {
  -                    throw new ProcessingException(se);
  -                } catch (SAXException se) {
  -                    throw new ProcessingException(se);
  -                } finally {
  -                    this.resolver.release(source);
  -                }
  -
  -                appHandler.setIsLoaded(true);
  -
  -                context.setApplicationXML(appHandler.getHandler().getName(),
  -                                          appHandler.getName(),
  -                                          path,
  -                                          fragment);
  -
  -                // now test handler if all applications are loaded
  -                Iterator applications = appHandler.getHandler().getApplications().values().iterator();
  -                boolean     allLoaded = true;
  -                while (allLoaded == true && applications.hasNext() == true) {
  -                    allLoaded = ((ApplicationHandler)applications.next()).getIsLoaded();
  -                }
  -                appHandler.getHandler().setApplicationsLoaded(allLoaded);
  -            }
  -
  -        } // end synchronized
  -
  -        if (this.getLogger().isDebugEnabled() ) {
  -            this.getLogger().debug("END loadApplicationXML");
  +    
  +    private UserHandler getUserHandler(String name) {
  +        final UserStatus status = this.getUserStatus();
  +        if ( status != null ) {
  +            return status.getUserHandler( name );
           }
  +        return null;
       }
  -
  -    /*
  -     * Check if application for path is loaded
  -     */
  -    /* FIXME(SM): this method appears to be unused. Should we remove it?
  -    private void checkLoaded(SessionContextImpl context,
  -                               String             path,
  -                               ApplicationHandler applicationHandler)
  -    throws ProcessingException {
  -        // synchronized as loadApplicationXML is synced
  -        if ( this.getLogger().isDebugEnabled() ) {
  -            this.getLogger().debug("BEGIN checkLoaded path="+path);
  -        }
  -        if ( path.equals("/") || path.startsWith("/application") ) {
  -            if (applicationHandler != null) {
  -                this.loadApplicationXML(context, applicationHandler, "/");
  -            }
  -        }
  -
  -        if ( this.getLogger().isDebugEnabled() ) {
  -            this.getLogger().debug("END checkLoaded");
  -        }
  -    } */
       
  -    /**
  -     * Build parameters for loading and saving of application data
  -     */
  -    private SourceParameters createParameters(SourceParameters parameters,
  -                                                String             myHandler,
  -                                                String             path,
  -                                                String             appName)
  -    throws ProcessingException {
  -        // synchronized
  -        if (this.getLogger().isDebugEnabled() ) {
  -            this.getLogger().debug("BEGIN createParameters handler=" + myHandler +
  -                              ", path="+path+ ", application=" + appName);
  -        }
  -
  -        SessionContextImpl context;
  -        context = (SessionContextImpl)contextProvider.getSessionContext(AuthenticationConstants.SESSION_CONTEXT_NAME,
  -                                                      this.objectModel,
  -                                                      this.resolver,
  -                                                      this.manager);
  -        parameters = context.createParameters(parameters, myHandler, path, appName);
  -
  -        if (this.getLogger().isDebugEnabled() ) {
  -            this.getLogger().debug("END createParameters parameters="+parameters);
  -        }
  -        return parameters;
  +    private void updateUserStatus() {
  +        final Session session = this.getSession(true);
  +        Object status = session.getAttribute(SESSION_ATTRIBUTE_USER_STATUS);
  +        session.setAttribute(SESSION_ATTRIBUTE_USER_STATUS, status);
       }
  -
  -    /**
  -     * Build parameters for loading and saving of application data
  -     */
  -    public SourceParameters createParameters(String handler, 
  -                                              String applicationName,
  -                                              String path)
  -    throws ProcessingException {
  -        // synchronized
  -        if (handler == null) {
  -            return new SourceParameters();
  -        }
  -        if (path == null) {
  -            SessionContext context = this.getAuthenticationSessionContext(false);
  -            SourceParameters pars = (SourceParameters)context.getAttribute("cachedparameters_" + handler);
  -            if (pars == null) {
  -                 pars = this.createParameters(null, handler, path, applicationName);
  -                 context.setAttribute("cachedparameters_" + handler, pars);
  +    
  +	/* (non-Javadoc)
  +	 * @see org.apache.cocoon.webapps.authentication.components.Manager#authenticate(java.lang.String, java.lang.String, org.apache.excalibur.source.SourceParameters)
  +	 */
  +	public DocumentFragment authenticate(String handlerName,
  +                                          String applicationName,
  +                                          SourceParameters parameters)
  +    throws ProcessingException {
  +        HandlerConfiguration config = this.getHandlerConfiguration( handlerName );
  +        if ( config == null ) {
  +            throw new ProcessingException("Unknown handler to authenticate: " + handlerName);
  +        }
  +        // are we already logged in?
  +        UserHandler handler = this.getUserHandler( handlerName );
  +        if ( handler != null ) {
  +            throw new ProcessingException("User is already authenticated using handler: " + handlerName);
  +        }
  +        
  +        // TODO Authentication
  +        
  +        // create UserStatus
  +        final UserStatus status = this.createUserStatus();
  +        handler = new UserHandler( config );
  +        
  +        status.addHandler( handler );        
  +        this.updateUserStatus();
  +        
  + 		return null;
  +	}
  +
  +	/* (non-Javadoc)
  +	 * @see org.apache.cocoon.webapps.authentication.components.Manager#checkAuthentication(org.apache.cocoon.environment.Redirector, java.lang.String, java.lang.String)
  +	 */
  +	public boolean checkAuthentication(Redirector redirector,
  +                                        String handlerName,
  +                                        String applicationName)
  +	throws IOException, ProcessingException {
  +        HandlerConfiguration config = this.getHandlerConfiguration( handlerName );
  +        if ( config == null ) {
  +            throw new ProcessingException("Unknown handler to check: " + handlerName);
  +        }
  +        // are we already logged in?
  +        UserHandler handler = this.getUserHandler( handlerName );
  +        final boolean authenticated = ( handler != null );
  +        if ( !authenticated ) {
  +            // create parameters
  +            SourceParameters parameters = config.getRedirectParameters();
  +            if (parameters == null) parameters = new SourceParameters();
  +            final Request request = this.getRequest();
  +            String resource = request.getRequestURI();
  +            if (request.getQueryString() != null) {
  +                resource += '?' + request.getQueryString();
  +            }
  +
  +            parameters.setSingleParameterValue("resource", resource);
  +            final String redirectURI = config.getRedirectURI();
  +            redirector.globalRedirect(false, SourceUtil.appendParameters(redirectURI, parameters));
  +        }
  +        
  +		return authenticated;
  +	}
  +
  +	/* (non-Javadoc)
  +	 * @see org.apache.cocoon.webapps.authentication.components.Manager#isAuthenticated(java.lang.String)
  +	 */
  +	public boolean isAuthenticated(String handlerName)
  +    throws ProcessingException {
  +        return ( this.getUserHandler( handlerName ) != null);
  +	}
  +
  +	/* (non-Javadoc)
  +	 * @see org.apache.cocoon.webapps.authentication.components.Manager#logout(java.lang.String, java.lang.String)
  +	 */
  +	public void logout(String handlerName, int mode) 
  +    throws ProcessingException {
  +        HandlerConfiguration config = this.getHandlerConfiguration( handlerName );
  +        if ( config == null ) {
  +            throw new ProcessingException("Unknown handler to logout: " + handlerName);
  +        }
  +        // are we logged in?
  +        UserHandler handler = this.getUserHandler( handlerName );
  +        // we don't throw an exception if we are already logged out!
  +        if ( handler != null ) {
  +            UserStatus status = this.getUserStatus();
  +            status.removeHandler( handlerName );
  +            this.updateUserStatus();
  +        }
  +        
  +        /*
  +        if ( mode == AuthenticationConstants.LOGOUT_MODE_IMMEDIATELY ) {
  +            this.getSessionManager().terminateSession(true);
  +        } else if (!this.handlerManager.hasUserHandler( this.request )) {
  +            if (mode == AuthenticationConstants.LOGOUT_MODE_IF_UNUSED) {
  +                this.getSessionManager().terminateSession(false);
  +            } else {
  +                this.getSessionManager().terminateSession(true);
               }
  -            return pars;
           }
  -        return this.createParameters(null, handler, path, applicationName);
  -    }
  +        */
  +	}
  +
  +	/**
  +     * Serviceable
  +	 */
  +	public void service(ServiceManager manager) 
  +    throws ServiceException {
  +        this.manager = manager;
  +	}
   
  -    /**
  -     * Create a map for the actions
  -     * The result is cached!
  -     */
  -    public Map createMap(String handler, String applicationName)
  -    throws ProcessingException {
  -        if (handler == null) {
  -            // this is only a fallback
  -            return Collections.EMPTY_MAP;
  -        }
  -        SessionContext context = this.getAuthenticationSessionContext(false);
  -        Map map = (Map)context.getAttribute("cachedmap_" + handler);
  -        if (map == null) {
  -            map = new HashMap();
  -            Parameters pars = this.createParameters(handler, applicationName, null).getFirstParameters();
  -            String[] names = pars.getNames();
  -            if (names != null) {
  -                String key;
  -                String value;
  -                for(int i=0;i<names.length;i++) {
  -                    key = names[i];
  -                    value = pars.getParameter(key, null);
  -                    if (value != null) map.put(key, value);
  -                }
  -            }
  -            context.setAttribute("cachedmap_" + handler, map);
  -        }
  -        return map;
  -    }
   }
   
   
  -/**
  - * This class stores the media type configuration
  - */
  -final class PreparedMediaType {
  -
  -    String name;
  -    String useragent;
  -
  -    PreparedMediaType(String name, String useragent) {
  -        this.name = name;
  -        this.useragent = useragent;
  -    }
  -}
  
  
  
  1.1                  cocoon-2.1/src/blocks/authentication-fw/java/org/apache/cocoon/webapps/authentication/components/HandlerConfiguration.java
  
  Index: HandlerConfiguration.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
  
   Redistribution and use in source and binary forms, with or without modifica-
   tion, are permitted provided that the following conditions are met:
  
   1. Redistributions of  source code must  retain the above copyright  notice,
      this list of conditions and the following disclaimer.
  
   2. Redistributions in binary form must reproduce the above copyright notice,
      this list of conditions and the following disclaimer in the documentation
      and/or other materials provided with the distribution.
  
   3. The end-user documentation included with the redistribution, if any, must
      include  the following  acknowledgment:  "This product includes  software
      developed  by the  Apache Software Foundation  (http://www.apache.org/)."
      Alternately, this  acknowledgment may  appear in the software itself,  if
      and wherever such third-party acknowledgments normally appear.
  
   4. The names "Apache Cocoon" and  "Apache Software Foundation" must  not  be
      used to  endorse or promote  products derived from  this software without
      prior written permission. For written permission, please contact
      apache@apache.org.
  
   5. Products  derived from this software may not  be called "Apache", nor may
      "Apache" appear  in their name,  without prior written permission  of the
      Apache Software Foundation.
  
   THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
   INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
   FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
   APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY DIRECT,
   INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-
   DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS
   OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND ON
   ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
   (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
   THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  
   This software  consists of voluntary contributions made  by many individuals
   on  behalf of the Apache Software  Foundation and was  originally created by
   Stefano Mazzocchi  <st...@apache.org>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.cocoon.webapps.authentication.components;
  
  import java.io.IOException;
  import java.util.HashMap;
  import java.util.Hashtable;
  import java.util.Map;
  
  import org.apache.avalon.framework.configuration.Configuration;
  import org.apache.avalon.framework.configuration.ConfigurationException;
  import org.apache.cocoon.ProcessingException;
  import org.apache.cocoon.environment.Request;
  import org.apache.excalibur.source.SourceParameters;
  import org.apache.excalibur.source.SourceResolver;
  import org.xml.sax.SAXException;
  
  /**
   * The authentication Handler.
   *
   * @author <a href="mailto:cziegeler@apache.org">Carsten Ziegeler</a>
   * @version CVS $Id: HandlerConfiguration.java,v 1.1 2003/04/21 19:26:13 cziegeler Exp $
  */
  public final class HandlerConfiguration
  implements java.io.Serializable {
  
      /** The unique name of the handler */
      private final String name;
  
      /** The redirect-to URI */
      private String redirectURI;
  
      /** The redirect parameters */
      private SourceParameters redirectParameters;
  
      /** The authentication resource */
      private String authenticationResource;
  
      /** The authentication resource parameters */
      private SourceParameters authenticationResourceParameters;
  
      /** The load resource (optional) */
      private String loadResource;
  
      /** The load resource (optional) parameters */
      private SourceParameters loadResourceParameters;
  
      /** The save resource (optional) */
      private String saveResource;
  
      /** The save resource (optional) parameters */
      private SourceParameters saveResourceParameters;
  
      /** The Application Configurations */
      private Map applications = new Hashtable(3, 2);
  
      /** The configuration fragments */
      private Map configurations;
  
      /**
       * Create a new handler object.
       */
      public HandlerConfiguration(String name) {
          this.name = name;
          this.configurations = new HashMap(3, 2);
      }
  
      /**
       * Configure
       */
      public void configure(SourceResolver resolver,
                            Request        request,
                            Configuration  conf)
      throws ProcessingException, SAXException, IOException, ConfigurationException {
          // get login (required)
          Configuration child = conf.getChild("redirect-to", false);
          if (child == null)
              throw new ConfigurationException("Handler '"+this.name+"' needs a redirect-to URI.");
          this.redirectURI = child.getAttribute("uri");
          if ( this.redirectURI.startsWith("cocoon:") ) {
              final int pos = this.redirectURI.indexOf('/');
              if ( pos != -1 && this.redirectURI.length() > pos) {
                  if (this.redirectURI.charAt(pos+1) == '/') {
                      this.redirectURI = this.redirectURI.substring(pos+2).trim();
                      this.redirectURI = request.getContextPath()+"/"+this.redirectURI;
                  } else {
                      this.redirectURI = this.redirectURI.substring(pos+1).trim();
                  }
              }
          }
  
          this.redirectParameters = SourceParameters.create(child);
  
          // get load resource (required)
          child = conf.getChild("authentication", false);
          if (child == null)
              throw new ConfigurationException("Handler '"+this.name+"' needs authentication configuration");
          this.authenticationResource = child.getAttribute("uri");
          this.authenticationResourceParameters = SourceParameters.create(child);
  
          // get load resource (optional)
          child = conf.getChild("load", false);
          if (child != null) {
              this.loadResource = child.getAttribute("uri");
              this.loadResourceParameters = SourceParameters.create(child);
          }
  
          // get save resource (optional)
          child = conf.getChild("save", false);
          if (child != null) {
              this.saveResource = child.getAttribute("uri");
              this.saveResourceParameters = SourceParameters.create(child);
          }
  
          // And now: Applications
          child = conf.getChild("applications", false);
          if (child != null) {
              Configuration[] appConfs = child.getChildren("application");
              Configuration appconf;
  
              if (appConfs != null) {
                  for(int i = 0; i < appConfs.length; i++) {
                      appconf = appConfs[i];
  
                      // get name
                      String appName = appconf.getAttribute("name");
  
                      // test if handler is unique
                      if (this.applications.get(appName) != null) {
                          throw new ConfigurationException("Application names must be unique: " + appName);
                      }
  
                      // create handler
                      ApplicationConfiguration apphandler = new ApplicationConfiguration(this, appName);
  
                      // store handler
                      this.applications.put(appName, apphandler);
  
                      // configure
                      apphandler.configure(resolver, appconf);
                  }
              }
          }
  
          // get configurations (optional)
          Configuration[] configurations = conf.getChildren("configuration");
          if (configurations != null) {
              for(int i = 0; i < configurations.length; i++) {
                  child = configurations[i];
                  String value = child.getAttribute("name");
                  if (this.getConfiguration(value) != null) {
                      throw new ConfigurationException("Configuration names must be unique for application " + this.name + ": " + value);
                  }
                  this.configurations.put(value, child);
              }
          }
  
      }
  
  
      /**
       * Get the handler name.
       */
      public String getName() { return name; }
  
      /**
       * Get the redirect URI
       */
      public String getRedirectURI() {
          return this.redirectURI;
      }
  
      /**
       * Get the redirect parameters
       */
      public SourceParameters getRedirectParameters() {
          return this.redirectParameters;
      }
  
      /**
       * Get the authentication resource
       */
      public String getAuthenticationResource() {
          return this.authenticationResource;
      }
  
      /**
       * Get the authentication resource
       */
      public SourceParameters getAuthenticationResourceParameters() {
          return this.authenticationResourceParameters;
      }
  
      /** Get the save resource */
      public String getSaveResource() { return this.saveResource; }
  
      /** Get the load resource */
      public String getLoadResource() { return this.loadResource; }
  
      /** Get the save resource */
      public SourceParameters getSaveResourceParameters() { return this.saveResourceParameters; }
  
      /** Get the load resource parameters */
      public SourceParameters getLoadResourceParameters() { return this.loadResourceParameters; }
  
      /**
       * Get the applications map
       */
      public Map getApplications() { return applications; }
  
      /**
       * Get the configuration
       */
      public Configuration getConfiguration(String name) {
          return (Configuration)this.configurations.get(name);
      }
  
      /**
       * toString()
       */
      public String toString() {
          return "authentication-Handler " + this.name;
      }
  }
  
  
  
  1.1                  cocoon-2.1/src/blocks/authentication-fw/java/org/apache/cocoon/webapps/authentication/components/Status.java
  
  Index: Status.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
  
   Redistribution and use in source and binary forms, with or without modifica-
   tion, are permitted provided that the following conditions are met:
  
   1. Redistributions of  source code must  retain the above copyright  notice,
      this list of conditions and the following disclaimer.
  
   2. Redistributions in binary form must reproduce the above copyright notice,
      this list of conditions and the following disclaimer in the documentation
      and/or other materials provided with the distribution.
  
   3. The end-user documentation included with the redistribution, if any, must
      include  the following  acknowledgment:  "This product includes  software
      developed  by the  Apache Software Foundation  (http://www.apache.org/)."
      Alternately, this  acknowledgment may  appear in the software itself,  if
      and wherever such third-party acknowledgments normally appear.
  
   4. The names "Apache Cocoon" and  "Apache Software Foundation" must  not  be
      used to  endorse or promote  products derived from  this software without
      prior written permission. For written permission, please contact
      apache@apache.org.
  
   5. Products  derived from this software may not  be called "Apache", nor may
      "Apache" appear  in their name,  without prior written permission  of the
      Apache Software Foundation.
  
   THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
   INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
   FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
   APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY DIRECT,
   INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-
   DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS
   OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND ON
   ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
   (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
   THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  
   This software  consists of voluntary contributions made  by many individuals
   on  behalf of the Apache Software  Foundation and was  originally created by
   Stefano Mazzocchi  <st...@apache.org>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.cocoon.webapps.authentication.components;
  
  
  /**
   * The authentication Handler.
   *
   * @author <a href="mailto:cziegeler@apache.org">Carsten Ziegeler</a>
   * @version CVS $Id: Status.java,v 1.1 2003/04/21 19:26:13 cziegeler Exp $
  */
  public final class Status
  implements java.io.Serializable {
  
      /** The handlers */
      private UserHandler handler;
          
      /** The application */
      private String application;
      
      /**
       * Create a new handler object.
       */
      public Status(UserHandler handler, String app) {
          this.handler = handler;
          this.application = app;
      }
  
      public String getApplicationName() {
          return this.application;
      }
      
      public UserHandler getHandler() {
          return this.handler;
      }
      
  }
  
  
  
  1.1                  cocoon-2.1/src/blocks/authentication-fw/java/org/apache/cocoon/webapps/authentication/components/DefaultMediaManager.java
  
  Index: DefaultMediaManager.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
  
   Redistribution and use in source and binary forms, with or without modifica-
   tion, are permitted provided that the following conditions are met:
  
   1. Redistributions of  source code must  retain the above copyright  notice,
      this list of conditions and the following disclaimer.
  
   2. Redistributions in binary form must reproduce the above copyright notice,
      this list of conditions and the following disclaimer in the documentation
      and/or other materials provided with the distribution.
  
   3. The end-user documentation included with the redistribution, if any, must
      include  the following  acknowledgment:  "This product includes  software
      developed  by the  Apache Software Foundation  (http://www.apache.org/)."
      Alternately, this  acknowledgment may  appear in the software itself,  if
      and wherever such third-party acknowledgments normally appear.
  
   4. The names "Apache Cocoon" and  "Apache Software Foundation" must  not  be
      used to  endorse or promote  products derived from  this software without
      prior written permission. For written permission, please contact
      apache@apache.org.
  
   5. Products  derived from this software may not  be called "Apache", nor may
      "Apache" appear  in their name,  without prior written permission  of the
      Apache Software Foundation.
  
   THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
   INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
   FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
   APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY DIRECT,
   INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-
   DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS
   OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND ON
   ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
   (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
   THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  
   This software  consists of voluntary contributions made  by many individuals
   on  behalf of the Apache Software  Foundation and was  originally created by
   Stefano Mazzocchi  <st...@apache.org>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.cocoon.webapps.authentication.components;
  
  import java.io.IOException;
  import java.util.Map;
  
  import org.apache.avalon.excalibur.pool.Recyclable;
  import org.apache.avalon.framework.configuration.Configurable;
  import org.apache.avalon.framework.configuration.Configuration;
  import org.apache.avalon.framework.configuration.ConfigurationException;
  import org.apache.avalon.framework.logger.AbstractLogEnabled;
  import org.apache.cocoon.ProcessingException;
  import org.apache.cocoon.components.RequestLifecycleComponent;
  import org.apache.cocoon.environment.ObjectModelHelper;
  import org.apache.cocoon.environment.Request;
  import org.apache.cocoon.environment.SourceResolver;
  import org.apache.cocoon.webapps.authentication.MediaManager;
  import org.xml.sax.SAXException;
  
  /**
   * This is the basis authentication component.
   *
   * @author <a href="mailto:cziegeler@apache.org">Carsten Ziegeler</a>
   * @version CVS $Id: DefaultMediaManager.java,v 1.1 2003/04/21 19:26:14 cziegeler Exp $
  */
  public final class DefaultMediaManager
  extends AbstractLogEnabled
  implements MediaManager, Configurable, RequestLifecycleComponent, Recyclable {
  
      /** The media Types */
      private PreparedMediaType[] allMediaTypes;
      
      /** The default media type (usually this is html) */
      private String      defaultMediaType;
      
      /** All media type names */
      private String[]    mediaTypeNames;
  
      /** tThe current media type */
      private String mediaType;
  
      /** The current request */
      private Request request;
      
      /**
       * Configurable interface.
       */
      public void configure(Configuration myConfiguration)
      throws ConfigurationException {
          // no sync required
          Configuration mediaConf = myConfiguration.getChild("mediatypes", false);
          if (mediaConf == null) {
              // default configuration
              this.defaultMediaType = "html";
          } else {
              this.defaultMediaType = mediaConf.getAttribute("default", "html");
          }
          this.mediaTypeNames = new String[1];
          this.mediaTypeNames[0] = this.defaultMediaType;
          boolean found;
          int     i;
          String  name;
  
          Configuration[] childs = mediaConf.getChildren("media");
          PreparedMediaType[] array = new PreparedMediaType[0];
          PreparedMediaType[] copy;
          Configuration current;
          if (childs != null) {
              for(int x = 0; x < childs.length; x++) {
                  current = childs[x];
                  copy = new PreparedMediaType[array.length + 1];
                  System.arraycopy(array, 0, copy, 0, array.length);
                  array = copy;
                  name = current.getAttribute("name");
                  array[array.length-1] = new PreparedMediaType(name, current.getAttribute("useragent"));
                  found = false;
                  i = 0;
                  while ( i < this.mediaTypeNames.length && found == false) {
                      found = this.mediaTypeNames[i].equals(name);
                      i++;
                  }
                  if (found == false) {
                      String[] newStrings = new String[this.mediaTypeNames.length + 1];
                      System.arraycopy(this.mediaTypeNames, 0, newStrings, 0, this.mediaTypeNames.length);
                      newStrings[newStrings.length-1] = name;
                      this.mediaTypeNames = newStrings;
                  }
              }
          }
          this.allMediaTypes = array;
      }
  
      /**
       * Get the current media type
       */
      public void setup(SourceResolver resolver, Map objectModel)
      throws ProcessingException, SAXException, IOException {
          this.request = ObjectModelHelper.getRequest( objectModel );
          // get the media of the current request
          String useragent = this.request.getHeader("User-Agent");
          PreparedMediaType media = null;
          if (useragent != null) {
              int i, l;
              i = 0;
              l = this.allMediaTypes.length;
              while (i < l && media == null) {
                  if (useragent.indexOf(this.allMediaTypes[i].useragent) == -1) {
                      i++;
                  } else {
                      media = this.allMediaTypes[i];
                  }
              }
          }
          this.mediaType = (media == null ? this.defaultMediaType : media.name);
      }
  
      /**
       * Test if the media of the current request is the given value
       */
      public boolean testMedia(String value) {
          // synchronized
          boolean result = false;
  
          String useragent = this.request.getHeader("User-Agent");
          PreparedMediaType theMedia = null;
          int i, l;
          i = 0;
          l = this.allMediaTypes.length;
          while (i < l && theMedia == null) {
              if (useragent.indexOf(this.allMediaTypes[i].useragent) == -1) {
                  i++;
              } else {
                  theMedia = this.allMediaTypes[i];
              }
          }
          if (theMedia != null) {
              result = theMedia.name.equals(value);
          } else {
              result = this.defaultMediaType.equals(value);
          }
  
          return result;
      }
  
      /**
       * Get all media type names
       */
      public String[] getMediaTypes() {
          // synchronized
          return this.mediaTypeNames;
      }
  
      /**
       * Return the current media type
       */
      public String getMediaType() {
          // synchronized
          return this.mediaType;
      }
  
      /**
       * Recyclable
       */
      public void recycle() {
          this.request = null;
          this.mediaType = null;
      }
  }
  
  
  /**
   * This class stores the media type configuration
   */
  final class PreparedMediaType {
  
      String name;
      String useragent;
  
      PreparedMediaType(String name, String useragent) {
          this.name = name;
          this.useragent = useragent;
      }
  }
  
  
  
  1.1                  cocoon-2.1/src/blocks/authentication-fw/java/org/apache/cocoon/webapps/authentication/components/ApplicationConfiguration.java
  
  Index: ApplicationConfiguration.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
  
   Redistribution and use in source and binary forms, with or without modifica-
   tion, are permitted provided that the following conditions are met:
  
   1. Redistributions of  source code must  retain the above copyright  notice,
      this list of conditions and the following disclaimer.
  
   2. Redistributions in binary form must reproduce the above copyright notice,
      this list of conditions and the following disclaimer in the documentation
      and/or other materials provided with the distribution.
  
   3. The end-user documentation included with the redistribution, if any, must
      include  the following  acknowledgment:  "This product includes  software
      developed  by the  Apache Software Foundation  (http://www.apache.org/)."
      Alternately, this  acknowledgment may  appear in the software itself,  if
      and wherever such third-party acknowledgments normally appear.
  
   4. The names "Apache Cocoon" and  "Apache Software Foundation" must  not  be
      used to  endorse or promote  products derived from  this software without
      prior written permission. For written permission, please contact
      apache@apache.org.
  
   5. Products  derived from this software may not  be called "Apache", nor may
      "Apache" appear  in their name,  without prior written permission  of the
      Apache Software Foundation.
  
   THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
   INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
   FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
   APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY DIRECT,
   INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-
   DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS
   OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND ON
   ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
   (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
   THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  
   This software  consists of voluntary contributions made  by many individuals
   on  behalf of the Apache Software  Foundation and was  originally created by
   Stefano Mazzocchi  <st...@apache.org>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.cocoon.webapps.authentication.components;
  
  import java.io.IOException;
  import java.util.HashMap;
  import java.util.Map;
  
  import org.apache.avalon.framework.configuration.Configuration;
  import org.apache.avalon.framework.configuration.ConfigurationException;
  import org.apache.cocoon.ProcessingException;
  import org.apache.excalibur.source.SourceParameters;
  import org.apache.excalibur.source.SourceResolver;
  import org.xml.sax.SAXException;
  
  /**
   * This object stores information about an application configuration
   * inside a handler configuration.
   *
   * @author <a href="mailto:cziegeler@apache.org">Carsten Ziegeler</a>
   * @version CVS $Id: ApplicationConfiguration.java,v 1.1 2003/04/21 19:26:14 cziegeler Exp $
  */
  public final class ApplicationConfiguration
  implements java.io.Serializable {
  
      /** The unique name of the handler */
      private String name;
  
      /** The load resource (optional) */
      private String loadResource;
  
      /** The save resource (optional) */
      private String saveResource;
  
      /** The load resource parameters (optional) */
      private SourceParameters loadResourceParameters;
  
      /** The save resource parameters (optional) */
      private SourceParameters saveResourceParameters;
  
      /** Is the application loaded on demand */
      private boolean loadOnDemand = false;
  
      /** The corresponding handler */
      private HandlerConfiguration handler;
  
      /** The configuration fragments */
      private Map configurations;
  
      /**
       * Construct a new application handler
       */
      public ApplicationConfiguration(HandlerConfiguration handler, String name)
      throws ProcessingException {
          this.handler = handler;
          this.name = name;
          if (name.indexOf('_') != -1
              || name.indexOf(':') != -1
              || name.indexOf('/') != -1) {
             throw new ProcessingException("application name must not contain one of the characters ':','_' or '/'.");
          }
          this.configurations = new HashMap(3, 2);
      }
  
      /**
       * Configure an application
       */
      public void configure(SourceResolver resolver, Configuration appconf)
      throws ProcessingException, SAXException, IOException, ConfigurationException {
          Configuration child = null;
  
          // test for loadondemand attribute
          this.loadOnDemand = appconf.getAttributeAsBoolean("loadondemand", false);
  
          // get load resource (optinal)
          child = appconf.getChild("load", false);
          if (child != null) {
              this.loadResource = child.getAttribute("uri");
              this.loadResourceParameters = SourceParameters.create(child);
          }
  
          // get save resource (optional)
          child =  appconf.getChild("save", false);
          if (child != null) {
              this.saveResource = child.getAttribute("uri");
              this.saveResourceParameters = SourceParameters.create(child);
          }
  
          // get configurations (optional)
          Configuration[] configurations = appconf.getChildren("configuration");
          if (configurations != null) {
              for(int i = 0; i < configurations.length; i++) {
                  child = configurations[i];
                  String value = child.getAttribute("name");
                  if (this.getConfiguration(value) != null) {
                      throw new ConfigurationException("Configuration names must be unique for application " + this.name + ": " + value);
                  }
                  this.configurations.put(value, child);
              }
          }
      }
  
      /**
       * Get the application name.
       */
      public String getName() { return name; }
  
      /**
       * Get the handler
       */
      public HandlerConfiguration getHandler() { return handler; }
  
      /**
       * Get the load resource
       */
      public String getLoadResource() {
          return this.loadResource;
      }
  
      /**
       * Get the save resource
       */
      public String getSaveResource() {
          return this.saveResource;
      }
  
      /**
       * Get the load resource parameters
       */
      public SourceParameters getLoadResourceParameters() {
          return this.loadResourceParameters;
      }
  
      /**
       * Get the save resource parameters
       */
      public SourceParameters getSaveResourceParameters() {
          return this.saveResourceParameters;
      }
  
      public boolean getLoadOnDemand() { return loadOnDemand; }
  
      /**
       * Get the configuration
       */
      public Configuration getConfiguration(String name) {
          return (Configuration)this.configurations.get(name);
      }
  
  }
  
  
  
  1.1                  cocoon-2.1/src/blocks/authentication-fw/java/org/apache/cocoon/webapps/authentication/components/UserHandler.java
  
  Index: UserHandler.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
  
   Redistribution and use in source and binary forms, with or without modifica-
   tion, are permitted provided that the following conditions are met:
  
   1. Redistributions of  source code must  retain the above copyright  notice,
      this list of conditions and the following disclaimer.
  
   2. Redistributions in binary form must reproduce the above copyright notice,
      this list of conditions and the following disclaimer in the documentation
      and/or other materials provided with the distribution.
  
   3. The end-user documentation included with the redistribution, if any, must
      include  the following  acknowledgment:  "This product includes  software
      developed  by the  Apache Software Foundation  (http://www.apache.org/)."
      Alternately, this  acknowledgment may  appear in the software itself,  if
      and wherever such third-party acknowledgments normally appear.
  
   4. The names "Apache Cocoon" and  "Apache Software Foundation" must  not  be
      used to  endorse or promote  products derived from  this software without
      prior written permission. For written permission, please contact
      apache@apache.org.
  
   5. Products  derived from this software may not  be called "Apache", nor may
      "Apache" appear  in their name,  without prior written permission  of the
      Apache Software Foundation.
  
   THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
   INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
   FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
   APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY DIRECT,
   INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-
   DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS
   OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND ON
   ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
   (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
   THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  
   This software  consists of voluntary contributions made  by many individuals
   on  behalf of the Apache Software  Foundation and was  originally created by
   Stefano Mazzocchi  <st...@apache.org>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.cocoon.webapps.authentication.components;
  
  import java.util.ArrayList;
  import java.util.List;
  
  import org.apache.cocoon.ProcessingException;
  import org.apache.cocoon.webapps.session.context.SessionContext;
  
  /**
   * The authentication Handler.
   *
   * @author <a href="mailto:cziegeler@apache.org">Carsten Ziegeler</a>
   * @version CVS $Id: UserHandler.java,v 1.1 2003/04/21 19:26:14 cziegeler Exp $
  */
  public final class UserHandler
  implements java.io.Serializable {
  
      /** The corresponding handler */
      private HandlerConfiguration handler;
      
      /** Are all apps loaded? */
      private boolean appsLoaded = false;
  
      /** The handler contexts */
      private List handlerContexts = new ArrayList(2);
  
     /**
       * Create a new handler object.
       */
      public UserHandler(HandlerConfiguration handler) {
          this.handler = handler;
      }
  
      public void setApplicationsLoaded(boolean value)
      throws ProcessingException {
          this.appsLoaded = value;
      }
  
      public boolean getApplicationsLoaded()
      throws ProcessingException {
          if ( this.handler.getApplications().isEmpty() ) {
              return true;
          } else {
              return this.appsLoaded;
          }
      }
      
      /**
       * Add a handler context
       */
      public void addHandlerContext(SessionContext context) {
          this.handlerContexts.add( context );
      }
  
      /**
       * Get handler contexts
       */
      public List getHandlerContexts() {
          return this.handlerContexts;
      }
  
      /**
       * Clear handler contexts
       */
      public void clearHandlerContexts() {
          this.handlerContexts.clear();
      }
      
      /**
       * Get the handler name
       */
      public String getHandlerName() {
          return this.handler.getName();
      }
  }
  
  
  
  1.1                  cocoon-2.1/src/blocks/authentication-fw/java/org/apache/cocoon/webapps/authentication/components/UserStatus.java
  
  Index: UserStatus.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
  
   Redistribution and use in source and binary forms, with or without modifica-
   tion, are permitted provided that the following conditions are met:
  
   1. Redistributions of  source code must  retain the above copyright  notice,
      this list of conditions and the following disclaimer.
  
   2. Redistributions in binary form must reproduce the above copyright notice,
      this list of conditions and the following disclaimer in the documentation
      and/or other materials provided with the distribution.
  
   3. The end-user documentation included with the redistribution, if any, must
      include  the following  acknowledgment:  "This product includes  software
      developed  by the  Apache Software Foundation  (http://www.apache.org/)."
      Alternately, this  acknowledgment may  appear in the software itself,  if
      and wherever such third-party acknowledgments normally appear.
  
   4. The names "Apache Cocoon" and  "Apache Software Foundation" must  not  be
      used to  endorse or promote  products derived from  this software without
      prior written permission. For written permission, please contact
      apache@apache.org.
  
   5. Products  derived from this software may not  be called "Apache", nor may
      "Apache" appear  in their name,  without prior written permission  of the
      Apache Software Foundation.
  
   THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
   INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
   FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
   APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY DIRECT,
   INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-
   DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS
   OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND ON
   ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
   (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
   THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  
   This software  consists of voluntary contributions made  by many individuals
   on  behalf of the Apache Software  Foundation and was  originally created by
   Stefano Mazzocchi  <st...@apache.org>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.cocoon.webapps.authentication.components;
  
  import java.util.HashMap;
  import java.util.Map;
  
  /**
   * The authentication Handler.
   *
   * @author <a href="mailto:cziegeler@apache.org">Carsten Ziegeler</a>
   * @version CVS $Id: UserStatus.java,v 1.1 2003/04/21 19:26:14 cziegeler Exp $
  */
  public final class UserStatus
  implements java.io.Serializable {
  
      /** The handlers */
      private Map handlers = new HashMap(7);
  
     /**
       * Create a new handler object.
       */
      public UserStatus() {
      }
  
      public void addHandler(UserHandler value) {
          this.handlers.put(value.getHandlerName(), value);
      }
  
      public void removeHandler(String name) {
          this.handlers.remove( name );
      }
      
      public UserHandler getUserHandler(String name) {
          return (UserHandler) this.handlers.get( name );
      }
  }
  
  
  
  1.1                  cocoon-2.1/src/blocks/authentication-fw/java/org/apache/cocoon/webapps/authentication/MediaManager.java
  
  Index: MediaManager.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
  
   Redistribution and use in source and binary forms, with or without modifica-
   tion, are permitted provided that the following conditions are met:
  
   1. Redistributions of  source code must  retain the above copyright  notice,
      this list of conditions and the following disclaimer.
  
   2. Redistributions in binary form must reproduce the above copyright notice,
      this list of conditions and the following disclaimer in the documentation
      and/or other materials provided with the distribution.
  
   3. The end-user documentation included with the redistribution, if any, must
      include  the following  acknowledgment:  "This product includes  software
      developed  by the  Apache Software Foundation  (http://www.apache.org/)."
      Alternately, this  acknowledgment may  appear in the software itself,  if
      and wherever such third-party acknowledgments normally appear.
  
   4. The names "Apache Cocoon" and  "Apache Software Foundation" must  not  be
      used to  endorse or promote  products derived from  this software without
      prior written permission. For written permission, please contact
      apache@apache.org.
  
   5. Products  derived from this software may not  be called "Apache", nor may
      "Apache" appear  in their name,  without prior written permission  of the
      Apache Software Foundation.
  
   THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
   INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
   FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
   APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY DIRECT,
   INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-
   DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS
   OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND ON
   ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
   (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
   THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  
   This software  consists of voluntary contributions made  by many individuals
   on  behalf of the Apache Software  Foundation and was  originally created by
   Stefano Mazzocchi  <st...@apache.org>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.cocoon.webapps.authentication;
  
  
  
  
  /**
   * This is the media manager.
   * It provides simple support for developing multi-channel applications
   *
   * @author <a href="mailto:cziegeler@apache.org">Carsten Ziegeler</a>
   * @version CVS $Id: MediaManager.java,v 1.1 2003/04/21 19:26:15 cziegeler Exp $
  */
  public interface MediaManager {
  
      /** The Avalon Role */
      public static final String ROLE = MediaManager.class.getName();
  
      /**
       * Test if the media of the current request is the given value
       */
      boolean testMedia(String value);
  
      /**
       * Get all media type names
       */
      String[] getMediaTypes();
  
      /**
       * Return the current media type
       */
      String getMediaType();
  }
  
  
  
  1.1                  cocoon-2.1/src/blocks/authentication-fw/java/org/apache/cocoon/webapps/authentication/AuthenticationManager.java
  
  Index: AuthenticationManager.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
  
   Redistribution and use in source and binary forms, with or without modifica-
   tion, are permitted provided that the following conditions are met:
  
   1. Redistributions of  source code must  retain the above copyright  notice,
      this list of conditions and the following disclaimer.
  
   2. Redistributions in binary form must reproduce the above copyright notice,
      this list of conditions and the following disclaimer in the documentation
      and/or other materials provided with the distribution.
  
   3. The end-user documentation included with the redistribution, if any, must
      include  the following  acknowledgment:  "This product includes  software
      developed  by the  Apache Software Foundation  (http://www.apache.org/)."
      Alternately, this  acknowledgment may  appear in the software itself,  if
      and wherever such third-party acknowledgments normally appear.
  
   4. The names "Apache Cocoon" and  "Apache Software Foundation" must  not  be
      used to  endorse or promote  products derived from  this software without
      prior written permission. For written permission, please contact
      apache@apache.org.
  
   5. Products  derived from this software may not  be called "Apache", nor may
      "Apache" appear  in their name,  without prior written permission  of the
      Apache Software Foundation.
  
   THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
   INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
   FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
   APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY DIRECT,
   INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-
   DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS
   OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND ON
   ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
   (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
   THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  
   This software  consists of voluntary contributions made  by many individuals
   on  behalf of the Apache Software  Foundation and was  originally created by
   Stefano Mazzocchi  <st...@apache.org>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.cocoon.webapps.authentication;
  
  import org.apache.avalon.framework.configuration.Configuration;
  import org.apache.cocoon.ProcessingException;
  import org.apache.cocoon.webapps.session.context.SessionContext;
  
  /**
   * This is the basis authentication manager.
   *
   * @author <a href="mailto:cziegeler@apache.org">Carsten Ziegeler</a>
   * @version CVS $Id: AuthenticationManager.java,v 1.1 2003/04/21 19:26:15 cziegeler Exp $
  */
  public interface AuthenticationManager {
  
      /** The Avalon Role */
      public static final String ROLE = AuthenticationManager.class.getName();
  
      /**
       * Get the configuration if available
       * @return Return the configuration or <code>null</code>
       */
      Configuration getModuleConfiguration(String module)
      throws ProcessingException;
  
      /**
       * Get the application session context
       */
      SessionContext getContext();
      
      /**
       * Get the current user
      User getUser();
       */
  }