Search in sources :

Example 21 with Session

use of org.apache.shiro.session.Session in project shiro by apache.

the class AbstractNativeSessionManager method start.

public Session start(SessionContext context) {
    Session session = createSession(context);
    applyGlobalSessionTimeout(session);
    onStart(session, context);
    notifyStart(session);
    // Don't expose the EIS-tier Session object to the client-tier:
    return createExposedSession(session, context);
}
Also used : Session(org.apache.shiro.session.Session)

Example 22 with Session

use of org.apache.shiro.session.Session in project shiro by apache.

the class AbstractNativeSessionManager method removeAttribute.

public Object removeAttribute(SessionKey sessionKey, Object attributeKey) throws InvalidSessionException {
    Session s = lookupRequiredSession(sessionKey);
    Object removed = s.removeAttribute(attributeKey);
    if (removed != null) {
        onChange(s);
    }
    return removed;
}
Also used : Session(org.apache.shiro.session.Session)

Example 23 with Session

use of org.apache.shiro.session.Session in project shiro by apache.

the class AbstractValidatingSessionManager method doGetSession.

@Override
protected final Session doGetSession(final SessionKey key) throws InvalidSessionException {
    enableSessionValidationIfNecessary();
    log.trace("Attempting to retrieve session with key {}", key);
    Session s = retrieveSession(key);
    if (s != null) {
        validate(s, key);
    }
    return s;
}
Also used : Session(org.apache.shiro.session.Session)

Example 24 with Session

use of org.apache.shiro.session.Session in project shiro by apache.

the class AbstractValidatingSessionManager method validateSessions.

/**
 * @see ValidatingSessionManager#validateSessions()
 */
public void validateSessions() {
    if (log.isInfoEnabled()) {
        log.info("Validating all active sessions...");
    }
    int invalidCount = 0;
    Collection<Session> activeSessions = getActiveSessions();
    if (activeSessions != null && !activeSessions.isEmpty()) {
        for (Session s : activeSessions) {
            try {
                // simulate a lookup key to satisfy the method signature.
                // this could probably stand to be cleaned up in future versions:
                SessionKey key = new DefaultSessionKey(s.getId());
                validate(s, key);
            } catch (InvalidSessionException e) {
                if (log.isDebugEnabled()) {
                    boolean expired = (e instanceof ExpiredSessionException);
                    String msg = "Invalidated session with id [" + s.getId() + "]" + (expired ? " (expired)" : " (stopped)");
                    log.debug(msg);
                }
                invalidCount++;
            }
        }
    }
    if (log.isInfoEnabled()) {
        String msg = "Finished session validation.";
        if (invalidCount > 0) {
            msg += "  [" + invalidCount + "] sessions were stopped.";
        } else {
            msg += "  No sessions were stopped.";
        }
        log.info(msg);
    }
}
Also used : InvalidSessionException(org.apache.shiro.session.InvalidSessionException) ExpiredSessionException(org.apache.shiro.session.ExpiredSessionException) Session(org.apache.shiro.session.Session)

Example 25 with Session

use of org.apache.shiro.session.Session in project shiro by apache.

the class DefaultSessionManager method retrieveSession.

protected Session retrieveSession(SessionKey sessionKey) throws UnknownSessionException {
    Serializable sessionId = getSessionId(sessionKey);
    if (sessionId == null) {
        log.debug("Unable to resolve session ID from SessionKey [{}].  Returning null to indicate a " + "session could not be found.", sessionKey);
        return null;
    }
    Session s = retrieveSessionFromDataSource(sessionId);
    if (s == null) {
        // session ID was provided, meaning one is expected to be found, but we couldn't find one:
        String msg = "Could not find session with ID [" + sessionId + "]";
        throw new UnknownSessionException(msg);
    }
    return s;
}
Also used : Serializable(java.io.Serializable) UnknownSessionException(org.apache.shiro.session.UnknownSessionException) Session(org.apache.shiro.session.Session)

Aggregations

Session (org.apache.shiro.session.Session)93 Subject (org.apache.shiro.subject.Subject)34 Test (org.junit.Test)21 Serializable (java.io.Serializable)11 PrincipalCollection (org.apache.shiro.subject.PrincipalCollection)8 UsernamePasswordToken (org.apache.shiro.authc.UsernamePasswordToken)6 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)6 SecurityManager (org.apache.shiro.mgt.SecurityManager)5 SessionListener (org.apache.shiro.session.SessionListener)5 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)5 User (com.hfut.entity.User)4 Subject (ddf.security.Subject)4 ApiOperation (io.swagger.annotations.ApiOperation)4 Date (java.util.Date)4 HttpServletRequest (javax.servlet.http.HttpServletRequest)4 AuthenticationException (org.apache.shiro.authc.AuthenticationException)4 InvalidSessionException (org.apache.shiro.session.InvalidSessionException)4 SessionListenerAdapter (org.apache.shiro.session.SessionListenerAdapter)4 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3