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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T20:16:29+00:00 2026-06-14T20:16:29+00:00

I am using spring security and for database based authentication I used following configuration

  • 0

I am using spring security and for database based authentication I used following configuration and its working fine

<authentication-manager alias="authenticationManager">
  <authentication-provider>
     <jdbc-user-service data-source-ref="dataSource"
      users-by-username-query="SELECT ...... U.email_address=?"
      authorities-by-username-query="SELECT ... U.email_address=?">
  </authentication-provider>
</authentication-manager>

now I wanted to add extra info to the session and came across Adding user to session, spring security default login, I tried it and now I have a problem.

XML says I cant use user-service-ref and jdbc-user-service combined. Is there a way to sort it out or else what I have to do if I have to use user-service-ref tag only to authenticate users? What can be the other way to add extra info say a whole Users object to the session.?

Your help will be appreciated.

  • 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-14T20:16:30+00:00Added an answer on June 14, 2026 at 8:16 pm

    After hours of searching and experimenting I was able to do it like this.

    1. Make a new service say MyUserService that will implement org.springframework.security.core.userdetails.UserDetailsService and has annotation @Service. UserDetailsService only has one method loadUserByUserName. Implementation of this method will be in MyUserService. It will look like this.

      @Service
      public class MyUserService implements UserDetailsService {

      @Override
      public UserDetails loadUserByUsername(String arg0)
              throws UsernameNotFoundException {
      
          MyUser user=new MyUser();
          /*get details of user and authorities from database whose username is   
                  arg0 and place them in user instance */
          return user;
      }
      
      }
      
    2. MyUser is also a new class that implements org.springframework.security.core.userdetails.UserDetails and all its methods are implemented inside MyUser class. It will look like this.

      public class MyUser implements UserDetails {
          private static final long serialVersionUID = 1L;
      /*All the variables their getter setters that you wish to store in session. And    
         implementation of all the methods of UserDetails go here.*/
      
       }
      
    3. Define a bean like this
      <bean id="customUserDetailsService" class="org.aurora.timeexpense.service.MyUserService"/>

    Where org.aurora.timeexpense.service.MyUserService is the path of my defined service that implements UserDetailsService.

    4.And Spring Security Configuration will go like this
    <authentication-manager alias="authenticationManager">
    <authentication-provider user-service-ref="customUserDetailsService">
    </authentication-provider>
    </authentication-manager>

    You are good to go.

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

Sidebar

Related Questions

I'm building a restful web-service based on Spring. I'm using Spring Security. It will
I have my spring security set up to do basic authentication to a database
I'm building a webapp with role based access control using Acegi (Spring) security. So
I have configured spring security core plugin using requestmap table inside the database.. Now
I am using Grails multi-tenant plugin with single-tenant mode. I have used spring security
I've been always trying to avoid using Sessions. I've used spring security or other
My application uses Spring Security for handling authentication. So far I was using simple
I am using Spring/Hibernate and Spring-Security for my web-based application. Now I have a
I am trying to implement DAOs to work with Spring Security database authentication in
I am accessing a service based database by using the following connection string static

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.