Package com.vaadin.browserless
Class SpringSecurityContextHandler
java.lang.Object
com.vaadin.browserless.SpringSecurityContextHandler
- All Implemented Interfaces:
SecurityContextHandler<org.springframework.security.core.Authentication>
public class SpringSecurityContextHandler
extends Object
implements SecurityContextHandler<org.springframework.security.core.Authentication>
Spring Security implementation of
SecurityContextHandler.
Manages the thread-local SecurityContext via
SecurityContextHolder for multi-user test isolation.
The SecurityContextHandler.setupAuthentication(Object) method expects an
Authentication instance as the credentials parameter, or null
for an anonymous user — in which case an AnonymousAuthenticationToken
is installed (mirroring the behaviour of @WithAnonymousUser).
- Since:
- 1.1
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidorg.springframework.security.core.AuthenticationcreateCredentials(String username, String... roles) Builds anAuthenticationfor the given username and roles, in the same shape produced by Spring Security's@WithMockUser: aUsernamePasswordAuthenticationTokencarrying aUserprincipal whose authorities are the given roles, prefixed withROLE_when not already prefixed.voidrestoreContext(Object snapshot) org.springframework.security.core.context.SecurityContextvoidsetupAuthentication(org.springframework.security.core.Authentication credentials)
-
Constructor Details
-
SpringSecurityContextHandler
public SpringSecurityContextHandler()
-
-
Method Details
-
setupAuthentication
public void setupAuthentication(org.springframework.security.core.Authentication credentials) - Specified by:
setupAuthenticationin interfaceSecurityContextHandler<org.springframework.security.core.Authentication>
-
saveContext
public org.springframework.security.core.context.SecurityContext saveContext()- Specified by:
saveContextin interfaceSecurityContextHandler<org.springframework.security.core.Authentication>
-
restoreContext
- Specified by:
restoreContextin interfaceSecurityContextHandler<org.springframework.security.core.Authentication>
-
clearContext
public void clearContext()- Specified by:
clearContextin interfaceSecurityContextHandler<org.springframework.security.core.Authentication>
-
createCredentials
public org.springframework.security.core.Authentication createCredentials(String username, String... roles) Builds anAuthenticationfor the given username and roles, in the same shape produced by Spring Security's@WithMockUser: aUsernamePasswordAuthenticationTokencarrying aUserprincipal whose authorities are the given roles, prefixed withROLE_when not already prefixed.- Specified by:
createCredentialsin interfaceSecurityContextHandler<org.springframework.security.core.Authentication>
-