For some specific scenarios, UserDetails can be customized in order to add some validations and constraints needed to build complete user credentials. In this recipe, we added a simple Comparator to arrange all the authorities alphabetically. There is also a username and password validation to check whether the account is not null. Moreover, all credentials must come from a custom UserDetailsService that injects LoginDao to retrieve all logindetails that match the username. Instead of hardcoding the data in a HashMap, the service will use a query transaction to supply all the needed credential to AppUserDetails. It is recommended to use a separate @Service that will generate the encoded password prior to the logindetails execution.