Class SecurityMockServerConfigurers
java.lang.Object
org.springframework.security.test.web.reactive.server.SecurityMockServerConfigurers
Test utilities for working with Spring Security and
WebTestClient.Builder.apply(WebTestClientConfigurer).- Since:
- 5.0
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classstatic final classUpdates the WebServerExchange using{@link SecurityMockServerConfigurers#mockAuthentication(Authentication)}.static final classstatic final classstatic final classstatic final classstatic final classUpdates the WebServerExchange using{@link SecurityMockServerConfigurers#mockUser(UserDetails)}. -
Method Summary
Modifier and TypeMethodDescriptioncsrf()static <T extends org.springframework.test.web.reactive.server.WebTestClientConfigurer & org.springframework.test.web.reactive.server.MockServerConfigurer>
TmockAuthentication(Authentication authentication) Updates the ServerWebExchange to use the provided Authentication as the PrincipalmockJwt()Updates the ServerWebExchange to establish aSecurityContextthat has aJwtAuthenticationTokenfor theAuthenticationand aJwtfor theAuthentication.getPrincipal().Updates the ServerWebExchange to establish aOAuth2AuthorizedClientin the session.mockOAuth2Client(String registrationId) Updates the ServerWebExchange to establish aOAuth2AuthorizedClientin the session.Updates the ServerWebExchange to establish aSecurityContextthat has aOAuth2AuthenticationTokenfor theAuthentication.Updates the ServerWebExchange to establish aSecurityContextthat has aOAuth2AuthenticationTokenfor theAuthentication.Updates the ServerWebExchange to establish aSecurityContextthat has aBearerTokenAuthenticationfor theAuthenticationand anOAuth2AuthenticatedPrincipalfor theAuthentication.getPrincipal().mockUser()Updates the ServerWebExchange to use a UserDetails to create a UsernamePasswordAuthenticationToken as the Principal.Updates the ServerWebExchange to use a UserDetails to create a UsernamePasswordAuthenticationToken as the Principal.static <T extends org.springframework.test.web.reactive.server.WebTestClientConfigurer & org.springframework.test.web.reactive.server.MockServerConfigurer>
TmockUser(UserDetails userDetails) Updates the ServerWebExchange to use the provided UserDetails to create a UsernamePasswordAuthenticationToken as the Principalstatic org.springframework.test.web.reactive.server.MockServerConfigurerSets up Spring Security'sWebTestClienttest support
-
Method Details
-
springSecurity
public static org.springframework.test.web.reactive.server.MockServerConfigurer springSecurity()Sets up Spring Security'sWebTestClienttest support- Returns:
- the MockServerConfigurer to use
-
mockAuthentication
public static <T extends org.springframework.test.web.reactive.server.WebTestClientConfigurer & org.springframework.test.web.reactive.server.MockServerConfigurer> T mockAuthentication(Authentication authentication) Updates the ServerWebExchange to use the provided Authentication as the Principal- Parameters:
authentication- the Authentication to use.- Returns:
- the configurer to use
-
mockUser
public static <T extends org.springframework.test.web.reactive.server.WebTestClientConfigurer & org.springframework.test.web.reactive.server.MockServerConfigurer> T mockUser(UserDetails userDetails) Updates the ServerWebExchange to use the provided UserDetails to create a UsernamePasswordAuthenticationToken as the Principal- Parameters:
userDetails- the UserDetails to use.- Returns:
- the configurer to use
-
mockUser
Updates the ServerWebExchange to use a UserDetails to create a UsernamePasswordAuthenticationToken as the Principal. This uses a default username of "user", password of "password", and granted authorities of "ROLE_USER".- Returns:
- the
SecurityMockServerConfigurers.UserExchangeMutatorto use
-
mockUser
Updates the ServerWebExchange to use a UserDetails to create a UsernamePasswordAuthenticationToken as the Principal. This uses a default password of "password" and granted authorities of "ROLE_USER".- Returns:
- the
WebTestClientConfigurerto use
-
mockJwt
Updates the ServerWebExchange to establish aSecurityContextthat has aJwtAuthenticationTokenfor theAuthenticationand aJwtfor theAuthentication.getPrincipal(). All details are declarative and do not require the JWT to be valid.- Returns:
- the
SecurityMockServerConfigurers.JwtMutatorto further configure or use - Since:
- 5.2
-
mockOpaqueToken
Updates the ServerWebExchange to establish aSecurityContextthat has aBearerTokenAuthenticationfor theAuthenticationand anOAuth2AuthenticatedPrincipalfor theAuthentication.getPrincipal(). All details are declarative and do not require the token to be valid.- Returns:
- the
SecurityMockServerConfigurers.OpaqueTokenMutatorto further configure or use - Since:
- 5.3
-
mockOAuth2Login
Updates the ServerWebExchange to establish aSecurityContextthat has aOAuth2AuthenticationTokenfor theAuthentication. All details are declarative and do not require the corresponding OAuth 2.0 tokens to be valid.- Returns:
- the
SecurityMockServerConfigurers.OAuth2LoginMutatorto further configure or use - Since:
- 5.3
-
mockOidcLogin
Updates the ServerWebExchange to establish aSecurityContextthat has aOAuth2AuthenticationTokenfor theAuthentication. All details are declarative and do not require the corresponding OAuth 2.0 tokens to be valid.- Returns:
- the
SecurityMockServerConfigurers.OidcLoginMutatorto further configure or use - Since:
- 5.3
-
mockOAuth2Client
Updates the ServerWebExchange to establish aOAuth2AuthorizedClientin the session. All details are declarative and do not require the corresponding OAuth 2.0 tokens to be valid.The support works by associating the authorized client to the ServerWebExchange using a
ServerOAuth2AuthorizedClientRepository- Returns:
- the
SecurityMockServerConfigurers.OAuth2ClientMutatorto further configure or use - Since:
- 5.3
-
mockOAuth2Client
public static SecurityMockServerConfigurers.OAuth2ClientMutator mockOAuth2Client(String registrationId) Updates the ServerWebExchange to establish aOAuth2AuthorizedClientin the session. All details are declarative and do not require the corresponding OAuth 2.0 tokens to be valid.The support works by associating the authorized client to the ServerWebExchange using a
ServerOAuth2AuthorizedClientRepository- Parameters:
registrationId- The registration id associated with theOAuth2AuthorizedClient- Returns:
- the
SecurityMockServerConfigurers.OAuth2ClientMutatorto further configure or use - Since:
- 5.3
-
csrf
-