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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T06:00:52+00:00 2026-05-26T06:00:52+00:00

I have set up spring security to intercept correctly and prompt user with custom

  • 0

I have set up spring security to intercept correctly and prompt user with custom login page, that then authenticates correctly and adds userdetails to SecurityContextHolder.

Supplementary to that I now want to add my own custom User object added to session whenever login is performed; so the code will look like this:

public returnwhat? doMySupplementaryLogin() {

   UserDetails principal = (UserDetails) SecurityContextHolder.getContext()
                                .getAuthentication().getPrincipal();
   MyUser user = myUserService.getMyUser(principal.getUsername());

   add user to what ?
}

Where will this code go? I want the nomral spring authentication to be performed and then the above code will put a MyUser object into session and then send user to the original intercepted url/viewname. I have the strong feeling I am making things more complicated than they need to be …

  • 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-05-26T06:00:52+00:00Added an answer on May 26, 2026 at 6:00 am

    You do make it complicated… 🙂

    What you want is to add a custom authentication provider to spring’s normal authentication manager.
    So you would configure the authentication manager like this:

        <security:authentication-manager alias="authenticationManager">
          <security:authentication-provider user-service-ref="authServiceImpl">
            <security:password-encoder ref="passwordEncoder"/>
          </security:authentication-provider>
        </security:authentication-manager>
        <bean id="passwordEncoder" class="org.springframework.security.authentication.encoding.Md5PasswordEncoder"/>
    

    Now you only need to define the authServiceImpl bean inside your spring context. You can either do this through xml or annotations (my prefered way).

    @Service
    public class AuthServiceImpl implements AuthService {
    

    You need to implement the AuthService interface. Just implement to methods from the interface – should be pretty straight forward.
    You don’t need to put things into the SecurityContextHolder yourself – spring will do that.

    What you want is this:

    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException, DataAccessException {
         return MyUser user = myUserService.getMyUser(username);
    }
    

    Feel free to ask if you have any further questions.

    EDIT:
    Or you could just have your UserService class implement the interface – I just did it like this because you didn’t provide your UserService class.

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

Sidebar

Related Questions

Currently I have a custom form login page in Spring Security 3 that sends
I have a web application that uses spring security. It uses <intercept-url ../> elements
I am using spring security and have an admin jsp page for editing user
I currently have a web application that is utilizing Spring Security hosted on a
I have my spring security set up to do basic authentication to a database
I am using BlazeDS and Spring Security and have set up my application using
I have 2 spring web apps that provide 2 separate set of services. Web
I am working on a legacy app that uses Spring Security 2.0.4. I have
I have a problem with my j2ee application using spring security. I set max-sessions
I have multiple projects that need to pass user login information to common-api project

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.