Package org.apache.cocoon.sunshine.context

Examples of org.apache.cocoon.sunshine.context.SessionContext


                }
            }
            consumer.endElement("", "menue", "menue");
        }

        SessionContext context = this.getSunRiseSessionContext(true);

        synchronized (context) {

            String state = this.request.getParameter(SunRise.REQ_PARAMETER_STATE);
            if (state == null) {
                state = (isAdmin == true ? "main" : "seluser");
            }

            if (state.equals("addrole") == true) {
                String role = this.request.getParameter(SunRise.REQ_PARAMETER_ROLE);
                if (role != null && role.trim().length() > 0) {
                    SourceParameters pars = new SourceParameters();
                    // first include all request parameters
                    Enumeration requestParameters = this.request.getParameterNames();
                    String current;
                    while (requestParameters.hasMoreElements() == true) {
                        current = (String)requestParameters.nextElement();
                        pars.setParameter(current, this.request.getParameter(current));
                    }
                    this.addRole(role, pars);
                } else {
                    role = null;
                }
                context.setAttribute(SunRise.SESSION_CONTEXT_ATTRIBUTE_ADMIN_ROLE, null);
            }

            if (state.equals("delrole") == true) {
                try {
                    String role = this.request.getParameter(SunRise.REQ_PARAMETER_ROLE);
                    if (role != null) {
                        // first delete user
                        DocumentFragment userDF = this.getUsers(role, null);
                        NodeList         users   = null;
                        if (userDF != null) users = XMLUtil.selectNodeList(userDF, "users/user");
                        if (users != null) {
                            for(int i = 0; i < users.getLength(); i++) {
                                this.deleteUser(role, XMLUtil.getValueOf(users.item(i), "ID"), null);
                            }
                        }
                        this.deleteRole(role, null);
                    }
                    context.setAttribute(SunRise.SESSION_CONTEXT_ATTRIBUTE_ADMIN_ROLE, null);
                } catch (javax.xml.transform.TransformerException local) {
                    throw new ProcessingException("TransformerException: " + local, local);
                }
            }


            if (state.equals("chguser") == true) {
                String role;
                String id;
                String user;

                if (isAdmin == false) {
                    SourceParameters pars = this.createParameters(null);
                    id = pars.getParameter("ID", null);
                    role = pars.getParameter("role", null);
                    user = "old";
                } else {
                    role = this.request.getParameter(SunRise.REQ_PARAMETER_ROLE);
                    id   = this.request.getParameter(SunRise.REQ_PARAMETER_ID);
                    user = this.request.getParameter(SunRise.REQ_PARAMETER_USER);
                }

                boolean addingNewUserFailed = false;
                if (role != null && id != null && user != null) {
                    if (user.equals("new") == true) {
                        SourceParameters pars = new SourceParameters();
                        // first include all request parameters
                        Enumeration requestParameters = this.request.getParameterNames();
                        String current;
                        while (requestParameters.hasMoreElements() == true) {
                            current = (String)requestParameters.nextElement();
                            pars.setParameter(current, this.request.getParameter(current));
                        }
                        addingNewUserFailed = !this.addUser(role, id, pars);
                        if (addingNewUserFailed == false) {
                            consumer.startElement("", "addeduser", "addeduser", attr);
                            consumer.characters(id.toCharArray(), 0, id.length());
                            consumer.endElement("", "addeduser", "addeduser");
                        }
                    } else {
                        String delete = this.request.getParameter("sunrisedeluser");
                        if (delete != null && delete.equals("true") == true) {
                            this.deleteUser(role, id, null);
                        } else {
                            SourceParameters pars = new SourceParameters();
                            // first include all request parameters
                            Enumeration requestParameters = this.request.getParameterNames();
                            String current;
                            while (requestParameters.hasMoreElements() == true) {
                                current = (String)requestParameters.nextElement();
                                pars.setParameter(current, this.request.getParameter(current));
                            }
                            this.changeUser(role, id, pars);
                        }
                    }
                    context.setAttribute(SunRise.SESSION_CONTEXT_ATTRIBUTE_ADMIN_ROLE, null);
                }
                if (addingNewUserFailed == false) {
                    state = (isAdmin == true ? "adduser" : "seluser");
                } else {
                    state = "erruser";
                }
            }

            if (state.equals("seluser") == true) {
                String role;
                String id;

                if (isAdmin == false) {
                    SourceParameters pars = this.createParameters(null);
                    id = pars.getParameter("ID", null);
                    role = pars.getParameter("role", null);
                } else {
                    role = this.request.getParameter(SunRise.REQ_PARAMETER_ROLE);
                    id   = this.request.getParameter(SunRise.REQ_PARAMETER_ID);
                }
                if (role != null && id != null) {
                    context.setAttribute(SunRise.SESSION_CONTEXT_ATTRIBUTE_ADMIN_ROLE, role);

                    // include users
                    DocumentFragment userDF = this.getUsers(role, id);
                    Element          users   = null;
                    try {
                        if (userDF != null) users = (Element)XMLUtil.getSingleNode(userDF, "users/user");
                    } catch (javax.xml.transform.TransformerException local) {
                        throw new ProcessingException("TransformerException: " + local, local);
                    }
                    consumer.startElement("", "uservalues", "uservalues", attr);
                    if (users != null && users.hasChildNodes() == true) {
                        NodeList childs = users.getChildNodes();
                        for(int i = 0; i < childs.getLength(); i++) {
                            if (childs.item(i).getNodeType() == Node.ELEMENT_NODE)
                                IncludeXMLConsumer.includeNode(childs.item(i), consumer, consumer);
                        }
                    }
                    consumer.endElement("", "uservalues", "uservalues");
                }
                consumer.startElement("", "user", "user", attr);
                consumer.characters("old".toCharArray(), 0, 3);
                consumer.endElement("", "user", "user");
                if (isAdmin == false) {
                    consumer.startElement("", "role", "role", attr);
                    consumer.characters(role.toCharArray(), 0, role.length());
                    consumer.endElement("", "role", "role");
               }
            }

            if (state.equals("erruser") == true) {
                String role;
                String id;

                if (isAdmin == false) {
                    SourceParameters pars = this.createParameters(null);
                    id = pars.getParameter("ID", null);
                    role = pars.getParameter("role", null);
                } else {
                    role = this.request.getParameter(SunRise.REQ_PARAMETER_ROLE);
                    id   = this.request.getParameter(SunRise.REQ_PARAMETER_ID);
                }
                if (role != null && id != null) {
                    context.setAttribute(SunRise.SESSION_CONTEXT_ATTRIBUTE_ADMIN_ROLE, role);

                    // include users
                    DocumentFragment userDF = this.getUsers(role, id);
                    Element          users   = null;
                    try {
                        if (userDF != null) users = (Element)XMLUtil.getSingleNode(userDF, "users/user");
                    } catch (javax.xml.transform.TransformerException local) {
                        throw new ProcessingException("TransformerException: " + local, local);
                    }
                    consumer.startElement("", "uservalues", "uservalues", attr);
                    if (users != null && users.hasChildNodes() == true) {
                        NodeList childs = users.getChildNodes();
                        for(int i = 0; i < childs.getLength(); i++) {
                            if (childs.item(i).getNodeType() == Node.ELEMENT_NODE)
                                IncludeXMLConsumer.includeNode(childs.item(i), consumer, consumer);
                        }
                    }
                    consumer.endElement("", "uservalues", "uservalues");
                }
                consumer.startElement("", "user", "user", attr);
                consumer.characters("error".toCharArray(), 0, 5);
                consumer.endElement("", "user", "user");
                if (isAdmin == false) {
                    consumer.startElement("", "role", "role", attr);
                    consumer.characters(role.toCharArray(), 0, role.length());
                    consumer.endElement("", "role", "role");
               }
            }

            if (state.equals("adduser") == true) {
                consumer.startElement("", "user", "user", attr);
                consumer.characters("new".toCharArray(), 0, 3);
                consumer.endElement("", "user", "user");
            }

            if (state.equals("selrole") == true) {
                String role = this.request.getParameter(SunRise.REQ_PARAMETER_ROLE);
                context.setAttribute(SunRise.SESSION_CONTEXT_ATTRIBUTE_ADMIN_ROLE, role);
                // include users
                DocumentFragment userDF = this.getUsers(role, null);
                Node             users   = null;
                try {
                    if (userDF != null) users = XMLUtil.getSingleNode(userDF, "users");
                } catch (javax.xml.transform.TransformerException local) {
                    throw new ProcessingException("TransformerException: " + local, local);
                }
                IncludeXMLConsumer.includeNode(users, consumer, consumer);
            }

            if (isAdmin == true) {
                // include roles
                DocumentFragment rolesDF = this.getRoles();
                Node             roles   = null;
                try {
                    if (rolesDF != null) roles = XMLUtil.getSingleNode(rolesDF, "roles");
                } catch (javax.xml.transform.TransformerException local) {
                    throw new ProcessingException("TransformerException: " + local, local);
                }
                IncludeXMLConsumer.includeNode(roles, consumer, consumer);

                // include selected role
                String role = (String)context.getAttribute(SunRise.SESSION_CONTEXT_ATTRIBUTE_ADMIN_ROLE);
                if (role != null) {
                    consumer.startElement("", "role", "role", attr);
                    consumer.characters(role.toCharArray(), 0, role.length());
                    consumer.endElement("", "role", "role");
                }
View Full Code Here


        if (name != null) {
            isAuthenticated = false;

            // get the session context
            // if no session context: not authenticated
            SessionContext context = this.getSunRiseSessionContext(false);
            if (context != null) {
                synchronized(context) {

                    try {
                        // is result in cache (= context attribute)
                        if (context.getAttribute("SUNRISE_ISAUTHENTICATED:" + name) != null) {
                            isAuthenticated = true;
                        } else {
                            DocumentFragment id = context.getXML("/" + name + "/authentication/ID");
                            isAuthenticated = (id != null);
                            if (isAuthenticated == true) {
                                // cache result
                                context.setAttribute("SUNRISE_ISAUTHENTICATED:" + name, "YES");
                            }
                        }
                    } catch (ProcessingException local) {
                        // ignore this for now
                        this.getLogger().error("isAuthenticated");
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.getSunRiseSessionContext(true);
                    if (this.getLogger().isDebugEnabled() == true) {
                        this.getLogger().debug("session created");
                    }
                    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("sunrise");
                        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 getSunRiseSessionContext create=" + create);
        }
        SessionContext context = null;

        Session session = this.getSunShineComponent().getSession(create);
        if (session != null) {
            synchronized(session) {
                context = (SessionContext)session.getAttribute(Constants.SESSION_ATTRIBUTE_CONTEXT_NAME);
                if (context == null && create == true) {
                    context = new SimpleSessionContext();
                    context.setup(Constants.SESSION_CONTEXT_NAME, null, null);
                    session.setAttribute(Constants.SESSION_ATTRIBUTE_CONTEXT_NAME, context);
                }
            }
        }
View Full Code Here

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

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

            // cached?
            if (context.getAttribute("SUNRISE_ISAUTHENTICATED:" + logoutHandlerName) != null) {
                context.setAttribute("SUNRISE_ISAUTHENTICATED:" + logoutHandlerName, null);
            }
            // remove context
            context.removeXML(logoutHandlerName);
            ((SessionContextImpl)this.getSunShineComponent().getContext(Constants.SESSION_CONTEXT_NAME)).cleanParametersCache(logoutHandlerName);
            Handler logoutHandler = (Handler)this.getHandler(logoutHandlerName);

            // reset application load status
            logoutHandler.setApplicationsLoaded(context, false);
            Iterator apps = logoutHandler.getApplications().values().iterator();
            ApplicationHandler current;
            while (apps.hasNext() == true) {
                current = (ApplicationHandler)apps.next();
                current.setIsLoaded(context, false);
            }

            final List handlerContexts = logoutHandler.getHandlerContexts();
            final Iterator iter = handlerContexts.iterator();
            while ( iter.hasNext() ) {
                final SessionContext deleteContext = (SessionContext) iter.next();
                this.getSunShineComponent().deleteContext( deleteContext.getName() );
            }
            logoutHandler.clearHandlerContexts();
        }

        if ( mode != null && mode.equalsIgnoreCase("terminateSession") ) {
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.getSunShineComponent().getSession(false);
            synchronized(session) {
View Full Code Here

        // synchronized
        if (this.handler == null) {
            return new SourceParameters();
        }
        if (path == null) {
            SessionContext context = this.getSunRiseSessionContext(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 new HashMap();
        }
        SessionContext context = this.getSunRiseSessionContext(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

        }
        this.mediaType = (this.sunletPars != null ? (String)sunletPars.getParameter(Constants.PARAMETER_MEDIA)
                                                  : (String)request.getAttribute(org.apache.cocoon.sunshine.sunrise.Constants.REQUEST_ATTRIBUTE_MEDIA_TYPE));
        // get the profile

        SessionContext context = sunspot.getContext(false);
        if (context != null) {
            if (context.getAttribute(SunSpot.ATTRIBUTE_PORTAL_ROLE) != null) {
                this.profileID = sunspot.getProfileID(SunSpot.BUILDTYPE_VALUE_ID,
                  (String)context.getAttribute(SunSpot.ATTRIBUTE_PORTAL_ROLE),
                  (String)context.getAttribute(SunSpot.ATTRIBUTE_PORTAL_ID), false);
                this.profile = sunspot.retrieveProfile(this.profileID);
            }
        }
        this.getConfigurationDOM(sunspot);
    }
View Full Code Here

    throws ProcessingException, IOException, SAXException {
        // synchronized
        if (this.getLogger().isDebugEnabled() == true) {
            this.getLogger().debug("BEGIN getContext create="+create);
        }
        SessionContext context = null;

        final Session session = this.getSunShineComponent().getSession(false);
        if (session != null) {
            synchronized(session) {
                String appName = (String)this.request.getAttribute(org.apache.cocoon.sunshine.sunrise.Constants.REQUEST_ATTRIBUTE_APPLICATION_NAME);
View Full Code Here

TOP

Related Classes of org.apache.cocoon.sunshine.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.