Class SecurityMockServerConfigurers
- java.lang.Object
-
- org.springframework.security.test.web.reactive.server.SecurityMockServerConfigurers
-
public class SecurityMockServerConfigurers extends java.lang.Object
Test utilities for working with Spring Security andWebTestClient.Builder.apply(WebTestClientConfigurer)
.- Since:
- 5.0
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
SecurityMockServerConfigurers.CsrfMutator
static class
SecurityMockServerConfigurers.JwtMutator
Updates the WebServerExchange using{@link SecurityMockServerConfigurers#mockAuthentication(Authentication)}
.static class
SecurityMockServerConfigurers.UserExchangeMutator
Updates the WebServerExchange using{@link SecurityMockServerConfigurers#mockUser(UserDetails)}
.
-
Constructor Summary
Constructors Constructor Description SecurityMockServerConfigurers()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static SecurityMockServerConfigurers.CsrfMutator
csrf()
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 Principalstatic SecurityMockServerConfigurers.JwtMutator
mockJwt()
Updates the ServerWebExchange to establish aSecurityContext
that has aJwtAuthenticationToken
for theAuthentication
and aJwt
for theAuthentication.getPrincipal()
.static SecurityMockServerConfigurers.UserExchangeMutator
mockUser()
Updates the ServerWebExchange to use a UserDetails to create a UsernamePasswordAuthenticationToken as the Principal.static SecurityMockServerConfigurers.UserExchangeMutator
mockUser(java.lang.String username)
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.MockServerConfigurer
springSecurity()
Sets up Spring Security'sWebTestClient
test support
-
-
-
Method Detail
-
springSecurity
public static org.springframework.test.web.reactive.server.MockServerConfigurer springSecurity()
Sets up Spring Security'sWebTestClient
test 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
public static SecurityMockServerConfigurers.UserExchangeMutator 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.UserExchangeMutator
to use
-
mockUser
public static SecurityMockServerConfigurers.UserExchangeMutator mockUser(java.lang.String username)
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
WebTestClientConfigurer
to use
-
mockJwt
public static SecurityMockServerConfigurers.JwtMutator mockJwt()
Updates the ServerWebExchange to establish aSecurityContext
that has aJwtAuthenticationToken
for theAuthentication
and aJwt
for theAuthentication.getPrincipal()
. All details are declarative and do not require the JWT to be valid.- Returns:
- the
SecurityMockServerConfigurers.JwtMutator
to further configure or use - Since:
- 5.2
-
csrf
public static SecurityMockServerConfigurers.CsrfMutator csrf()
-
-