测试时禁用Spring安全性
我有一个用JSF、Spring事务和IoC编写的应用程序。由于我使用ACL,应用程序使用Spring安全保护非常复杂。通过应用程序的流量为: JSF管理Bean->服务类->DAO类->数据库,反之亦然 被测试方法实现的接口如下所示:测试时禁用Spring安全性,spring,spring-security,Spring,Spring Security,我有一个用JSF、Spring事务和IoC编写的应用程序。由于我使用ACL,应用程序使用Spring安全保护非常复杂。通过应用程序的流量为: JSF管理Bean->服务类->DAO类->数据库,反之亦然 被测试方法实现的接口如下所示: public interface MyService extends GenericService { @PreAuthorize("hasPermission(#oId,'com.mycompany.core.entity.MyObject','rea
public interface MyService extends GenericService {
@PreAuthorize("hasPermission(#oId,'com.mycompany.core.entity.MyObject','read')")
public abstract MyObject getMyObject(Long oId);
}
指定方法的试验:
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration({ "classpath:/applicationContext.xml","classpath: /applicationContext-test.xml" })
@TransactionConfiguration(transactionManager = "transactionManager", defaultRollback = true)
@Transactional(propagation = Propagation.REQUIRED)
public class MyServiceImplIntegrationTest {
@Inject
private MyService myService;
@Test
public void testGetMyObject(){
myService.getMyObject();
}
}
可以看出,我使用两个xml文件来配置spring,一个用于测试,另一个用于非测试。
我的问题是,对于整个测试类,我希望消除真实方法上的spring安全性注释。
我的第一个任务是覆盖元素,该元素现在如下所示:
<security:global-method-security pre-post-annotations="enabled">
<security:expression-handler ref="methodExpressionHandler" />
</security:global-method-security>
与
但是这个元素似乎不能在其他文件中被覆盖。
有没有其他想法可以让我达到同样的效果
PS.组件版本为:
<org.springframework.version>4.0.7.RELEASE</org.springframework.version>
<org.springframework.security.version>3.2.4.RELEASE</org.springframework.security.version>
在应用程序配置服务等中拆分配置。安全配置和测试不加载安全部分。我的配置已经拆分,但我不能完全跳过安全部分,因为它在其他文件中引用。对于一些测试,我还想运行安全性:然后在这些测试中加载额外的文件。引用什么?存在@PreAuthorize并不意味着配置必须存在。这只是元数据。是的,我知道,但我还有其他依赖于安全性bean的bean,即用于创建AC条目的AclServiceHelper依赖于org.springframework.security.acls.model.MutableAclService。。等等
<org.springframework.version>4.0.7.RELEASE</org.springframework.version>
<org.springframework.security.version>3.2.4.RELEASE</org.springframework.security.version>