Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8131017
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T08:56:38+00:00 2026-06-06T08:56:38+00:00

I have implemented form authentication as offered by JAAS. Since I process all my

  • 0

I have implemented form authentication as offered by JAAS. Since I process all my pages as templates code has to be evaluated every time. Thus when the user is directo to /login the doGet request has to handle it and process the login template.

Now I would like to redirect to the main page after the login was successful. When the user chooses /login again he/she should be redirected to the main page.

Thus I need to know during a doGet request whether the user is authorized, maybe also which authentication. How can I check? Or is this idiom wrong?


Or is this done by request.isUserInRole(String role)? Since it does both, authentication AND authorization?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T08:56:39+00:00Added an answer on June 6, 2026 at 8:56 am

    You can check if an user is logged in by checking if HttpServletRequest#getRemoteUser() (the user name) or #getUserPrincipal() (the associated Princpal object) does not return null.

    So, e.g. in doGet() of the /login servlet you could do this:

    if (request.getRemoteUser() != null) {
        // Already logged in, so redirect to some main page.
        response.sendRedirect(request.getContextPath() + "/main");
        return;
    }
    
    // ...
    

    The #isUserInRole() only checks if the logged-in user has some specific role and this is usually only useful to restrict some pages or page sections for specific roles. So unless you’ve a general role which is shared by every user, this isn’t useful.

    You may only want to add a message to inform the enduser why s/he is been redirected and what’s the proper way to login again as another user. E.g. “You are already logged in. If you need to login as another user, please go to logout page first.” or so in the main page which is conditionally displayed based on some redirect parameter.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In our application we have implemented role-based forms authentication. This has been handled using
I have implemented spring-security in my application, my spring-security.xml has following form-login tag. <form-login
Here is what I am trying to do: I have implemented Form Authentication in
Symfony2 and FOS User Bundle issue... I have implemented my own login form in
I have a form with most of its functionality implemented using standard TAction. I
I have a form with 3 text fields and 3 checkboxes. I had implemented
I have implemented correctly bump's api, and added this code: - (void) configureBump {
I have implemented a registration/login/authentication system using this Django guide . But, how would
I have implement Form Authentication <location path=Admin> <system.web> <authorization> <deny users=?/> <allow roles=Admin />
I have a Customer class which has all the account info.(it does NOT extend

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.