Search in sources :

Example 71 with Session

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

the class DefaultSubjectFactory method createSubject.

public Subject createSubject(SubjectContext context) {
    SecurityManager securityManager = context.resolveSecurityManager();
    Session session = context.resolveSession();
    boolean sessionCreationEnabled = context.isSessionCreationEnabled();
    PrincipalCollection principals = context.resolvePrincipals();
    boolean authenticated = context.resolveAuthenticated();
    String host = context.resolveHost();
    return new DelegatingSubject(principals, authenticated, host, session, sessionCreationEnabled, securityManager);
}
Also used : DelegatingSubject(org.apache.shiro.subject.support.DelegatingSubject) PrincipalCollection(org.apache.shiro.subject.PrincipalCollection) Session(org.apache.shiro.session.Session)

Example 72 with Session

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

the class DefaultSubjectContext method resolveAuthenticated.

public boolean resolveAuthenticated() {
    Boolean authc = getTypedValue(AUTHENTICATED, Boolean.class);
    if (authc == null) {
        // see if there is an AuthenticationInfo object.  If so, the very presence of one indicates a successful
        // authentication attempt:
        AuthenticationInfo info = getAuthenticationInfo();
        authc = info != null;
    }
    if (!authc) {
        // fall back to a session check:
        Session session = resolveSession();
        if (session != null) {
            Boolean sessionAuthc = (Boolean) session.getAttribute(AUTHENTICATED_SESSION_KEY);
            authc = sessionAuthc != null && sessionAuthc;
        }
    }
    return authc;
}
Also used : AuthenticationInfo(org.apache.shiro.authc.AuthenticationInfo) Session(org.apache.shiro.session.Session)

Example 73 with Session

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

the class DelegatingSubject method popIdentity.

private PrincipalCollection popIdentity() {
    PrincipalCollection popped = null;
    List<PrincipalCollection> stack = getRunAsPrincipalsStack();
    if (!CollectionUtils.isEmpty(stack)) {
        popped = stack.remove(0);
        Session session;
        if (!CollectionUtils.isEmpty(stack)) {
            // persist the changed stack to the session
            session = getSession();
            session.setAttribute(RUN_AS_PRINCIPALS_SESSION_KEY, stack);
        } else {
            // stack is empty, remove it from the session:
            clearRunAsIdentities();
        }
    }
    return popped;
}
Also used : PrincipalCollection(org.apache.shiro.subject.PrincipalCollection) ProxiedSession(org.apache.shiro.session.ProxiedSession) Session(org.apache.shiro.session.Session)

Example 74 with Session

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

the class AbstractNativeSessionManager method setAttribute.

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

Example 75 with Session

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

the class AbstractNativeSessionManager method setTimeout.

public void setTimeout(SessionKey key, long maxIdleTimeInMillis) throws InvalidSessionException {
    Session s = lookupRequiredSession(key);
    s.setTimeout(maxIdleTimeInMillis);
    onChange(s);
}
Also used : 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