public interface MockMvcAuthenticationSpecification
spring-security-test module to the classpath and use the with(RequestPostProcessor, RequestPostProcessor...) method for authentication and authorization.| Modifier and Type | Method and Description |
|---|---|
MockMvcRequestSpecification |
authentication(Object authentication)
Authenticate using the given authentication instance.
|
MockMvcRequestSpecification |
none()
Explicitly state that you don't which to use any authentication in this request.
|
MockMvcRequestSpecification |
principal(Object principal)
Authenticate using the given principal.
|
MockMvcRequestSpecification |
principal(Principal principal)
Authenticate using the given principal.
|
MockMvcRequestSpecification |
principalWithCredentials(Object principal,
Object credentials,
String... authorities)
Authenticate using the given principal and credentials.
|
MockMvcRequestSpecification |
with(org.springframework.test.web.servlet.request.RequestPostProcessor requestPostProcessor,
org.springframework.test.web.servlet.request.RequestPostProcessor... additionalRequestPostProcessor)
Authenticate using a
RequestPostProcessor. |
MockMvcRequestSpecification principal(Principal principal)
MockHttpServletRequestBuilder.principal(java.security.Principal).principal - The principal to use.MockHttpServletRequestBuilder.principal(java.security.Principal)MockMvcRequestSpecification with(org.springframework.test.web.servlet.request.RequestPostProcessor requestPostProcessor, org.springframework.test.web.servlet.request.RequestPostProcessor... additionalRequestPostProcessor)
RequestPostProcessor.
This is mainly useful when you have added the spring-security-test artifact to classpath. This allows
you to do for example:
given().auth().with(user("username").password("password")). ..
where user is statically imported from org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.requestPostProcessor - The first request post processor to be used for authenticationadditionalRequestPostProcessor - Additional request post processors to be used for authenticationMockMvcAuthenticationScheme instance.MockMvcRequestSpecification principal(Object principal)
SecurityContextHolder.getContext().setAuthentication(new TestingAuthenticationToken(principal, ""));
Note that this method require Spring Security to be on the classpath. Also note that if you use this method Rest Assured will NOT be thread-safe.
principal - The principal to use.MockMvcRequestSpecification principalWithCredentials(Object principal, Object credentials, String... authorities)
SecurityContextHolder.getContext().setAuthentication(new TestingAuthenticationToken(principal, credentials, authorities));
Note that this method require Spring Security to be on the classpath. Also note that if you use this method Rest Assured will NOT be thread-safe.
principal - The principal to use.credentials - The credentials to useauthorities - Optional list of authoritiesMockMvcRequestSpecification authentication(Object authentication)
SecurityContextHolder.getContext().setAuthentication(authentication);This means that the supplied object must be an instance of
org.springframework.security.core.Authentication.
Note that this method require Spring Security to be on the classpath. Also note that if you use this method Rest Assured will NOT be thread-safe.
authentication - the spring security authentication to use.MockMvcRequestSpecification none()
Copyright © 2010–2025. All rights reserved.