Search in sources :

Example 6 with InvalidSessionException

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

the class DefaultSessionManagerTest method testSessionListenerExpiredNotification.

@Test
public void testSessionListenerExpiredNotification() {
    final boolean[] expired = new boolean[1];
    SessionListener listener = new SessionListenerAdapter() {

        public void onExpiration(Session session) {
            expired[0] = true;
        }
    };
    sm.getSessionListeners().add(listener);
    sm.setGlobalSessionTimeout(100);
    Session session = sm.start(null);
    sleep(150);
    try {
        sm.checkValid(new DefaultSessionKey(session.getId()));
        fail("check should have thrown an exception.");
    } catch (InvalidSessionException expected) {
    // do nothing - expected.
    }
    assertTrue(expired[0]);
}
Also used : InvalidSessionException(org.apache.shiro.session.InvalidSessionException) SessionListenerAdapter(org.apache.shiro.session.SessionListenerAdapter) SessionListener(org.apache.shiro.session.SessionListener) Session(org.apache.shiro.session.Session) Test(org.junit.Test)

Example 7 with InvalidSessionException

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

the class HttpServletSession method getAttributeKeys.

public Collection<Object> getAttributeKeys() throws InvalidSessionException {
    try {
        Enumeration namesEnum = httpSession.getAttributeNames();
        Collection<Object> keys = null;
        if (namesEnum != null) {
            keys = new ArrayList<Object>();
            while (namesEnum.hasMoreElements()) {
                keys.add(namesEnum.nextElement());
            }
        }
        return keys;
    } catch (Exception e) {
        throw new InvalidSessionException(e);
    }
}
Also used : InvalidSessionException(org.apache.shiro.session.InvalidSessionException) Enumeration(java.util.Enumeration) InvalidSessionException(org.apache.shiro.session.InvalidSessionException)

Example 8 with InvalidSessionException

use of org.apache.shiro.session.InvalidSessionException 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

InvalidSessionException (org.apache.shiro.session.InvalidSessionException)8 Session (org.apache.shiro.session.Session)4 ArrayList (java.util.ArrayList)1 Enumeration (java.util.Enumeration)1 DELETE (javax.ws.rs.DELETE)1 NewCookie (javax.ws.rs.core.NewCookie)1 RememberMeManager (org.apache.shiro.mgt.RememberMeManager)1 Realm (org.apache.shiro.realm.Realm)1 ExpiredSessionException (org.apache.shiro.session.ExpiredSessionException)1 SessionListener (org.apache.shiro.session.SessionListener)1 SessionListenerAdapter (org.apache.shiro.session.SessionListenerAdapter)1 SubjectContext (org.apache.shiro.subject.SubjectContext)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