Package it.univr.passportease.config
Class AppUserDetailsService
java.lang.Object
it.univr.passportease.config.AppUserDetailsService
- All Implemented Interfaces:
org.springframework.security.core.userdetails.UserDetailsService
@Component
public class AppUserDetailsService
extends Object
implements org.springframework.security.core.userdetails.UserDetailsService
This class is used by spring security to authenticate and authorize users
-
Field Summary
Modifier and TypeFieldDescriptionThe redis template used to check if the user is validatedprivate final UserRepository
The repository of the usersprivate final WorkerRepository
The repository of the workers -
Constructor Summary
ConstructorDescriptionAppUserDetailsService
(UserRepository userRepository, WorkerRepository workerRepository, org.springframework.data.redis.core.RedisTemplate<String, String> redisTemplate) Constructor ofAppUserDetailsService
. -
Method Summary
Modifier and TypeMethodDescriptionprivate void
addAuthorities
(String id, List<org.springframework.security.core.GrantedAuthority> authorities, String role) Add the authorities to the list of authorities of the userorg.springframework.security.core.userdetails.UserDetails
Load the user details of the user identified by the id
-
Field Details
-
userRepository
The repository of the users -
workerRepository
The repository of the workers -
redisTemplate
The redis template used to check if the user is validated
-
-
Constructor Details
-
AppUserDetailsService
@Autowired public AppUserDetailsService(UserRepository userRepository, WorkerRepository workerRepository, org.springframework.data.redis.core.RedisTemplate<String, String> redisTemplate) Constructor ofAppUserDetailsService
. It takes the repository of the users, the repository of the workers and the redis template used to check if the user is validated. It creates aUserDetailsService
object.- Parameters:
userRepository
- The repository of the usersworkerRepository
- The repository of the workersredisTemplate
- The redis template used to check if the user is validated
-
-
Method Details
-
loadUserByUsername
public org.springframework.security.core.userdetails.UserDetails loadUserByUsername(String id) throws org.springframework.security.core.userdetails.UsernameNotFoundException Load the user details of the user identified by the id- Specified by:
loadUserByUsername
in interfaceorg.springframework.security.core.userdetails.UserDetailsService
- Parameters:
id
- the username identifying the user whose data is required. It is the id of the user- Returns:
- the user details of the user identified by the id
- Throws:
org.springframework.security.core.userdetails.UsernameNotFoundException
- if the user is not found
-
addAuthorities
private void addAuthorities(String id, List<org.springframework.security.core.GrantedAuthority> authorities, String role) Add the authorities to the list of authorities of the user- Parameters:
id
- the id of the userauthorities
- the list of authorities of the userrole
- the role of the user, it can be "USER" or "WORKER"
-