Search in sources :

Example 31 with Session

use of org.apache.catalina.Session in project tomcat by apache.

the class ManagerBase method getSession.

/**
     * Returns information about the session with the given session id.
     *
     * <p>The session information is organized as a HashMap, mapping
     * session attribute names to the String representation of their values.
     *
     * @param sessionId Session id
     *
     * @return HashMap mapping session attribute names to the String
     * representation of their values, or null if no session with the
     * specified id exists, or if the session does not have any attributes
     */
public HashMap<String, String> getSession(String sessionId) {
    Session s = sessions.get(sessionId);
    if (s == null) {
        if (log.isInfoEnabled()) {
            log.info("Session not found " + sessionId);
        }
        return null;
    }
    Enumeration<String> ee = s.getSession().getAttributeNames();
    if (ee == null || !ee.hasMoreElements()) {
        return null;
    }
    HashMap<String, String> map = new HashMap<>();
    while (ee.hasMoreElements()) {
        String attrName = ee.nextElement();
        map.put(attrName, getSessionAttribute(sessionId, attrName));
    }
    return map;
}
Also used : HashMap(java.util.HashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Session(org.apache.catalina.Session)

Example 32 with Session

use of org.apache.catalina.Session in project tomcat by apache.

the class ManagerBase method getSessionAttribute.

/**
     * For debugging.
     *
     * @param sessionId The ID for the session of interest
     * @param key       The key for the attribute to obtain
     *
     * @return The attribute value for the specified session, if found, null
     *         otherwise
     */
public String getSessionAttribute(String sessionId, String key) {
    Session s = sessions.get(sessionId);
    if (s == null) {
        if (log.isInfoEnabled())
            log.info("Session not found " + sessionId);
        return null;
    }
    Object o = s.getSession().getAttribute(key);
    if (o == null)
        return null;
    return o.toString();
}
Also used : Session(org.apache.catalina.Session)

Example 33 with Session

use of org.apache.catalina.Session in project tomcat by apache.

the class PersistentManagerBase method findSession.

/**
     * {@inheritDoc}
     * <p>
     * This method checks the persistence store if persistence is enabled,
     * otherwise just uses the functionality from ManagerBase.
     */
@Override
public Session findSession(String id) throws IOException {
    Session session = super.findSession(id);
    // safely.
    if (session != null) {
        synchronized (session) {
            session = super.findSession(session.getIdInternal());
            if (session != null) {
                // To keep any external calling code from messing up the
                // concurrency.
                session.access();
                session.endAccess();
            }
        }
    }
    if (session != null)
        return session;
    // See if the Session is in the Store
    session = swapIn(id);
    return session;
}
Also used : Session(org.apache.catalina.Session)

Example 34 with Session

use of org.apache.catalina.Session in project tomcat by apache.

the class StandardManager method stopInternal.

/**
     * Stop this component and implement the requirements
     * of {@link org.apache.catalina.util.LifecycleBase#stopInternal()}.
     *
     * @exception LifecycleException if this component detects a fatal error
     *  that prevents this component from being used
     */
@Override
protected synchronized void stopInternal() throws LifecycleException {
    if (log.isDebugEnabled()) {
        log.debug("Stopping");
    }
    setState(LifecycleState.STOPPING);
    // Write out sessions
    try {
        unload();
    } catch (Throwable t) {
        ExceptionUtils.handleThrowable(t);
        log.error(sm.getString("standardManager.managerUnload"), t);
    }
    // Expire all active sessions
    Session[] sessions = findSessions();
    for (int i = 0; i < sessions.length; i++) {
        Session session = sessions[i];
        try {
            if (session.isValid()) {
                session.expire();
            }
        } catch (Throwable t) {
            ExceptionUtils.handleThrowable(t);
        } finally {
            // Measure against memory leaking if references to the session
            // object are kept in a shared field somewhere
            session.recycle();
        }
    }
    // Require a new random number generator if we are restarted
    super.stopInternal();
}
Also used : Session(org.apache.catalina.Session)

Example 35 with Session

use of org.apache.catalina.Session in project tomcat by apache.

the class Response method isEncodeable.

// ------------------------------------------------------ Protected Methods
/**
     * Return <code>true</code> if the specified URL should be encoded with
     * a session identifier.  This will be true if all of the following
     * conditions are met:
     * <ul>
     * <li>The request we are responding to asked for a valid session
     * <li>The requested session ID was not received via a cookie
     * <li>The specified URL points back to somewhere within the web
     *     application that is responding to this request
     * </ul>
     *
     * @param location Absolute URL to be validated
     * @return <code>true</code> if the URL should be encoded
     */
protected boolean isEncodeable(final String location) {
    if (location == null) {
        return false;
    }
    // Is this an intra-document reference?
    if (location.startsWith("#")) {
        return false;
    }
    // Are we in a valid session that is not using cookies?
    final Request hreq = request;
    final Session session = hreq.getSessionInternal(false);
    if (session == null) {
        return false;
    }
    if (hreq.isRequestedSessionIdFromCookie()) {
        return false;
    }
    // Is URL encoding permitted
    if (!hreq.getServletContext().getEffectiveSessionTrackingModes().contains(SessionTrackingMode.URL)) {
        return false;
    }
    if (SecurityUtil.isPackageProtectionEnabled()) {
        return (AccessController.doPrivileged(new PrivilegedAction<Boolean>() {

            @Override
            public Boolean run() {
                return Boolean.valueOf(doIsEncodeable(hreq, session, location));
            }
        })).booleanValue();
    } else {
        return doIsEncodeable(hreq, session, location);
    }
}
Also used : Session(org.apache.catalina.Session)

Aggregations

Session (org.apache.catalina.Session)58 HttpSession (javax.servlet.http.HttpSession)17 Manager (org.apache.catalina.Manager)16 IOException (java.io.IOException)13 StandardSession (org.apache.catalina.session.StandardSession)8 HttpServletRequest (javax.servlet.http.HttpServletRequest)7 Context (org.apache.catalina.Context)7 StringManager (org.apache.tomcat.util.res.StringManager)7 StandardContext (org.apache.catalina.core.StandardContext)5 Principal (java.security.Principal)3 Container (org.apache.catalina.Container)3 LifecycleException (org.apache.catalina.LifecycleException)3 Realm (org.apache.catalina.Realm)3 File (java.io.File)2 ArrayList (java.util.ArrayList)2 ServletContext (javax.servlet.ServletContext)2 ServletRequest (javax.servlet.ServletRequest)2 Cookie (javax.servlet.http.Cookie)2 HttpServletResponse (javax.servlet.http.HttpServletResponse)2 Loader (org.apache.catalina.Loader)2