码迷,mamicode.com
首页 > 其他好文 > 详细

Shiro SessionManager会话管理器

时间:2018-06-05 14:05:42      阅读:178      评论:0      收藏:0      [点我收藏+]

标签:ring   ted   lse   wan   cep   tee   subject   run   with   

SessionManager所有的行为

public interface SessionManager {

    // 开启一个新的会话
    Session start(SessionContext context);

    // 获得会话
    Session getSession(SessionKey key) throws SessionException;
}

登录

Subject currentUser = SecurityUtils.getSubject();
UsernamePasswordToken token = new UsernamePasswordToken("username", "password");
currentUser.login(token);            

DelegatingSubject的login

public void login(AuthenticationToken token) throws AuthenticationException {
    clearRunAsIdentitiesInternal();
    // 认证登录
    Subject subject = securityManager.login(this, token);

    PrincipalCollection principals;

    String host = null;

    if (subject instanceof DelegatingSubject) {
        DelegatingSubject delegating = (DelegatingSubject) subject;
        //we have to do this in case there are assumed identities - we don‘t want to lose the ‘real‘ principals:
        principals = delegating.principals;
        host = delegating.host;
    } else {
        principals = subject.getPrincipals();
    }

    if (principals == null || principals.isEmpty()) {
        String msg = "Principals returned from securityManager.login( token ) returned a null or " +
                "empty value.  This value must be non null and populated with one or more elements.";
        throw new IllegalStateException(msg);
    }
    this.principals = principals;
    this.authenticated = true;
    if (token instanceof HostAuthenticationToken) {
        host = ((HostAuthenticationToken) token).getHost();
    }
    if (host != null) {
        this.host = host;
    }
    // 认证登录成功后试图获得会话,没有的话就创建一个新的会话
    Session session = subject.getSession(false);
    if (session != null) {
        this.session = decorate(session);
    } else {
        this.session = null;
    }
}

 

Shiro SessionManager会话管理器

标签:ring   ted   lse   wan   cep   tee   subject   run   with   

原文地址:https://www.cnblogs.com/BINGJJFLY/p/9139348.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!