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]);
}
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);
}
}
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;
}
Aggregations