in Education by
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! JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
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 authorities = new ArrayList(); 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;} }

Related questions

0 votes
    are set to control the pro .. are used to input information in a more user friendly way than tables. fa database ... in a . table Select the correct answer from above options...
asked Nov 28, 2021 in Education by JackTerrance
0 votes
    I’ve done my btech in information Technology. What should I study (diploma or post graduation) to get a job in cyber security field? Select the correct answer from above options...
asked Dec 23, 2021 in Education by JackTerrance
0 votes
    I’ve done my btech in information Technology. How can I get a job in cyber security field? Select the correct answer from above options...
asked Dec 23, 2021 in Education by JackTerrance
0 votes
    I have a GWT application that I am trying to login using spring security. Currently, after a successful ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 7, 2022 in Education by JackTerrance
0 votes
    So I am trying to creating simple Login Page with help of the Spring Boot and Security. So what I ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 17, 2022 in Education by JackTerrance
0 votes
    How Is Spring Security Implemented In a Spring Boot Application?...
asked Nov 15, 2020 in Technology by Editorial Staff
0 votes
    From the options below, which of them is not a threat to information security? (a) Disaster (b) Eavesdropping (c ... Security questions and answers pdf, mcq on Cyber Security pdf,...
asked Nov 5, 2021 in Education by JackTerrance
0 votes
    From the options below, which of them is not a vulnerability to information security? (a) flood (b) without ... Security questions and answers pdf, mcq on Cyber Security pdf,...
asked Nov 5, 2021 in Education by JackTerrance
0 votes
    In Wi-Fi Security, which of the following protocol is more used? WPA WPA2 WPS Both A and C...
asked Mar 6, 2021 in Technology by JackTerrance
0 votes
    ____________ is the information gathering phase in ethical hacking from the target user. (a) Reconnaissance (b) Scanning ... questions and answers pdf, mcq on Cyber Security pdf,...
asked Nov 5, 2021 in Education by JackTerrance
0 votes
    Using which language can a user request information from a database? (a) Query (b) Relational (c) ... Answers, Database Interview Questions and Answers for Freshers and Experience...
asked Oct 11, 2021 in Education by JackTerrance
0 votes
    To build SQL statements it is more secure to user PreparedStatement than Statement. (1)True (2)False...
asked May 15, 2021 in Education by JackTerrance
0 votes
    Windows will automatically generate a domain-wide __________ security certificate for any user who encrypts a file for the first time. Select the correct answer from above options...
asked Dec 29, 2021 in Education by JackTerrance
0 votes
    this is my first question here, i hope you can help me. I've been trying to get a specific path ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 16, 2022 in Education by JackTerrance
0 votes
    this is my first question here, i hope you can help me. I've been trying to get a specific path ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 16, 2022 in Education by JackTerrance
...