How to find out if a session with an associated with an entity has expired or not in java siro

I am implementing java shiro for security. I need to return a message when the session has expired, and if the session has not expired, then I need to return another message, for example un Authenticate user.

This is my code.

@GET
@Path("/{userId}")
public Response view(@PathParam("userId")String userId)
{
   ResponseBuilder builder = Response.ok();
   if(SecurityUtils.getSubject().isAuthenticated())
    {

       Registeration registeration=new Registeration();
       boolean status=registeration.getDetails(userId,builder);
       log.debug("the status is:"+status); 


    }
    else
    {
        builder.status(401).entity("You are currently not login .please Login for Access Services");

    }   
    return builder.build();     

}

, . . else. , , , , " ". , , , , . , , 1) , = " " 2) , messsage = " "

+4
1

, SecurityUtils.getSubject().isAuthenticated() , . , , Subject . , ThreadContext.getSubject() SecurityUtils.getSubject(), Subject, . , ThreadContext.getSubject() null, Shiro.

, , "-", Subject.isAuthenticated() true.

, (.. subject.getSession()). , .

SessionListener onExpiration. :

if(SecurityUtils.getSubject().isAuthenticated()) {
    Session session = SecurityUtils.getSubject().getSession(false);
    try {
        session.touch();
    } catch (ExpiredSessionException e) {
        // timeout case.
    }
} else {
    // not login case.
}

session.touch() , lastAccessTime, , .

+2

All Articles