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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T14:32:35+00:00 2026-05-27T14:32:35+00:00

I have implemented Spring Security in my application. I have used default implementation, i.e.,

  • 0

I have implemented Spring Security in my application. I have used default implementation, i.e., I have configured it with my own parameters (DataSource, Secured Areas, etc), but I haven’t write any Custom implementation.

Now I want to capture more data from the user, that is on the same table as username and password, like company name, id, etc. However, I don’t want do use this information in order to login.

I’m not sure how to do it. From what I’ve read, it’s related to UserDetailsService. However, it seems that writing a Custom UserDetailsService would be necessary if I wanted to use this information during the login, and that’s not what I want. I just want to use this information inside the application, after the user have logged in.

Is it really related to UserDetailsServer? Is this the only file I have to modificate?

All the examples I found of custom UserDetailsService just used username and password, so I can’t understand where new data would come in.

Thanks!

  • 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-27T14:32:35+00:00Added an answer on May 27, 2026 at 2:32 pm

    Overriding the UserDetailsService is what we did.. You’ll need to implement your own UserDetailsService and your own UserDetails object:

    public class CustomService implements UserDetailsService {
       @Transactional(readOnly = true)
        public UserDetails loadUserByUsername(String username) {
    
            Account account = accountDAO.findAccountByName(username);
    
            if (account == null) {
                throw new UsernameNotFoundException("account name not found");
            }
            return buildUserFromAccount(account);
        }
    
    
        @SuppressWarnings("unchecked")
        @Transactional(readOnly = true)
        private User buildUserFromAccount(Account account) {
    
            String username = account.getUsername();
            String password = account.getPassword();
            boolean enabled = account.getEnabled();
            boolean accountNonExpired = account.getAccountNonExpired();
            boolean credentialsNonExpired = account.getCredentialsNonExpired();
            boolean accountNonLocked = account.getAccountNonLocked();
    
            // additional information goes here
            String companyName = companyDAO.getCompanyName(account);
    
    
            Collection<GrantedAuthority> authorities = new ArrayList<GrantedAuthority>();
            for (Role role : account.getRoles()) {
                authorities.add(new SimpleGrantedAuthority(role.getName()));
            }
    
            CustomUserDetails user = new CustomUserDetails (username, password, enabled, accountNonExpired, credentialsNonExpired, accountNonLocked,
                    authorities, company);
    
            return user;
        }
    
    
    public class CustomUserDetails extends User{
    
        // ...
        public CustomUserDetails(..., String company){
             super(...);
             this.company = company;
        }
    
        private String company;
    
        public String getCompany() { return company;}
    
        public void setCompany(String company) { this.company = company;}
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following situation: my application's authorization mechanism is implemented using Spring security.
I have a web application that uses spring security. It uses <intercept-url ../> elements
I have implemented spring security's remember me feature in our app, the way i
hi I have a j2ee application using Spring webflow and Spring Security. I want
I'm working on Spring based application with Spring Security. I have users with different
I have integrated Spring Security in my application , and would like to display
I have implemented spring security in controller method. Below is my spring security.xml -->
I have a grails app configured with spring-security-core and I need to allow Facebook
I have a j2ee web application running on Spring framework. I want to implement
I have implemented a SAX parser in Java by extending the default handler. 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.