I have a custom AuthenticationProvider that simply returns the Authentication object for the authenticate method. What I want to do is add a role to the user when they log in. This is for demo purposes, so all I want is the user to enter a username and let them in. I need to assign them the admin role.
I have a custom AuthenticationProvider that simply returns the Authentication object for the authenticate
Share
There are, of course, several ways to achieve that.
My preferred one is do this in a custom
UserDetailsService. The only method isloadUserByUsername, that will return an instance ofUserDetails. When you are constructing yourUserDetails, you can add whateverGrantedAuthorityyou want.So first, you’ll declare your custom
UserDetailsServicein your application context configuration file:Then you write the class itself: