Class WithSecurityContextTestExecutionListener

    • Field Summary

      • Fields inherited from interface org.springframework.core.Ordered

        HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method 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.
      • Methods inherited from class org.springframework.test.context.support.AbstractTestExecutionListener

        afterTestClass, afterTestExecution, beforeTestClass, prepareTestInstance
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • WithSecurityContextTestExecutionListener

        public WithSecurityContextTestExecutionListener()
    • Method Detail

      • beforeTestMethod

        public void beforeTestMethod​(org.springframework.test.context.TestContext testContext)
        Sets up the 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.
        Specified by:
        beforeTestMethod in interface org.springframework.test.context.TestExecutionListener
        Overrides:
        beforeTestMethod in class org.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:
        beforeTestExecution in interface org.springframework.test.context.TestExecutionListener
        Overrides:
        beforeTestExecution in class org.springframework.test.context.support.AbstractTestExecutionListener
        Since:
        5.1
      • afterTestMethod

        public void afterTestMethod​(org.springframework.test.context.TestContext testContext)
        Clears out the TestSecurityContextHolder and the SecurityContextHolder after each test method.
        Specified by:
        afterTestMethod in interface org.springframework.test.context.TestExecutionListener
        Overrides:
        afterTestMethod in class org.springframework.test.context.support.AbstractTestExecutionListener
      • getOrder

        public int getOrder()
        Returns 10000.
        Specified by:
        getOrder in interface org.springframework.core.Ordered
        Overrides:
        getOrder in class org.springframework.test.context.support.AbstractTestExecutionListener