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 Details

    • SpringSecurityContextHandler

      public SpringSecurityContextHandler()
  • Method Details

    • setupAuthentication

      public void setupAuthentication(org.springframework.security.core.Authentication credentials)
      Specified by:
      setupAuthentication in interface com.vaadin.browserless.SecurityContextHandler<org.springframework.security.core.Authentication>
    • saveContext

      public org.springframework.security.core.context.SecurityContext saveContext()
      Specified by:
      saveContext in interface com.vaadin.browserless.SecurityContextHandler<org.springframework.security.core.Authentication>
    • restoreContext

      public void restoreContext(Object snapshot)
      Specified by:
      restoreContext in interface com.vaadin.browserless.SecurityContextHandler<org.springframework.security.core.Authentication>
    • clearContext

      public void clearContext()
      Specified by:
      clearContext in interface com.vaadin.browserless.SecurityContextHandler<org.springframework.security.core.Authentication>
    • createCredentials

      public org.springframework.security.core.Authentication createCredentials(String username, String... roles)
      Builds an Authentication for the given username and roles, in the same shape produced by Spring Security's @WithMockUser: a UsernamePasswordAuthenticationToken carrying a User principal whose authorities are the given roles, prefixed with ROLE_ when not already prefixed.
      Specified by:
      createCredentials in interface com.vaadin.browserless.SecurityContextHandler<org.springframework.security.core.Authentication>