public final class AuthenticationHelper extends Object
Modifier and Type | Field and Description |
---|---|
static String |
KENMEI_USER_ROLE
The user role of the user
|
static String |
PUBLIC_USER_ROLE
The user role of the public user
|
static String |
ROLE_ANONYMOUS
The user role of the anonymous user
|
static String |
ROLE_INTERNAL_SYSTEM
The user role of the public user
|
Modifier and Type | Method and Description |
---|---|
static org.springframework.security.core.Authentication |
createAuthentication(User user)
Create an authentication for the user that can be used to be set in the security context
|
static void |
removeAuthentication()
Remove the authentication from the security context.
|
static org.springframework.security.core.Authentication |
setAsAuthenticatedUser(User user)
Set the provided user as the currently authenticated user for the current thread.
|
static org.springframework.security.core.Authentication |
setAuthentication(org.springframework.security.core.Authentication newAuth)
Set the provided authentication object as the currently authenticated principal for the
current thread.
|
static org.springframework.security.core.context.SecurityContext |
setInternalSystemToSecurityContext()
Login as the internal system user.
|
static void |
setPublicUserToSecurityContext(javax.servlet.ServletRequest request)
Set the public user as authenticated user to the current SecurityContext.
|
static void |
setSecurityContext(org.springframework.security.core.context.SecurityContext securityContext)
Set the given SecurityContext.
|
public static final String ROLE_ANONYMOUS
public static final String PUBLIC_USER_ROLE
public static final String ROLE_INTERNAL_SYSTEM
public static final String KENMEI_USER_ROLE
public static org.springframework.security.core.Authentication createAuthentication(User user)
user
- the userpublic static void removeAuthentication()
setAuthentication(Authentication)
public static org.springframework.security.core.Authentication setAsAuthenticatedUser(User user)
The caller is responsible for restoring the authentication object that was previously set for the current thread.
NOTE: be careful when using this method from threads that originate from servlet requests as in this context the authentication is shared among all threads of the current HTTP session.
user
- the user to set as authenticatedpublic static org.springframework.security.core.Authentication setAuthentication(org.springframework.security.core.Authentication newAuth)
The caller is responsible for restoring the authentication object that was previously set for the current thread.
NOTE: be careful when using this method from threads that originate from servlet requests as in this context the authentication is shared among all threads of the current HTTP session.
newAuth
- the new authentication object, can be null to clear the authenticationpublic static org.springframework.security.core.context.SecurityContext setInternalSystemToSecurityContext()
Since Communote uses the SecurityContextPersistenceFilter the SecurityContext is shared between all threads of the current session. Therefore the internal system user is not just set in the existing security context, instead a new security context containing the internal system user is exposed to the SecurityContextHolder. The calling code has to ensure that it resets the previously contained SecurityContext after completing the operation which should have been run as internal system user. The recommended pattern is to use a try-finally block.
setSecurityContext(SecurityContext)
public static void setPublicUserToSecurityContext(javax.servlet.ServletRequest request)
request
- the servlet requestpublic static void setSecurityContext(org.springframework.security.core.context.SecurityContext securityContext)
setInternalSystemToSecurityContext()
completed.securityContext
- The security context to restoreCopyright © 2019 Communote team. All rights reserved.