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)NtsSecurityUtils(NtsProperties ntsProperties)
-
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<Object>getCurrentUserClaim(String claim)Get claim value of current user by claim namestatic 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
@Autowired public NtsSecurityUtils(NtsProperties ntsProperties)
-
-
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)
-
getCurrentUserClaim
public static Optional<Object> getCurrentUserClaim(String claim)
Get claim value of current user by claim name- Parameters:
claim- the name of claim in JWT- Returns:
- Optional of claim value
-
afterPropertiesSet
public void afterPropertiesSet()
- Specified by:
afterPropertiesSetin interfaceorg.springframework.beans.factory.InitializingBean
-
-