Package org.apache.cocoon.webapps.authentication.user

Examples of org.apache.cocoon.webapps.authentication.user.UserHandler


        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);
        }

        Authenticator authenticator = this.lookupAuthenticator( config );
        try {
            Authenticator.AuthenticationResult result = authenticator.authenticate( config, parameters );
            if (result != null) {
                if (result.valid) {
                    AuthenticationContext authContext = new AuthenticationContext(this.context, this.xpathProcessor, this.resolver);
                    handler = new UserHandler(config, authContext);
                    // store the authentication data in the context
                    authContext.init(result.result);
                } else {
                    // now set the failure information in the temporary context
                    ContextManager contextManager = null;
                    try {
                        contextManager = (ContextManager) this.manager.lookup( ContextManager.ROLE );
                        SessionContext temp = contextManager.getContext( SessionConstants.TEMPORARY_CONTEXT );
   
                        final DocumentFragment fragment = result.result.createDocumentFragment();
                        final Node root = result.result.getDocumentElement();
                        root.normalize();
                        Node child;
                        boolean appendedNode = false;
                        while (root.hasChildNodes() ) {
                            child = root.getFirstChild();
                            root.removeChild(child);
                            // Leave out empty text nodes before any other node
                            if (appendedNode
                                || child.getNodeType() != Node.TEXT_NODE
                                || child.getNodeValue().trim().length() > 0) {
                                fragment.appendChild(child);
                                appendedNode = true;
                            }
                        }
                        temp.appendXML("/", fragment);
                    } catch ( ServiceException se ) {
                        throw new ProcessingException("Unable to lookup session manager.", se);
                    } finally {
                        this.manager.release( contextManager );
                    }
                }
            }
        } finally {
            this.releaseAuthenticator( authenticator, config );
        }

        if ( handler != null ) {
            // create UserStatus
            final UserState status = this.createUserState();

            status.addHandler( handler );
            this.updateUserState();

            // update RequestState
            RequestState state = new RequestState( handler, applicationName);
            this.setState( state );
            state.initialize( this.resolver );

            // And now load applications
            Iterator applications = handler.getHandlerConfiguration().getApplications().values().iterator();

            while ( applications.hasNext() ) {
                ApplicationConfiguration appHandler = (ApplicationConfiguration)applications.next();
                if ( !appHandler.getLoadOnDemand() ) {
                    handler.getContext().loadApplicationXML( appHandler, this.resolver );
                }
            }
        }

        return handler;
