我在 Web 应用程序中使用 Apache Shiro。登录和身份验证检查效果很好,但是我在实现注销/重新登录机制时遇到了问题:注销是在 servlet 中完成的:
private void logout(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
log.debug("do logout");
Subject subject = SecurityUtils.getSubject();
subject.logout();
resp.sendRedirect("end.html");
}
但是注销并重新登录后,我收到以下错误:
org.apache.shiro.session.InvalidSessionException: java.lang.IllegalStateException:
getAttribute: Session already invalidated
at org.apache.shiro.web.session.HttpServletSession.removeAttribute(HttpServletSession.java:167)
at org.apache.shiro.session.ProxiedSession.removeAttribute(ProxiedSession.java:135)
at org.apache.shiro.subject.support.DelegatingSubject.clearRunAsIdentities(DelegatingSubject.java:424)
at org.apache.shiro.subject.support.DelegatingSubject.login(DelegatingSubject.java:246)
登录通过以下方式完成(在一个UI组件的方法中,我使用ZK作为UI框架):
private void tryLogin(UsernamePasswordToken token) {
Subject subject = SecurityUtils.getSubject();
try {
subject.login(token);
...
我不明白这个异常,因为从 shiro 注销会使会话无效,并且重新登录应该访问一个新会话。