public class WithSecurityContextTestExecutionListener
extends org.springframework.test.context.support.AbstractTestExecutionListener
TestExecutionListener that will find annotations that are annotated with
WithSecurityContext on a test method or at the class level. If found, the
WithSecurityContext.factory() is used to create a SecurityContext that
will be used with this test. If using with MockMvc the
SecurityMockMvcRequestPostProcessors.testSecurityContext() needs to be used
too.ReactorContextTestExecutionListener,
SecurityTestExecutionListeners| Constructor and Description |
|---|
WithSecurityContextTestExecutionListener() |
| Modifier and Type | Method and Description |
|---|---|
void |
afterTestMethod(org.springframework.test.context.TestContext testContext)
Clears out the
TestSecurityContextHolder and the
SecurityContextHolder after each test method. |
void |
beforeTestExecution(org.springframework.test.context.TestContext testContext)
If configured before test execution sets the SecurityContext
|
void |
beforeTestMethod(org.springframework.test.context.TestContext testContext)
Sets up the
SecurityContext for each test method. |
int |
getOrder()
Returns
10000. |
public WithSecurityContextTestExecutionListener()
public void beforeTestMethod(org.springframework.test.context.TestContext testContext)
SecurityContext for each test method. First the specific method
is inspected for a WithSecurityContext or Annotation that has
WithSecurityContext on it. If that is not found, the class is inspected. If
still not found, then no SecurityContext is populated.beforeTestMethod in interface org.springframework.test.context.TestExecutionListenerbeforeTestMethod in class org.springframework.test.context.support.AbstractTestExecutionListenerpublic void beforeTestExecution(org.springframework.test.context.TestContext testContext)
beforeTestExecution in interface org.springframework.test.context.TestExecutionListenerbeforeTestExecution in class org.springframework.test.context.support.AbstractTestExecutionListenerpublic void afterTestMethod(org.springframework.test.context.TestContext testContext)
TestSecurityContextHolder and the
SecurityContextHolder after each test method.afterTestMethod in interface org.springframework.test.context.TestExecutionListenerafterTestMethod in class org.springframework.test.context.support.AbstractTestExecutionListenerpublic int getOrder()
10000.getOrder in interface org.springframework.core.OrderedgetOrder in class org.springframework.test.context.support.AbstractTestExecutionListener