Package com.vaadin.browserless
Class SpringSecurityContextHandler
java.lang.Object
com.vaadin.browserless.SpringSecurityContextHandler
- All Implemented Interfaces:
com.vaadin.browserless.SecurityContextHandler<org.springframework.security.core.Authentication>
public class SpringSecurityContextHandler
extends Object
implements com.vaadin.browserless.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).
- 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 interfacecom.vaadin.browserless.SecurityContextHandler<org.springframework.security.core.Authentication>
-
saveContext
public org.springframework.security.core.context.SecurityContext saveContext()- Specified by:
saveContextin interfacecom.vaadin.browserless.SecurityContextHandler<org.springframework.security.core.Authentication>
-
restoreContext
- Specified by:
restoreContextin interfacecom.vaadin.browserless.SecurityContextHandler<org.springframework.security.core.Authentication>
-
clearContext
public void clearContext()- Specified by:
clearContextin interfacecom.vaadin.browserless.SecurityContextHandler<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 interfacecom.vaadin.browserless.SecurityContextHandler<org.springframework.security.core.Authentication>
-