Creating user details
The previous recipes introduced us to how to store user details using in-memory and providers and filters. This time the correct manner of storing user credentials and roles will be showcased without bothering with the providers and filters.
Getting started
Use the Maven project ch04
again and create another security model imposing the use of org.springframework.security.core.userdetails.UserDetails
and org.springframework.security.core.userdetails.UserDetailsService
.
How to do it...
Instead of hardcoding the user details inside the security model, we will implement a service layer that will programmatically generate a username and password for the application:
- Let us create the
UserService
interface, as follows that will generate hardcoded data for theUserDetails
:
public interface UserService { public String getUserCredentials(String username); public Set<String> getuserRoles(String username); }
- Save this file in our
org.secured.mvc.service
since this is...