1
0
mirror of synced 2026-08-04 17:27:13 +00:00

SEC-3084: Doc SecurityContextRequestPostProcessorSupport & SecurityContextHolder

This commit is contained in:
Rob Winch
2015-08-20 09:30:24 -05:00
parent c79bceab03
commit 327695ab0c
2 changed files with 65 additions and 4 deletions
@@ -371,9 +371,20 @@ There are two simple ways of populating the user:
[[test-mockmvc-securitycontextholder-rpp]]
==== Running as a User in Spring MVC Test with RequestPostProcessor
There are a number of options available to populate a test user.
There are a number of options available to associate a user to the current `HttpServletRequest`.
For example, the following will run as a user (which does not need to exist) with the username "user", the password "password", and the role "ROLE_USER":
[NOTE]
====
The support works by associating the user to the `HttpServletRequest`.
To associate the request to the `SecurityContextHolder` you need to ensure that the `SecurityContextPersistenceFilter` is associated with the `MockMvc` instance.
A few ways to do this are:
* Invoking <<test-mockmvc-setup,apply(springSecurity())>>
* Adding Spring Security's `FilterChainProxy` to `MockMvc`
* Manually adding `SecurityContextPersistenceFilter` to the `MockMvc` instance may make sense when using `MockMvcBuilders.standaloneSetup`
====
[source,java]
----
mvc