View Full Code Here


        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 ) {
            if (redirector != null) {
                // create parameters
                SourceParameters parameters = config.getRedirectParameters();
View Full Code Here

        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 ) {

            // Do we save something on logout?
            /*

            if ( config.saveOnLogout()
                 && config.getSaveResource() != null) {
                final AuthenticationContext authContext = handler.getContext();
                try {
                    // This might not work, because of the missing state
                    authContext.saveXML("/authentication",
                                    null,
                                    ContextHelper.getObjectModel(this.context),
                                    this.resolver, this.manager);
                } catch (Exception ignore) {
                    // we don't want to stop the logout process
                    // because of errors during save
                    this.getLogger().error("Exception while saving authentication information.", ignore);
                }
            }
            // save applications (if configured)
            Iterator iter = config.getApplications().values().iterator();
            while ( iter.hasNext() ) {
                ApplicationConfiguration appConfig = (ApplicationConfiguration) iter.next();
                if ( appConfig.saveOnLogout()
                     && appConfig.getSaveResource() != null ) {
                     // ???
                }
            }
            */
            // notify the authenticator
            try {
                this.lookupAuthenticator(config).logout(handler);
            } catch (Exception ignore) {
                // we really ignore any exception!
            }

            List applicationContexts = handler.getApplicationContexts();
            if ( applicationContexts != null ) {
                ContextManager contextManager = null;

                try {
                    contextManager = (ContextManager)this.manager.lookup(ContextManager.ROLE);
View Full Code Here

    public SessionContext createApplicationContext(String name,
                                                   String loadURI,
                                                   String saveURI)
    throws ProcessingException {
        RequestState state = this.getState();
        UserHandler handler = state.getHandler();

        SessionContext context = null;

        if ( handler != null ) {
            ContextManager contextManager = null;
            try {
                contextManager = (ContextManager)this.manager.lookup(ContextManager.ROLE);
                // create new context
                context = contextManager.createContext(name, loadURI, saveURI);
                handler.addApplicationContext( name );

            } catch (ServiceException ce) {
                throw new ProcessingException("Unable to create session context.", ce);
            } catch (IOException ioe) {
                throw new ProcessingException("Unable to create session context.", ioe);
View Full Code Here

        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);
        }

        Authenticator authenticator = this.lookupAuthenticator( config );
        try {
            Authenticator.AuthenticationResult result = authenticator.authenticate( config, parameters );
            if (result != null) {
                if (result.valid) {
                    AuthenticationContext authContext = new AuthenticationContext(this.context, this.xpathProcessor, this.resolver);
                    handler = new UserHandler(config, authContext);
                    // store the authentication data in the context
                    authContext.init(result.result);
                } else {
                    // now set the failure information in the temporary context
                    ContextManager contextManager = null;
                    try {
                        contextManager = (ContextManager) this.manager.lookup( ContextManager.ROLE );
                        SessionContext temp = contextManager.getContext( SessionConstants.TEMPORARY_CONTEXT );
   
                        final DocumentFragment fragment = result.result.createDocumentFragment();
                        final Node root = result.result.getDocumentElement();
                        root.normalize();
                        Node child;
                        boolean appendedNode = false;
                        while (root.hasChildNodes() ) {
                            child = root.getFirstChild();
                            root.removeChild(child);
                            // Leave out empty text nodes before any other node
                            if (appendedNode
                                || child.getNodeType() != Node.TEXT_NODE
                                || child.getNodeValue().trim().length() > 0) {
                                fragment.appendChild(child);
                                appendedNode = true;
                            }
                        }
                        temp.appendXML("/", fragment);
                    } catch ( ServiceException se ) {
                        throw new ProcessingException("Unable to lookup session manager.", se);
                    } finally {
                        this.manager.release( contextManager );
                    }
                }
            }
        } finally {
            this.releaseAuthenticator( authenticator, config );
        }

        if ( handler != null ) {
            // create UserStatus
            final UserState status = this.createUserState();

            status.addHandler( handler );
            this.updateUserState();

            // update RequestState
            RequestState state = new RequestState( handler, applicationName);
            this.setState( state );
            state.initialize( this.resolver );

            // And now load applications
            Iterator applications = handler.getHandlerConfiguration().getApplications().values().iterator();

            while ( applications.hasNext() ) {
                ApplicationConfiguration appHandler = (ApplicationConfiguration)applications.next();
                if ( !appHandler.getLoadOnDemand() ) {
                    handler.getContext().loadApplicationXML( appHandler, this.resolver );
                }
            }
        }

        return handler;
View Full Code Here

        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 ) {
            if (redirector != null) {
                // create parameters
                SourceParameters parameters = config.getRedirectParameters();
View Full Code Here

        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 ) {

            // Do we save something on logout?
            /*

            if ( config.saveOnLogout()
                 && config.getSaveResource() != null) {
                final AuthenticationContext authContext = handler.getContext();
                try {
                    // This might not work, because of the missing state
                    authContext.saveXML("/authentication",
                                    null,
                                    ContextHelper.getObjectModel(this.context),
                                    this.resolver, this.manager);
                } catch (Exception ignore) {
                    // we don't want to stop the logout process
                    // because of errors during save
                    this.getLogger().error("Exception while saving authentication information.", ignore);
                }
            }
            // save applications (if configured)
            Iterator iter = config.getApplications().values().iterator();
            while ( iter.hasNext() ) {
                ApplicationConfiguration appConfig = (ApplicationConfiguration) iter.next();
                if ( appConfig.saveOnLogout()
                     && appConfig.getSaveResource() != null ) {
                     // ???
                }
            }
            */
            // notify the authenticator
            try {
                this.lookupAuthenticator(config).logout(handler);
            } catch (Exception ignore) {
                // we really ignore any exception!
            }

            List applicationContexts = handler.getApplicationContexts();
            if ( applicationContexts != null ) {
                ContextManager contextManager = null;

                try {
                    contextManager = (ContextManager)this.manager.lookup(ContextManager.ROLE);
View Full Code Here

        }

        this.xmlConsumer.startDocument();
        if ( state != null ) {
            try {
                UserHandler userhandler = state.getHandler();

                Configuration conf = state.getModuleConfiguration("single-role-user-management");
                if (conf == null) {
                    throw new ProcessingException("Module configuration 'single-role-user-management' for authentication user management generator not found.");
                }
                UserManagementHandler handler = new UserManagementHandler(conf,
                                                                          state.getApplicationName());
                this.showConfiguration(this.xmlConsumer, this.source, handler, userhandler.getContext());

            } catch (ConfigurationException ex) {
                throw new ProcessingException("ConfigurationException: " + ex, ex);
            }
        }
View Full Code Here

        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);
        }
       
        Authenticator authenticator = this.lookupAuthenticator( config );
View Full Code Here

        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 ) {
            if (redirector != null) {
                // create parameters
                SourceParameters parameters = config.getRedirectParameters();
View Full Code Here

TOP

Related Classes of org.apache.cocoon.webapps.authentication.user.UserHandler

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.