Package org.nentangso.core.security
Class NtsSecurityUtils
- java.lang.Object
-
- org.nentangso.core.security.NtsSecurityUtils
-
- All Implemented Interfaces:
org.springframework.beans.factory.InitializingBean
@Component public final class NtsSecurityUtils extends Object implements org.springframework.beans.factory.InitializingBean
Utility class for Spring Security.
-
-
Constructor Summary
Constructors Constructor Description NtsSecurityUtils(String rolesClaim, String rolePrefix, boolean reverseOrderOfDisplayName)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidafterPropertiesSet()static List<org.springframework.security.core.GrantedAuthority>extractAuthorityFromClaims(Map<String,Object> claims)static Optional<String>getCurrentUserDisplayName()Get the display name of the current user.static Optional<String>getCurrentUserLogin()Get the login of the current user.static booleanhasCurrentUserAnyOfAuthorities(String... authorities)Checks if the current user has any of the authorities.static booleanhasCurrentUserNoneOfAuthorities(String... authorities)Checks if the current user has none of the authorities.static booleanhasCurrentUserThisAuthority(String authority)Checks if the current user has a specific authority.static booleanisAuthenticated()Check if a user is authenticated.
-
-
-
Constructor Detail
-
NtsSecurityUtils
public NtsSecurityUtils(@Value("${nts.security.oauth2.client.configuration.roles-claim:roles}") String rolesClaim, @Value("${nts.security.oauth2.client.configuration.role-prefix:ROLE_}") String rolePrefix, @Value("${nts.security.oauth2.client.configuration.reverse-order-of-display-name:true}") boolean reverseOrderOfDisplayName)
-
-
Method Detail
-
getCurrentUserLogin
public static Optional<String> getCurrentUserLogin()
Get the login of the current user.- Returns:
- the login of the current user.
-
getCurrentUserDisplayName
public static Optional<String> getCurrentUserDisplayName()
Get the display name of the current user.- Returns:
- the display name of the current user.
-
isAuthenticated
public static boolean isAuthenticated()
Check if a user is authenticated.- Returns:
- true if the user is authenticated, false otherwise.
-
hasCurrentUserAnyOfAuthorities
public static boolean hasCurrentUserAnyOfAuthorities(String... authorities)
Checks if the current user has any of the authorities.- Parameters:
authorities- the authorities to check.- Returns:
- true if the current user has any of the authorities, false otherwise.
-
hasCurrentUserNoneOfAuthorities
public static boolean hasCurrentUserNoneOfAuthorities(String... authorities)
Checks if the current user has none of the authorities.- Parameters:
authorities- the authorities to check.- Returns:
- true if the current user has none of the authorities, false otherwise.
-
hasCurrentUserThisAuthority
public static boolean hasCurrentUserThisAuthority(String authority)
Checks if the current user has a specific authority.- Parameters:
authority- the authority to check.- Returns:
- true if the current user has the authority, false otherwise.
-
extractAuthorityFromClaims
public static List<org.springframework.security.core.GrantedAuthority> extractAuthorityFromClaims(Map<String,Object> claims)
-
afterPropertiesSet
public void afterPropertiesSet()
- Specified by:
afterPropertiesSetin interfaceorg.springframework.beans.factory.InitializingBean
-
-