Package com.vaadin.hilla
Class AuthenticationUtil
java.lang.Object
com.vaadin.hilla.AuthenticationUtil
Helpers for authentication related tasks.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic org.springframework.security.core.AuthenticationGets the authentication from the Spring SecurityContextHolder the same way Spring Security does when it authorizes a request: an anonymous user is reported with itsAnonymousAuthenticationTokeninstead ofnull, and a completely missing authentication is an error.static org.springframework.security.core.AuthenticationGets the authenticated user from the Spring SecurityContextHolder.Gets a function for checking if the authenticated user from the Spring SecurityContextHolder is in a given role.getSecurityHolderRoleChecker(String rolePrefix) Gets a function for checking if the authenticated user from the Spring SecurityContextHolder is in a given role.
-
Constructor Details
-
AuthenticationUtil
public AuthenticationUtil()
-
-
Method Details
-
getSecurityHolderAuthentication
public static org.springframework.security.core.Authentication getSecurityHolderAuthentication()Gets the authenticated user from the Spring SecurityContextHolder.- Returns:
- the authenticated user or
null
-
getRequiredSecurityHolderAuthentication
public static org.springframework.security.core.Authentication getRequiredSecurityHolderAuthentication()Gets the authentication from the Spring SecurityContextHolder the same way Spring Security does when it authorizes a request: an anonymous user is reported with itsAnonymousAuthenticationTokeninstead ofnull, and a completely missing authentication is an error.- Returns:
- the current authentication, never
null - Throws:
org.springframework.security.authentication.AuthenticationCredentialsNotFoundException- if the SecurityContextHolder holds no authentication
-
getSecurityHolderRoleChecker
Gets a function for checking if the authenticated user from the Spring SecurityContextHolder is in a given role. Given role is prefixed with the role prefix fromVaadinRolePrefixHolderif available, otherwise defaults to 'ROLE_'.- Returns:
- a function for checking if the given user has the given role
-
getSecurityHolderRoleChecker
Gets a function for checking if the authenticated user from the Spring SecurityContextHolder is in a given role.- Parameters:
rolePrefix- Prefix for the given role.- Returns:
- a function for checking if the given user has the given role
-