java.lang.Object
io.github.yvasyliev.telegramforwarderbot.util.AuthUtils

public class AuthUtils extends Object
Utility class for authentication-related operations. Provides methods to check user roles and create user details.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    final String
    Default password for users.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    org.springframework.security.core.userdetails.UserDetails
    createAdmin(Long adminId)
    Creates a UserDetails object for an admin user with the specified ID.
    org.springframework.security.core.userdetails.UserDetails
    createUser(Long userId)
    Creates a UserDetails object for a regular user with the specified ID.
    org.springframework.security.core.userdetails.UserDetails
    createUser(Long userId, Collection<? extends org.springframework.security.core.GrantedAuthority> authorities)
    Creates a UserDetails object with the specified user ID and authorities.
    boolean
    Checks if the current user has admin privileges.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • DEFAULT_PASSWORD

      public final String DEFAULT_PASSWORD
      Default password for users. Always {noop} for empty password without encoding.
      See Also:
  • Constructor Details

    • AuthUtils

      public AuthUtils()
  • Method Details

    • isAdmin

      public boolean isAdmin()
      Checks if the current user has admin privileges.
      Returns:
      true if the user is an admin, false otherwise.
    • createAdmin

      public org.springframework.security.core.userdetails.UserDetails createAdmin(Long adminId)
      Creates a UserDetails object for an admin user with the specified ID.
      Parameters:
      adminId - the ID of the admin user
      Returns:
      a UserDetails object representing the admin user
    • createUser

      public org.springframework.security.core.userdetails.UserDetails createUser(Long userId)
      Creates a UserDetails object for a regular user with the specified ID.
      Parameters:
      userId - the ID of the user
      Returns:
      a UserDetails object representing the user
    • createUser

      public org.springframework.security.core.userdetails.UserDetails createUser(Long userId, Collection<? extends org.springframework.security.core.GrantedAuthority> authorities)
      Creates a UserDetails object with the specified user ID and authorities.
      Parameters:
      userId - the ID of the user
      authorities - the authorities granted to the user
      Returns:
      a UserDetails object representing the user