public class WithSecurityContextTestExcecutionListener extends 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.Constructor and Description |
---|
WithSecurityContextTestExcecutionListener() |
Modifier and Type | Method and Description |
---|---|
void |
afterTestMethod(TestContext testContext)
Clears out the
TestSecurityContextHolder and the
SecurityContextHolder after each test method. |
void |
beforeTestMethod(TestContext testContext)
Sets up the
SecurityContext for each test method. |
afterTestClass, beforeTestClass, prepareTestInstance
public WithSecurityContextTestExcecutionListener()
public void beforeTestMethod(TestContext testContext) throws Exception
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 TestExecutionListener
beforeTestMethod
in class AbstractTestExecutionListener
Exception
public void afterTestMethod(TestContext testContext) throws Exception
TestSecurityContextHolder
and the
SecurityContextHolder
after each test method.afterTestMethod
in interface TestExecutionListener
afterTestMethod
in class AbstractTestExecutionListener
Exception