How to check if a user is logged in when using auth-method FORM

3.7k Views Asked by At

I am using auth-method FORM with apache tomcat to authenticate users. I am using the default j_security_check action.

If a user has signed in, I must display a Sign out link. Else a sign in link. How do I check if the user has signed in?

Also, how do I log a user out?

3

There are 3 best solutions below

0
On BEST ANSWER

You can use HttpServletRequest.getUserPrincipal() and check it to find the logged in user.

1
On

The state of being logged in is identical to the condition that HttpServletRequest.getUserPrincipal() returns non-null.

0
On
if(request.authenticate(response)){
    System.out.println("The User is Authenticated");
}else{
   System.out.println("The User is not Authenticated");
}

Use this code inside your JSP or in the Servlets.