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.
After hours of searching and experimenting I was able to do it like this.
Make a new service say MyUserService that will implement
org.springframework.security.core.userdetails.UserDetailsServiceand has annotation@Service. UserDetailsService only has one methodloadUserByUserName. Implementation of this method will be in MyUserService. It will look like this.@Service
public class MyUserService implements UserDetailsService {
MyUser is also a new class that implements
org.springframework.security.core.userdetails.UserDetailsand all its methods are implemented inside MyUser class. It will look like this.<bean id="customUserDetailsService" class="org.aurora.timeexpense.service.MyUserService"/>Where
org.aurora.timeexpense.service.MyUserServiceis 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.