2

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?

Sanjay
  • 103
  • 1
  • 2
  • 5

3 Answers3

7

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

Amir Pashazadeh
  • 7,170
  • 3
  • 39
  • 69
1

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

user207421
  • 305,947
  • 44
  • 307
  • 483
0
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.

Rory
  • 1
  • 3