昨天看到一个问题,在手动logout的时候,总是报错 There is no session with id [XXX]
今天修复了,但是暂时还不知道原因。
总结一下:
shiro 尝试释放当前session
try {
Subject currentUser = SecurityUtils.getSubject();
currentUser.logout();
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
shiro尝试释放其他 session ID
public void userLogout(String sessionId){
SecurityManager securityManager = SecurityUtils.getSecurityManager();
Subject.Builder builder = new Subject.Builder(securityManager);
builder.sessionId(sessionId);
Subject subject = builder.buildSubject();
if (null != subject) {
try {
subject.logout();
} catch (SessionException e) {
// TODO: handle exception
LogUtils.logError("OAClientService;userLogout;", e);
}
}
}
碰到错误的是,是尝试用 第二种方案去释放当前session