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.UserDetailscreateAdmin(Long adminId) Creates aUserDetailsobject for an admin user with the specified ID.org.springframework.security.core.userdetails.UserDetailscreateUser(Long userId) Creates aUserDetailsobject for a regular user with the specified ID.org.springframework.security.core.userdetails.UserDetailscreateUser(Long userId, Collection<? extends org.springframework.security.core.GrantedAuthority> authorities) Creates aUserDetailsobject with the specified user ID and authorities.booleanisAdmin()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:
trueif the user is an admin,falseotherwise.
-
createAdmin
Creates aUserDetailsobject for an admin user with the specified ID.- Parameters:
adminId- the ID of the admin user- Returns:
- a
UserDetailsobject representing the admin user
-
createUser
Creates aUserDetailsobject for a regular user with the specified ID.- Parameters:
userId- the ID of the user- Returns:
- a
UserDetailsobject representing the user
-
createUser
public org.springframework.security.core.userdetails.UserDetails createUser(Long userId, Collection<? extends org.springframework.security.core.GrantedAuthority> authorities) Creates aUserDetailsobject with the specified user ID and authorities.- Parameters:
userId- the ID of the userauthorities- the authorities granted to the user- Returns:
- a
UserDetailsobject representing the user
-