Class AuthInfoDetailsService

java.lang.Object
hu.rts.mike.example.dev.crm.service.AuthInfoDetailsService
All Implemented Interfaces:
org.springframework.security.core.userdetails.UserDetailsService

@Service("userDetailsService") public class AuthInfoDetailsService extends Object implements org.springframework.security.core.userdetails.UserDetailsService
  • Field Details

  • Constructor Details

    • AuthInfoDetailsService

      public AuthInfoDetailsService(AuthInfoRepository authInfoRepository, TokenCache tokenCache, jakarta.servlet.http.HttpServletRequest httpServletRequest)
  • Method Details

    • getPrivileges

      private Set<String> getPrivileges(Collection<Role> roles)
      Gets privileges of given roles. The privilege names are prefixed with "ROLE_" because the view-level @RolesAllowed annotation automatically extends the given role names with the same prefix and @PrivilegesAllowed annotation does not exist.
      Parameters:
      roles - The roles to be analysed.
      Returns:
      Set of privilege names.
    • getGrantedAuthorities

      private Set<org.springframework.security.core.GrantedAuthority> getGrantedAuthorities(Set<String> privileges)
      Converts privileges to GrantedAuthorities.
      Parameters:
      privileges - The privileges to be converted.
      Returns:
      Set of SimpleGrantedAuthorities.
    • getAuthorities

      private Set<? extends org.springframework.security.core.GrantedAuthority> getAuthorities(Collection<Role> roles)
      Returns user privileges as Set of SimpleGrantedAuthorities. Used in case of session-based authentication.
      Parameters:
      roles - The roles to be converted.
      Returns:
      Set of privileges as SimpleGrantedAuthority instances.
    • getAuthorities

      private Set<? extends org.springframework.security.core.GrantedAuthority> getAuthorities(org.springframework.security.oauth2.jwt.Jwt jwt)
      Returns user privileges as Set of SimpleGrantedAuthorities. Used in case of JWT-based authentication.
      Parameters:
      jwt - The JWT containing username, privileges and further information.
      Returns:
      Set of privileges as SimpleGrantedAuthority instances.
    • loadUserByUsername

      @Transactional(readOnly=true) public org.springframework.security.core.userdetails.UserDetails loadUserByUsername(String username) throws org.springframework.security.core.userdetails.UsernameNotFoundException
      Loads the user with given username from the database.
      Specified by:
      loadUserByUsername in interface org.springframework.security.core.userdetails.UserDetailsService
      Parameters:
      username - The user's name.
      Returns:
      User data represented with a UserDetails object.
      Throws:
      org.springframework.security.core.userdetails.UsernameNotFoundException - If user with the given name is not found.
    • getAuthenticatedUser

      public org.springframework.security.core.userdetails.UserDetails getAuthenticatedUser()
      Returns the current user in a UserDetails object.
      Returns:
      The current user's details or null if no user is logged in.
      Throws:
      UserBlockedException - If the current user is blocked and blacklisted by TokenCache.
    • isCurrentUser

      public boolean isCurrentUser(UserListDto userListDto)
      Is the given user the currently logged-in user?
      Parameters:
      userListDto - One of the users of the system.
      Returns:
      True if the passed user is the current user.
    • hasAllPrivileges

      public boolean hasAllPrivileges(Privilege... privileges)
      Return true if the user has all the specified privileges/roles.
      Parameters:
      privileges - Array of required privileges.
      Returns:
      True if the current user has all required privileges.
    • hasAnyPrivileges

      public boolean hasAnyPrivileges(Privilege... privileges)
      Return true if the user has any of the specified privileges/roles.
      Parameters:
      privileges - Array of appropriate privileges.
      Returns:
      True if the current user has any of the appropriate privileges.