Package org.apache.cocoon.environment

Examples of org.apache.cocoon.environment.Session


                                            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 ) {
                AuthenticationManager authManager = null;
                try {
                    authManager = (AuthenticationManager)manager.lookup(AuthenticationManager.ROLE);
                    final String handlerName = authManager.getHandlerName();
                    final String appName     = authManager.getApplicationName();
                    if ( null != handlerName ) {
                        context = new SessionContextImpl((SessionContext)session.getAttribute(AuthenticationConstants.SESSION_ATTRIBUTE_CONTEXT_NAME),
                                                         name, handlerName, appName, resolver, manager);
                    }
                } catch (ComponentException ce) {
                    throw new ProcessingException("Unabled to lookup authentication manager.", ce);
                } finally {
View Full Code Here


        }

        // get some important information
        Request request = ObjectModelHelper.getRequest(this.objectModel);
        Response response = ObjectModelHelper.getResponse(this.objectModel);
        Session session = request.getSession();
       
        boolean isAdmin = (src == null || src.equals("admin"));

        // now start producing xml:
        AttributesImpl attr = new AttributesImpl();
        consumer.startElement("", "configuration", "configuration", attr);

        // set the conf uri:
        // This is a bug in the servlet 2.2 API!!!
        // It does not contain the context:  String uri = HttpUtils.getRequestURL(this.request).toString();
        // So: ABSOLUTELY USELESS
        String uri = response.encodeURL(request.getRequestURI());
        consumer.startElement("", "uri", "uri", attr);
        consumer.characters(uri.toCharArray(), 0, uri.length());
        consumer.endElement("", "uri", "uri");

        if (isAdmin == true) {
            // build the menue
            consumer.startElement("", "menue", "menue", attr);

            if (handler.getNewRoleResource() != null) {
                consumer.startElement("", "addrole", "addrole", attr);
                consumer.endElement("", "addrole", "addrole");
            }
            if (handler.getDeleteRoleResource() != null) {
                consumer.startElement("", "delrole", "delrole", attr);
                consumer.endElement("", "delrole", "delrole");
            }

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


        synchronized (session) {

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

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

            if (state.equals("delrole") == true) {
                try {
                    String role = request.getParameter(REQ_PARAMETER_ROLE);
                    if (role != null) {
                        // first delete user
                        Document userDF = this.getUsers(role, null, handler);
                        NodeList users   = null;
                        if (userDF != null) users = DOMUtil.selectNodeList(userDF, "users/user");
                        if (users != null) {
                            for(int i = 0; i < users.getLength(); i++) {
                                this.deleteUser(role, DOMUtil.getValueOf(users.item(i), "ID"), null, handler);
                            }
                        }
                        this.deleteRole(role, null, handler);
                    }
                    session.removeAttribute(SESSION_CONTEXT_ATTRIBUTE_ADMIN_ROLE);
                } 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 = authManager.createParameters(null);
                    id = pars.getParameter("ID", null);
                    role = pars.getParameter("role", null);
                    user = "old";
                } else {
                    role = request.getParameter(REQ_PARAMETER_ROLE);
                    id   = request.getParameter(REQ_PARAMETER_ID);
                    user = request.getParameter(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 = request.getParameterNames();
                        String current;
                        while (requestParameters.hasMoreElements() == true) {
                            current = (String)requestParameters.nextElement();
                            pars.setParameter(current, request.getParameter(current));
                        }
                        addingNewUserFailed = !this.addUser(role, id, pars, handler);
                        if (addingNewUserFailed == false) {
                            consumer.startElement("", "addeduser", "addeduser", attr);
                            consumer.characters(id.toCharArray(), 0, id.length());
                            consumer.endElement("", "addeduser", "addeduser");
                        }
                    } else {
                        String delete = request.getParameter("authdeluser");
                        if (delete != null && delete.equals("true") == true) {
                            this.deleteUser(role, id, null, handler);
                        } else {
                            SourceParameters pars = new SourceParameters();
                            // first include all request parameters
                            Enumeration requestParameters = request.getParameterNames();
                            String current;
                            while (requestParameters.hasMoreElements() == true) {
                                current = (String)requestParameters.nextElement();
                                pars.setParameter(current, request.getParameter(current));
                            }
                            this.changeUser(role, id, pars, handler);
                        }
                    }
                    session.removeAttribute(SESSION_CONTEXT_ATTRIBUTE_ADMIN_ROLE);
                }
                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 = authManager.createParameters(null);
                    id = pars.getParameter("ID", null);
                    role = pars.getParameter("role", null);
                } else {
                    role = request.getParameter(REQ_PARAMETER_ROLE);
                    id   = request.getParameter(REQ_PARAMETER_ID);
                }
                if (role != null && id != null) {
                    session.setAttribute(SESSION_CONTEXT_ATTRIBUTE_ADMIN_ROLE, role);

                    // include users
                    Document userDF = this.getUsers(role, id, handler);
                    Element  users   = null;
                    try {
                        if (userDF != null) users = (Element)DOMUtil.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 = authManager.createParameters(null);
                    id = pars.getParameter("ID", null);
                    role = pars.getParameter("role", null);
                } else {
                    role = request.getParameter(REQ_PARAMETER_ROLE);
                    id   = request.getParameter(REQ_PARAMETER_ID);
                }
                if (role != null && id != null) {
                    session.setAttribute(SESSION_CONTEXT_ATTRIBUTE_ADMIN_ROLE, role);

                    // include users
                    Document userDF = this.getUsers(role, id, handler);
                    Element  users   = null;
                    try {
                        if (userDF != null) users = (Element)DOMUtil.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 = request.getParameter(REQ_PARAMETER_ROLE);
                session.setAttribute(SESSION_CONTEXT_ATTRIBUTE_ADMIN_ROLE, role);
                // include users
                Document userDF = this.getUsers(role, null, handler);
                Node     users   = null;
                try {
                    if (userDF != null) users = DOMUtil.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
                Document rolesDF = this.getRoles(handler);
                Node     roles   = null;
                try {
                    if (rolesDF != null) roles = DOMUtil.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)session.getAttribute(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

     */
    protected void debug(Environment environment, boolean internal) {
        String lineSeparator = System.getProperty("line.separator");
        Map objectModel = environment.getObjectModel();
        Request request = ObjectModelHelper.getRequest(objectModel);
        Session session = request.getSession(false);
        StringBuffer msg = new StringBuffer();
        msg.append("DEBUGGING INFORMATION:").append(lineSeparator);
        if (internal) {
            msg.append("INTERNAL ");
        }
        msg.append("REQUEST: ").append(request.getRequestURI()).append(lineSeparator).append(lineSeparator);
        msg.append("CONTEXT PATH: ").append(request.getContextPath()).append(lineSeparator);
        msg.append("SERVLET PATH: ").append(request.getServletPath()).append(lineSeparator);
        msg.append("PATH INFO: ").append(request.getPathInfo()).append(lineSeparator).append(lineSeparator);

        msg.append("REMOTE HOST: ").append(request.getRemoteHost()).append(lineSeparator);
        msg.append("REMOTE ADDRESS: ").append(request.getRemoteAddr()).append(lineSeparator);
        msg.append("REMOTE USER: ").append(request.getRemoteUser()).append(lineSeparator);
        msg.append("REQUEST SESSION ID: ").append(request.getRequestedSessionId()).append(lineSeparator);
        msg.append("REQUEST PREFERRED LOCALE: ").append(request.getLocale().toString()).append(lineSeparator);
        msg.append("SERVER HOST: ").append(request.getServerName()).append(lineSeparator);
        msg.append("SERVER PORT: ").append(request.getServerPort()).append(lineSeparator).append(lineSeparator);

        msg.append("METHOD: ").append(request.getMethod()).append(lineSeparator);
        msg.append("CONTENT LENGTH: ").append(request.getContentLength()).append(lineSeparator);
        msg.append("PROTOCOL: ").append(request.getProtocol()).append(lineSeparator);
        msg.append("SCHEME: ").append(request.getScheme()).append(lineSeparator);
        msg.append("AUTH TYPE: ").append(request.getAuthType()).append(lineSeparator).append(lineSeparator);
        msg.append("CURRENT ACTIVE REQUESTS: ").append(activeRequestCount).append(lineSeparator);

        // log all of the request parameters
        Enumeration e = request.getParameterNames();

        msg.append("REQUEST PARAMETERS:").append(lineSeparator).append(lineSeparator);

        while (e.hasMoreElements()) {
            String p = (String) e.nextElement();

            msg.append("PARAM: '").append(p).append("' ")
               .append("VALUES: '");
            String[] params = request.getParameterValues(p);
            for (int i = 0; i < params.length; i++) {
                msg.append("[" + params[i] + "]");
                if (i != (params.length - 1)) {
                    msg.append(", ");
                }
            }

            msg.append("'").append(lineSeparator);
        }

        // log all of the header parameters
        Enumeration e2 = request.getHeaderNames();

        msg.append("HEADER PARAMETERS:").append(lineSeparator).append(lineSeparator);

        while (e2.hasMoreElements()) {
            String p = (String) e2.nextElement();

            msg.append("PARAM: '").append(p).append("' ")
               .append("VALUES: '");
            Enumeration e3 = request.getHeaders(p);
            while (e3.hasMoreElements()) {
                msg.append("[" + e3.nextElement() + "]");
                if (e3.hasMoreElements()) {
                    msg.append(", ");
                }
            }

            msg.append("'").append(lineSeparator);
        }

        msg.append(lineSeparator).append("SESSION ATTRIBUTES:").append(lineSeparator).append(lineSeparator);

        // log all of the session attributes
        if (session != null) {
            // Fix bug #12139: Session can be modified while still
            // being enumerated here
            synchronized (session) {
                e = session.getAttributeNames();
                while (e.hasMoreElements()) {
                    String p = (String) e.nextElement();
                    msg.append("PARAM: '").append(p).append("' ")
                       .append("VALUE: '").append(session.getAttribute(p)).append("'")
                       .append(lineSeparator);
                }
            }
        }

View Full Code Here

*
*/
protected HttpClient getHttpClient()
{
  Request request = ObjectModelHelper.getRequest( objectModel );
  Session session = request.getSession( true );
  HttpClient httpClient = null;
  if (session != null)
  {
    httpClient = (HttpClient) session.getAttribute( HTTP_CLIENT );
  }
  if (httpClient == null)
  {
    httpClient = new HttpClient();
   
    if (System.getProperty("http.proxyHost") != null)
    {
      String proxyHost = System.getProperty("http.proxyHost");
      int proxyPort = Integer.parseInt(System.getProperty("http.proxyPort"));
      HostConfiguration config = httpClient.getHostConfiguration();
      if (config == null) {
        config = new HostConfiguration();
      }
      config.setProxy(proxyHost, proxyPort);
      httpClient.setHostConfiguration(config);
    }
   
    session.setAttribute( HTTP_CLIENT, httpClient );
  }
  return httpClient;
}
View Full Code Here

        if (this._useSessionInfo) {
            Request request = ObjectModelHelper.getRequest(objectModel);
            if (map == null) map = new HashMap(5);

            Session session = request.getSession(false);
            if (session != null) {
                map.put("session-available","true");
                map.put("session-is-new",session.isNew()?"true":"false");
                map.put("session-id-from-cookie",request.isRequestedSessionIdFromCookie()?"true":"false");
                map.put("session-id-from-url",request.isRequestedSessionIdFromURL()?"true":"false");
                map.put("session-valid",request.isRequestedSessionIdValid()?"true":"false");
                map.put("session-id",session.getId());
            } else {
                map.put("session-available","false");
            }
        }
View Full Code Here

    public Map act (Redirector redirector, SourceResolver resolver, Map objectModel, String src,
            Parameters parameters) throws Exception {
        Request req = ObjectModelHelper.getRequest(objectModel);

        /* check session validity */
        Session session = req.getSession (false);
        if (session == null) {
            if (this.getLogger().isDebugEnabled()) {
                getLogger ().debug ("No session object");
            }
            return null;
        }

        // read global parameter settings
        boolean reloadable = Constants.DESCRIPTOR_RELOADABLE_DEFAULT;
        if (this.settings.containsKey("reloadable")) {
            reloadable = Boolean.valueOf((String) this.settings.get("reloadable")).booleanValue();
        }

        try {
            Configuration conf = this.getConfiguration (
                    parameters.getParameter ("descriptor", (String) this.settings.get("descriptor")), resolver,
            parameters.getParameterAsBoolean("reloadable",reloadable));

            String valsetstr = parameters.getParameter ( "validate-set", (String) settings.get("validate-set") );
            String valstr = parameters.getParameter ( "validate", (String) settings.get("validate") );

            Configuration[] desc = conf.getChildren ("parameter");
            Configuration[] csets = conf.getChildren ("constraint-set");
            HashMap actionMap = new HashMap ();
            /*
             * old obsoleted method
             */
            if (valstr != null && !"".equals (valstr.trim ())) {
                if (this.getLogger().isDebugEnabled()) {
                    getLogger ().debug ("Validating parameters "
                        + "as specified via 'validate' parameter");
                }
                /* get list of params to be validated */
                String[] rparams = Tokenizer.tokenize (valstr, ",", false);

                /* perform actuall validation */
                ValidatorActionHelper result = null;
                String name = null;
                HashMap params = new HashMap (rparams.length);
                /* put required params into hash */
                for (int i = 0; i < rparams.length; i ++) {
                    name = rparams[i];
                    if (name == null || "".equals (name.trim ())) {
                        if (this.getLogger().isDebugEnabled()) {
                            getLogger ().debug ("Wrong syntax of the 'validate' parameter");
                        }
                        return null;
                    }
                    name = name.trim ();
                    params.put (name, session.getAttribute (name));
                }
                for (int i = 0; i < rparams.length; i ++) {
                    name = rparams[i].trim ();
                    result = validateParameter (name, null, desc,
                            params, false);
                    if (!result.isOK()) {
                        if (this.getLogger().isDebugEnabled()) {
                            getLogger().debug ("Validation failed for parameter " + name);
                        }
                        return null;
                    }
                    session.setAttribute (name, result.getObject());
                    actionMap.put (name, result.getObject());
                }
            }
            /*
             * new set-based method
             */
            if (valsetstr != null && !"".equals (valsetstr.trim ())) {
                if (this.getLogger().isDebugEnabled()) {
                    getLogger ().debug ("Validating parameters "
                        + "from given constraint-set " + valsetstr);
                }
                Configuration cset = null;
                String setname = null;
                int j = 0;
                boolean found = false;
                for (j = 0; j < csets.length; j ++) {
                    setname = csets[j].getAttribute ("name", "");
                    if (valsetstr.trim().equals (setname.trim ())) {
                        found = true;
                        break;
                    }
                }
                if (!found) {
                    if (this.getLogger().isDebugEnabled()) {
                        getLogger ().debug ("Given set "
                            + valsetstr
                            + " does not exist in a description file");
                    }
                    return null;
                }
                cset = csets[j];
                /* get the list of params to be validated */
                Configuration[] set = cset.getChildren ("validate");

                /* perform actuall validation */
                ValidatorActionHelper result = null;
                String name = null;
                HashMap params = new HashMap (set.length);
                if (this.getLogger().isDebugEnabled()) {
                    getLogger ().debug ("Given set "
                        + valsetstr
                        + " contains " + set.length + " rules");
                }
                /* put required params into hash */
                for (int i = 0; i < set.length; i ++) {
                    name = set[i].getAttribute ("name", "");
                    if ("".equals (name.trim ())) {
                        if (this.getLogger().isDebugEnabled()) {
                            getLogger ().debug ("Wrong syntax "
                                + " of 'validate' children nr. " + i);
                        }
                        return null;
                    }
                    name = name.trim ();
                    params.put (name, session.getAttribute (name));
                }
                for (int i = 0; i < set.length; i ++) {
                    name = set[i].getAttribute ("name", null);
                    result = validateParameter(name, set[i],
                            desc, params, false);
                    if (!result.isOK()) {
                        if (this.getLogger().isDebugEnabled()) {
                            getLogger().debug("Validation failed for parameter " + name);
                        }
                        return null;
                    }
                    session.setAttribute (name, result.getObject());
                    actionMap.put (name, result.getObject());
                }
            }
            if (this.getLogger().isDebugEnabled()) {
                getLogger().debug("All session params validated");
View Full Code Here

     */
    public Scriptable getSessionScope(Environment environment)
    {
        Map objectModel = environment.getObjectModel();
        Request request = ObjectModelHelper.getRequest(objectModel);
        Session session = request.getSession(false);

        if (session == null) {
            return null;
        }
        Scriptable scope;
        HashMap userScopes = (HashMap)session.getAttribute(USER_GLOBAL_SCOPE);

        if (userScopes == null) {
            return null;
        }
        String uriPrefix = environment.getURIPrefix();
View Full Code Here

     */
    public void setSessionScope(Environment environment, Scriptable scope)
    {
        Map objectModel = environment.getObjectModel();
        Request request = ObjectModelHelper.getRequest(objectModel);
        Session session = request.getSession(true);

        HashMap userScopes = (HashMap)session.getAttribute(USER_GLOBAL_SCOPE);
        if (userScopes == null) {
            userScopes = new HashMap();
            session.setAttribute(USER_GLOBAL_SCOPE, userScopes);
        }
       
        String uriPrefix = environment.getURIPrefix();
        userScopes.put(uriPrefix, scope);
    }
View Full Code Here

    public void removeSessionScope(Environment environment)
    {
        Map objectModel = environment.getObjectModel();
        Request request = ObjectModelHelper.getRequest(objectModel);
        Session session = request.getSession(true);

        HashMap userScopes = (HashMap)session.getAttribute(USER_GLOBAL_SCOPE);
        if (userScopes == null)
            return;

        userScopes.remove(environment.getURIPrefix());
    }
View Full Code Here

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

                PortalManager portal = null;
                try {
                    portal = (PortalManager)manager.lookup(PortalManager.ROLE);
View Full Code Here

TOP

Related Classes of org.apache.cocoon.environment.Session

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.