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 7809915
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T03:35:11+00:00 2026-06-02T03:35:11+00:00

I am building an app that has two types of users: regular users (have

  • 0

I am building an app that has two types of users:

  • regular users (have role ‘user’)
  • administrative users (have role ‘admin’, but do not have ‘user’ privileges)

How can I go about allowing someone to login/logout as a user and an administrator separately?

I have two realms defined using two http elements (I have two realms to allow separate login pages and user databases):

<security:http pattern="/admin/**" authentication-manager-ref="adminAuthManager"
    entry-point-ref="adminLoginUrlAuthEntryPoint" use-expressions="true">
    <security:intercept-url pattern="/admin/**" access="hasRole('admin')" />
    <security:access-denied-handler error-page="/admin/login" />
    <security:logout logout-url="/admin/logout" logout-success-url="/" />
    ...
</security:http>
<security:http pattern="/**" authentication-manager-ref="userAuthManager"
    entry-point-ref="userLoginUrlAuthEntryPoint" use-expressions="true">
    <security:intercept-url pattern="/**" access="permitAll" />
    <security:intercept-url pattern="/settings" access="hasRole('user')" />
    <security:access-denied-handler error-page="/login" />
    <security:logout logout-url="/logout" logout-success-url="/" />
    ...
</security:http>

With the current setup, I’m not able to allow a single session to be both an authenticated user and an authenticated administrator. When someone logs in as a user while logged in as an administrator, his/her administrator authentication is lost (or replaced) and vice versa.

I’ve thought about separating the two realms into two different webapps but would prefer not to, if possible.

EDIT: Here’s an example of how I would like this to work:

  1. Person navigates to the site, let’s say at path / which is open to all users
  2. Person clicks on login and authenticates at /login; person now has role “user”
  3. Person decides to navigate to a /admin/* page and is presented with the /admin/login page
  4. Person authenticates using another set of credentials at /admin/login; person now has roles “admin” AND “user”
  5. From the server point of view, when user is on an /admin/** page, the user’s principal is the username he used for /admin/login; when on a /** page, the user’s principal is the username he used for /login
  6. Person finishes admin activities and decides to log out of his admin session at /admin/logout; person loses “admin” role but is left with “user” role
  7. Person finally decides to log out of user role as well and goes to path /logout; person is now anonymous

I’m hoping this can be achieved without writing too much custom functionality.

  • 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-02T03:35:13+00:00Added an answer on June 2, 2026 at 3:35 am

    I don’t understand why you would want the same person to have two sets of credentials? This scenario is typically implemented using step-up authentication i.e. the user is always the same but he is prompted to re-authenticate when trying to access an admin area of the app. For example you may prompt him to enter some additional information or authenticate using a two factor token.

    In the past I have implemented this using a custom AccessDecisionManager/Voter which checks if the user is trying to access a “more secure” area of the site and then throws an InsufficientAuthenticationException if he does not have the correct role. The entry point then handles this exception and prompts the user to re-authenticate and spring assigns the new roles

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

Sidebar

Related Questions

I am building an App that fetches all entries a user has made this
I'm building a Rails app that has Etsy.com style functionality. In other words, it's
I'm building an app that currently has 3 ViewControllers. One of them is used
I am building an iPad app that has a split view controller. Is it
I'm building a new web app that has a requirement to generate an internal
I am building a FB canvas app that has share functionality, my plan is
I've been tasked with building a very simple app that that has a series
The app I'm currently building has the requirement that the app has to prevent
The app we're building has a simple button that starts a facetime session with
I have an application that I'm building that has had concurrency problems in the

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.