1
0
mirror of synced 2026-08-06 02:08:01 +00:00

Allow WithSecurityContextTestExecutionListener to execute after @Before

Fixes: gh-2935
This commit is contained in:
Rob Winch
2018-03-07 17:05:32 -06:00
parent 055a2ca917
commit abae2f3e87
12 changed files with 465 additions and 38 deletions
@@ -144,6 +144,15 @@ For example, the following would run every test with a user with the username "a
public class WithMockUserTests {
----
By default the `SecurityContext` is set during the `TestExecutionListener.beforeTestMethod` event.
This is the equivalent of happening before JUnit's `@Before`.
You can change this to happen during the `TestExecutionListener.beforeTestExecution` event which is after JUnit's `@Before` but before the test method is invoked.
[source,java]
----
@WithMockUser(setupBefore = TestExecutionEvent.TEST_EXECUTION)
----
[[test-method-withanonymoususer]]
=== @WithAnonymousUser
@@ -174,6 +183,15 @@ public class WithUserClassLevelAuthenticationTests {
}
----
By default the `SecurityContext` is set during the `TestExecutionListener.beforeTestMethod` event.
This is the equivalent of happening before JUnit's `@Before`.
You can change this to happen during the `TestExecutionListener.beforeTestExecution` event which is after JUnit's `@Before` but before the test method is invoked.
[source,java]
----
@WithAnonymousUser(setupBefore = TestExecutionEvent.TEST_EXECUTION)
----
[[test-method-withuserdetails]]
=== @WithUserDetails
@@ -227,6 +245,16 @@ public void getMessageWithUserDetailsServiceBeanName() {
Like `@WithMockUser` we can also place our annotation at the class level so that every test uses the same user.
However unlike `@WithMockUser`, `@WithUserDetails` requires the user to exist.
By default the `SecurityContext` is set during the `TestExecutionListener.beforeTestMethod` event.
This is the equivalent of happening before JUnit's `@Before`.
You can change this to happen during the `TestExecutionListener.beforeTestExecution` event which is after JUnit's `@Before` but before the test method is invoked.
[source,java]
----
@WithUserDetails(setupBefore = TestExecutionEvent.TEST_EXECUTION)
----
[[test-method-withsecuritycontext]]
=== @WithSecurityContext
@@ -301,6 +329,16 @@ final class WithUserDetailsSecurityContextFactory
}
----
By default the `SecurityContext` is set during the `TestExecutionListener.beforeTestMethod` event.
This is the equivalent of happening before JUnit's `@Before`.
You can change this to happen during the `TestExecutionListener.beforeTestExecution` event which is after JUnit's `@Before` but before the test method is invoked.
[source,java]
----
@WithSecurityContext(setupBefore = TestExecutionEvent.TEST_EXECUTION)
----
[[test-method-meta-annotations]]
=== Test Meta Annotations
+6 -18
View File
@@ -400,28 +400,16 @@ git clone https://github.com/spring-projects/spring-security.git
This will give you access to the entire project history (including all releases and branches) on your local machine.
[[new]]
== What's New in Spring Security 5.0
== What's New in Spring Security 5.1
Spring Security 5.0 provides a number of new features as well as support for Spring Framework 5.
In total there were 400+ enhancements and bugs resolved.
You can find the change log at
https://github.com/spring-projects/spring-security/milestone/90?closed=1[5.0.0.M1]
https://github.com/spring-projects/spring-security/milestone/97?closed=1[5.0.0.M2]
https://github.com/spring-projects/spring-security/milestone/100?closed=1[5.0.0.M3]
https://github.com/spring-projects/spring-security/milestone/101?closed=1[5.0.0.M4]
https://github.com/spring-projects/spring-security/milestone/102?closed=1[5.0.0.M5]
https://github.com/spring-projects/spring-security/milestone/103?closed=1[5.0.0.RC1]
https://github.com/spring-projects/spring-security/milestone/98?closed=1[5.0.0.RELEASE].
Below are the highlights of this milestone release.
Spring Security 5.1 provides a number of new features.
Below are the highlights of the release.
=== New Features
* <<jc-oauth2login,OAuth 2.0 Login>>
* Reactive Support
** <<jc-webflux,@EnableWebFluxSecurity>>
** <<jc-erms,@EnableReactiveMethodSecurity>>
** <<test-webflux,WebFlux Testing Support>>
* Modernized <<core-services-password-encoding,Password Encoding>>
* <<test-method>> - Support for customizing when the `SecurityContext` is setup in the test.
For example, `@WithMockUser(setupBefore = TestExecutionEvent.TEST_EXECUTION)` will setup a user after JUnit's `@Before` and before the test executes.
[[samples]]
== Samples and Guides (Start Here)