SEC-2700: Register WithSecurityContextTestExecutionListener by default

This commit is contained in:
Rob Winch
2014-08-14 15:55:37 -05:00
parent 1eaa621619
commit 3187ee8bf3
65 changed files with 233 additions and 287 deletions

View File

@@ -1,42 +0,0 @@
/*
* Copyright 2002-2014 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.security.test.context;
import org.springframework.security.test.context.support.WithSecurityContextTestExecutionListener;
import org.springframework.test.context.TestExecutionListeners;
import org.springframework.test.context.support.DependencyInjectionTestExecutionListener;
import org.springframework.test.context.support.DirtiesContextTestExecutionListener;
import org.springframework.test.context.transaction.TransactionalTestExecutionListener;
import org.springframework.test.context.web.ServletTestExecutionListener;
import java.lang.annotation.*;
/**
* A meta annotation that adds WithSecurityContextTestExcecutionListener to the default Spring TestExecutionListeners.
*
* @author Rob Winch
* @since 4.0
*/
@Documented
@Inherited
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
@TestExecutionListeners(listeners={ServletTestExecutionListener.class,
DependencyInjectionTestExecutionListener.class,
DirtiesContextTestExecutionListener.class,
TransactionalTestExecutionListener.class,
WithSecurityContextTestExecutionListener.class})
public @interface DefaultSecurityTestExecutionListeners {}

View File

@@ -19,6 +19,7 @@ import java.lang.annotation.Annotation;
import org.springframework.context.ApplicationContext;
import org.springframework.core.annotation.AnnotationUtils;
import org.springframework.core.annotation.Order;
import org.springframework.security.core.context.SecurityContext;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.test.context.TestSecurityContextHolder;
@@ -26,6 +27,7 @@ import org.springframework.security.test.web.servlet.request.SecurityMockMvcRequ
import org.springframework.test.context.TestContext;
import org.springframework.test.context.TestExecutionListener;
import org.springframework.test.context.support.AbstractTestExecutionListener;
import org.springframework.test.context.support.DependencyInjectionTestExecutionListener;
import org.springframework.test.web.servlet.MockMvc;
/**
@@ -39,9 +41,12 @@ import org.springframework.test.web.servlet.MockMvc;
* @author Rob Winch
* @since 4.0
*/
@Order(WithSecurityContextTestExecutionListener.ORDER)
public class WithSecurityContextTestExecutionListener extends
AbstractTestExecutionListener {
public static final int ORDER = 1000;
/**
* Sets up the {@link SecurityContext} for each test method. First the
* specific method is inspected for a {@link WithSecurityContext} or {@link Annotation}

View File

@@ -0,0 +1 @@
org.springframework.test.context.TestExecutionListener = org.springframework.security.test.context.support.WithSecurityContextTestExecutionListener