简体   繁体   English

Tomcat重新启动后,Apache Shiro isAuthenticated返回true

[英]Apache Shiro isAuthenticated returns true after Tomcat restart

I have a webapp deployed with Tomcat (8.0.32) and the login/logout operations work fine with each redeployment. 我已经在Tomcat(8.0.32)中部署了一个Webapp,并且每次重新部署时登录/注销操作都可以正常工作。 However they do not work so well if I stop Catalina without redeploying the webapp ( ./catalina.sh stop and then ./catalina.sh start without any changes to the contents of the webapp folder). 但是,如果我在不重新部署Webapp的情况下停止Catalina( ./catalina.sh stop然后./catalina.sh start不更改webapp文件夹内容的情况下./catalina.sh start ./catalina.sh stop ,则它们不能很好地工作)。 What happens is that method org.apache.shiro.subject.Subject.isAuthenticated() returns true right after the server starts but before the new login operation takes place . 发生的事情是,方法org.apache.shiro.subject.Subject.isAuthenticated()在服务器启动后但在进行新的登录操作之前立即返回true

More specifically, my implementation of javax.servlet.Filter.doFilter starts with the following line: 更具体地说,我对javax.servlet.Filter.doFilter实现从以下几行开始:

if(org.apache.shiro.SecurityUtils.getSubject().isAuthenticated()) ...

which returns true right after the server restarted but before the new login. 在服务器重新启动之后但在新登录之前,它返回true。 Shiro's version is 1.3.0. Shiro的版本是1.3.0。

Therefore I was wondering if I am missing something, eg is there any operation that must be performed before, or is this the wrong way to use this method? 因此,我想知道我是否缺少某些东西,例如,是否必须在此之前执行任何操作,或者这是使用此方法的错误方法? Thank you for your attention. 感谢您的关注。

I'm not sure how your Shiro configuration looks like but depending on your implementation Shiro by default sets a cookie which still can be valid after your server restarts. 我不确定您的Shiro配置是什么样子,但是根据您的实现,Shiro默认情况下会设置一个cookie,该cookie在服务器重新启动后仍然有效。

Depending on your SessionManager implementation, you can set a globalSessionTimeout and sessionValidationInterval . 根据您的SessionManager实现,您可以设置globalSessionTimeoutsessionValidationInterval The default session timeout is set to 1800000L (30 minutes). 默认会话超时设置为1800000L (30分钟)。 See AbstractSessionManager and DefaultWebSessionManager . 请参见AbstractSessionManagerDefaultWebSessionManager Example implementation: 示例实现:

sessionManager = org.apache.shiro.web.session.mgt.DefaultWebSessionManager
# Session timeout token_ttl_ms = 14 days
sessionManager.globalSessionTimeout = 1209600000
# Session valdiation = 15 minutes
sessionManager.sessionValidationInterval = 900000

If you don't want to use any cookie, you can disable it by setting the following property in your SecurityManager config and skip the session management by the SessionManager completely: 如果您不想使用任何cookie,则可以通过在SecurityManager配置中设置以下属性来禁用它,并完全跳过SessionManager的会话管理:

securityManager.sessionManager.sessionIdCookieEnabled = false 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM