Search in sources :

Example 6 with SubjectContext

use of org.apache.shiro.subject.SubjectContext in project nutzboot by nutzam.

the class ShiroEnvStarter method getWebSecurityManager.

@IocBean(name = "shiroWebSecurityManager")
public WebSecurityManager getWebSecurityManager() {
    DefaultWebSecurityManager webSecurityManager = new DefaultWebSecurityManager() {

        protected SubjectContext resolveSession(SubjectContext context) {
            if (context.resolveSession() != null) {
                return context;
            }
            try {
                Session session = resolveContextSession(context);
                if (session != null) {
                    context.setSession(session);
                }
            } catch (InvalidSessionException e) {
            }
            return context;
        }
    };
    // Shiro Session相关
    if (conf.getBoolean(PROP_SESSION_ENABLE, true)) {
        webSecurityManager.setSessionManager(ioc.get(WebSessionManager.class, "shiroWebSessionManager"));
    }
    List<Realm> realms = new ArrayList<>();
    for (String realmName : ioc.getNamesByType(Realm.class)) {
        realms.add(ioc.get(Realm.class, realmName));
    }
    if (realms.size() > 0)
        webSecurityManager.setRealms(realms);
    webSecurityManager.setRememberMeManager(ioc.get(RememberMeManager.class, "shiroRememberMeManager"));
    return webSecurityManager;
}
Also used : InvalidSessionException(org.apache.shiro.session.InvalidSessionException) RememberMeManager(org.apache.shiro.mgt.RememberMeManager) CookieRememberMeManager(org.apache.shiro.web.mgt.CookieRememberMeManager) SubjectContext(org.apache.shiro.subject.SubjectContext) DefaultWebSecurityManager(org.apache.shiro.web.mgt.DefaultWebSecurityManager) ArrayList(java.util.ArrayList) DefaultWebSessionManager(org.apache.shiro.web.session.mgt.DefaultWebSessionManager) WebSessionManager(org.apache.shiro.web.session.mgt.WebSessionManager) Realm(org.apache.shiro.realm.Realm) Session(org.apache.shiro.session.Session) IocBean(org.nutz.ioc.loader.annotation.IocBean)

Aggregations

SubjectContext (org.apache.shiro.subject.SubjectContext)6 DefaultSubjectContext (org.apache.shiro.subject.support.DefaultSubjectContext)5 PrincipalCollection (org.apache.shiro.subject.PrincipalCollection)2 Subject (org.apache.shiro.subject.Subject)2 ArrayList (java.util.ArrayList)1 AuthenticationException (org.apache.shiro.authc.AuthenticationException)1 AuthenticationToken (org.apache.shiro.authc.AuthenticationToken)1 UsernamePasswordToken (org.apache.shiro.authc.UsernamePasswordToken)1 RememberMeManager (org.apache.shiro.mgt.RememberMeManager)1 Realm (org.apache.shiro.realm.Realm)1 InvalidSessionException (org.apache.shiro.session.InvalidSessionException)1 Session (org.apache.shiro.session.Session)1 SimplePrincipalCollection (org.apache.shiro.subject.SimplePrincipalCollection)1 CookieRememberMeManager (org.apache.shiro.web.mgt.CookieRememberMeManager)1 DefaultWebSecurityManager (org.apache.shiro.web.mgt.DefaultWebSecurityManager)1 DefaultWebSessionManager (org.apache.shiro.web.session.mgt.DefaultWebSessionManager)1 WebSessionManager (org.apache.shiro.web.session.mgt.WebSessionManager)1 Test (org.junit.Test)1 IocBean (org.nutz.ioc.loader.annotation.IocBean)1