Class AuthUtils
java.lang.Object
io.github.yvasyliev.telegramforwarderbot.util.AuthUtils
Utility class for authentication-related operations.
Provides methods to check user roles and create user details.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionorg.springframework.security.core.userdetails.UserDetails
createAdmin
(Long adminId) Creates aUserDetails
object for an admin user with the specified ID.org.springframework.security.core.userdetails.UserDetails
createUser
(Long userId) Creates aUserDetails
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 aUserDetails
object with the specified user ID and authorities.boolean
isAdmin()
Checks if the current user has admin privileges.
-
Field Details
-
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
Creates aUserDetails
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
Creates aUserDetails
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 aUserDetails
object with the specified user ID and authorities.- Parameters:
userId
- the ID of the userauthorities
- the authorities granted to the user- Returns:
- a
UserDetails
object representing the user
-