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 reactor.core.publisher.Mono<String>getCurrentUserDisplayName()Get the display name of the current user.static reactor.core.publisher.Mono<String>getCurrentUserLogin()Get the login of the current user.static reactor.core.publisher.Mono<Boolean>hasCurrentUserAnyOfAuthorities(String... authorities)Checks if the current user has any of the authorities.static reactor.core.publisher.Mono<Boolean>hasCurrentUserNoneOfAuthorities(String... authorities)Checks if the current user has none of the authorities.static reactor.core.publisher.Mono<Boolean>hasCurrentUserThisAuthority(String authority)Checks if the current user has a specific authority.static reactor.core.publisher.Mono<Boolean>isAuthenticated()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 reactor.core.publisher.Mono<String> getCurrentUserLogin()
Get the login of the current user.- Returns:
- the login of the current user.
-
getCurrentUserDisplayName
public static reactor.core.publisher.Mono<String> getCurrentUserDisplayName()
Get the display name of the current user.- Returns:
- the display name of the current user.
-
isAuthenticated
public static reactor.core.publisher.Mono<Boolean> isAuthenticated()
Check if a user is authenticated.- Returns:
- true if the user is authenticated, false otherwise.
-
hasCurrentUserAnyOfAuthorities
public static reactor.core.publisher.Mono<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 reactor.core.publisher.Mono<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 reactor.core.publisher.Mono<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
-
-