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 Details

    • userRepository

      private final UserRepository userRepository
      The repository of the users
    • workerRepository

      private final WorkerRepository workerRepository
      The repository of the workers
    • redisTemplate

      private final org.springframework.data.redis.core.RedisTemplate<String,String> 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 of AppUserDetailsService. 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 a UserDetailsService object.
      Parameters:
      userRepository - The repository of the users
      workerRepository - The repository of the workers
      redisTemplate - 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 interface org.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 user
      authorities - the list of authorities of the user
      role - the role of the user, it can be "USER" or "WORKER"