Package org.apache.cocoon.webapps.session.context

Examples of org.apache.cocoon.webapps.session.context.SessionContext


                    this.getLogger().info("Authenticator: User authenticated using handler '" + configuration.getName()+"'");
                }
               
                handler = new UserHandler(configuration);
               
                SessionContext context = handler.getContext();

                MediaManager mediaManager = null;
                String mediaType;
                try {
                    mediaManager = (MediaManager)this.manager.lookup( MediaManager.ROLE );
                    mediaType = mediaManager.getMediaType();
                } catch (ServiceException se) {
                    throw new ProcessingException("Unable to lookup media manager.", se);
                } finally {
                    this.manager.release( mediaManager );
                }
                synchronized(context) {
                    // add special nodes to the authentication block:
                    // useragent, type and media
                    Element specialElement;
                    Text    specialValue;
                    Element authNode;

                    authNode = (Element)doc.getFirstChild();

                    specialElement = doc.createElementNS(null, "type");
                    specialValue = doc.createTextNode("cocoon.authentication");
                    specialElement.appendChild(specialValue);
                    authNode.appendChild(specialElement);

                    specialElement = doc.createElementNS(null, "media");
                    specialValue = doc.createTextNode(mediaType);
                    specialElement.appendChild(specialValue);
                    authNode.appendChild(specialElement);

                    // store the authentication data in the context
                    context.setNode("/" + configuration.getName(), doc);

                    // And now load applications
                    boolean loaded = true;
                    Iterator applications = configuration.getApplications().values().iterator();

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

                } // end sync
            }
        }
       
        if ( !isValid ) {
            if (this.getLogger().isInfoEnabled() ) {
                this.getLogger().info("Authenticator: Failed authentication using handler '" +  configuration.getName()+"'");
            }
            // get the /authentication/data Node if available
            Node data = null;

            if (doc != null) {
                data = DOMUtil.getFirstNodeFromPath(doc, 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
            DocumentFragment 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));
            }
           
            // now set this information in the temporary context
            SessionManager sessionManager = null;
            try {
                sessionManager = (SessionManager) this.manager.lookup( SessionManager.ROLE );
                SessionContext temp = sessionManager.getContext( SessionConstants.TEMPORARY_CONTEXT );
                temp.appendXML("/", authenticationFragment);
            } catch ( ServiceException se ) {
                throw new ProcessingException("Unable to lookup session manager.", se);
            } finally {
                this.manager.release( sessionManager );
            }
View Full Code Here


                    }
                    // 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,
                                                                     this.request);

                    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;
View Full Code Here

    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);
                }
            }
        }
View Full Code Here

        // synchronized via context
        if (this.getLogger().isDebugEnabled() ) {
            this.getLogger().debug("BEGIN logout handler=" + logoutHandlerName +
                                   ", mode="+mode);
        }
        SessionContext context = this.getAuthenticationSessionContext(false);

        if (context != null && logoutHandlerName != null) {

            // remove context
            context.removeXML(logoutHandlerName);
            // FIXME (CZ): The sessionContextImpl should not be null, but
            //             it is sometimes. Why?
            SessionContextImpl sessionContextImpl = (SessionContextImpl)
                        (this.getSessionManager().getContext(AuthenticationConstants.SESSION_CONTEXT_NAME));
            if (sessionContextImpl != null) {
                sessionContextImpl.cleanParametersCache(logoutHandlerName);
            } else if (this.getLogger().isWarnEnabled()) {
                this.getLogger().warn("AuthenticationManager:logout() - sessionContextImpl is null");
            }
            Handler logoutHandler = (Handler)this.getHandler(logoutHandlerName);

            final List handlerContexts = logoutHandler.getHandlerContexts();
            final Iterator iter = handlerContexts.iterator();
            while ( iter.hasNext() ) {
                final SessionContext deleteContext = (SessionContext) iter.next();
                this.getSessionManager().deleteContext( deleteContext.getName() );
            }
            logoutHandler.clearHandlerContexts();
            this.handlerManager.removeUserHandler( logoutHandler, this.request );
            if (logoutHandlerName.equals(this.handlerName)) {
                this.handlerName = null;
View Full Code Here

        // synchronized
        if (this.getLogger().isDebugEnabled() == true) {
            this.getLogger().debug("BEGIN createHandlerContext name="+name);
        }

        SessionContext context = null;

        if (this.handler != null) {

            final Session session = this.getSessionManager().getSession(false);
            synchronized(session) {
View Full Code Here

        // synchronized
        if (this.handler == null) {
            return new SourceParameters();
        }
        if (path == null) {
            SessionContext context = this.getAuthenticationSessionContext(false);
            SourceParameters pars = (SourceParameters)context.getAttribute("cachedparameters_" + this.handler.getName());
            if (pars == null) {
                 pars = this.createParameters(null, this.handlerName, path, this.applicationName);
                 context.setAttribute("cachedparameters_" + this.handler.getName(), pars);
            }
            return pars;
        }
        return this.createParameters(null, this.handlerName, path, this.applicationName);
    }
View Full Code Here

    throws ProcessingException {
        if (this.handler == null) {
            // this is only a fallback
            return EMPTY_MAP;
        }
        SessionContext context = this.getAuthenticationSessionContext(false);
        Map map = (Map)context.getAttribute("cachedmap_" + this.handler.getName());
        if (map == null) {
            map = new HashMap();
            Parameters pars = this.createParameters(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_" + this.handler.getName(), map);
        }
        return map;
    }
View Full Code Here

    public SessionContext getSessionContext(String           name,
                                            Map              objectModel,
                                            SourceResolver   resolver,
                                            ComponentManager manager)
    throws ProcessingException {
        SessionContext context = null;
        if (name.equals(org.apache.cocoon.webapps.authentication.AuthenticationConstants.SESSION_CONTEXT_NAME) ) {
            RequestState state = RequestState.getState();
            if ( null != state ) {
                UserHandler handler = state.getHandler();
                if ( handler != null ) {
View Full Code Here

    public SessionContext getSessionContext(String           name,
                                            Map              objectModel,
                                            SourceResolver   resolver,
                                            ComponentManager manager)
    throws ProcessingException {
        SessionContext context = null;
        if (name.equals(org.apache.cocoon.webapps.authentication.AuthenticationConstants.SESSION_CONTEXT_NAME) == true) {
            final Request req = ObjectModelHelper.getRequest(objectModel);
            final Session session = req.getSession(false);
           
            if ( null != session ) {
View Full Code Here

    public SessionContext getSessionContext(String name,
                                            Map objectModel,
                                            SourceResolver   resolver,
                                            ComponentManager manager)
    throws ProcessingException {
        SessionContext context = null;
        if (name.equals(PortalConstants.SESSION_CONTEXT_NAME) == true) {
            Request req = ObjectModelHelper.getRequest(objectModel);
            Session session = req.getSession(false);
            if (session != null) {
View Full Code Here

TOP

Related Classes of org.apache.cocoon.webapps.session.context.SessionContext

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.