Shiro complaining “There is no session with id xxx” with DefaultSecurityManager

前端 未结 3 1809
青春惊慌失措
青春惊慌失措 2021-02-19 22:47

I\'m using Apache Shiro 1.2.0 in a long-running application that reads messages from a queue and and takes action. The action taken requires a Shiro authenticated session, so I

3条回答
  •  说谎
    说谎 (楼主)
    2021-02-19 23:00

    Shiro is validating credentials against SecuritySubject, which is stored in Session. So, it's very likely your session expired after some time of inactivity. You can change expiration time in web.xml or you can use Shiro rememberMe function, but your client have to support cookies. After rememberMe function SecuritySubject will obtain different session and will return false against isAuthenticated, but isRemembered will return true.

    The session will never expired This will produce another problem, when your session will never expire. It will most likely get you out of memory, because your web container is most likely using memory session manager.

    
        -1
    
    

    Shiro rememberMe http://shiro.apache.org/java-authentication-guide.html

    //Example using most common scenario:
    //String username and password.  Acquire in
    //system-specific manner (HTTP request, GUI, etc)
    
    UsernamePasswordToken token =
     new UsernamePasswordToken( username, password );
    
    //”Remember Me” built-in, just do this:
    token.setRememberMe(true);
    

提交回复
热议问题