Class WithSecurityContextTestExecutionListener
- java.lang.Object
-
- org.springframework.test.context.support.AbstractTestExecutionListener
-
- org.springframework.security.test.context.support.WithSecurityContextTestExecutionListener
-
- All Implemented Interfaces:
org.springframework.core.Ordered,org.springframework.test.context.TestExecutionListener
public class WithSecurityContextTestExecutionListener extends org.springframework.test.context.support.AbstractTestExecutionListenerATestExecutionListenerthat will find annotations that are annotated withWithSecurityContexton a test method or at the class level. If found, theWithSecurityContext.factory()is used to create aSecurityContextthat will be used with this test. If using withMockMvctheSecurityMockMvcRequestPostProcessors.testSecurityContext()needs to be used too.- Since:
- 4.0
- See Also:
ReactorContextTestExecutionListener,SecurityTestExecutionListeners
-
-
Constructor Summary
Constructors Constructor Description WithSecurityContextTestExecutionListener()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidafterTestMethod(org.springframework.test.context.TestContext testContext)Clears out theTestSecurityContextHolderand theSecurityContextHolderafter each test method.voidbeforeTestExecution(org.springframework.test.context.TestContext testContext)If configured before test execution sets the SecurityContextvoidbeforeTestMethod(org.springframework.test.context.TestContext testContext)Sets up theSecurityContextfor each test method.intgetOrder()Returns10000.
-
-
-
Method Detail
-
beforeTestMethod
public void beforeTestMethod(org.springframework.test.context.TestContext testContext)
Sets up theSecurityContextfor each test method. First the specific method is inspected for aWithSecurityContextorAnnotationthat hasWithSecurityContexton it. If that is not found, the class is inspected. If still not found, then noSecurityContextis populated.- Specified by:
beforeTestMethodin interfaceorg.springframework.test.context.TestExecutionListener- Overrides:
beforeTestMethodin classorg.springframework.test.context.support.AbstractTestExecutionListener
-
beforeTestExecution
public void beforeTestExecution(org.springframework.test.context.TestContext testContext)
If configured before test execution sets the SecurityContext- Specified by:
beforeTestExecutionin interfaceorg.springframework.test.context.TestExecutionListener- Overrides:
beforeTestExecutionin classorg.springframework.test.context.support.AbstractTestExecutionListener- Since:
- 5.1
-
afterTestMethod
public void afterTestMethod(org.springframework.test.context.TestContext testContext)
Clears out theTestSecurityContextHolderand theSecurityContextHolderafter each test method.- Specified by:
afterTestMethodin interfaceorg.springframework.test.context.TestExecutionListener- Overrides:
afterTestMethodin classorg.springframework.test.context.support.AbstractTestExecutionListener
-
getOrder
public int getOrder()
Returns10000.- Specified by:
getOrderin interfaceorg.springframework.core.Ordered- Overrides:
getOrderin classorg.springframework.test.context.support.AbstractTestExecutionListener
-
-