问题描述
在XML配置中,我可以使用security
命名空间来启用对安全性的支持,例如:
In XML configuration, I can use security
namespace to enable support for security, such as:
<security:authentication-manager alias="authenticationManager">
<security:authentication-provider ref="authenticator" />
</security:authentication-manager>
<security:global-method-security pre-post-annotations="enabled" />
<bean id="authenticator"
class="org.springframework.security.authentication.TestingAuthenticationProvider" />
我尝试仅使用@Configuration
类使用不带XML的Spring.这种配置与上述XML示例的普通Java等效项是什么?
I try to use Spring without XML, with only @Configuration
classes. What is the plain Java equivalent of such configuration as the XML sample above?
推荐答案
编辑:2013年12月 Spring Security 3.2已发布和已实现Java配置,因此上述XML大致等同于:
EDIT: In December 2013 Spring Security 3.2 was released and Java Configuration was implemented, so above XML is roughly equivalent to:
@Configuration
@EnableGlobalMethodSecurity(prePostEnabled = true)
public class SecurityConfiguration extends WebSecurityConfigurerAdapter {
@Override
protected void configure(final AuthenticationManagerBuilder auth)
throws Exception {
auth.authenticationProvider(authenticator());
super.configure(auth);
}
@Bean
public AuthenticationProvider authenticator() {
return new TestingAuthenticationProvider();
}
}
2012年的旧答案:
不幸的是,没有任何东西. 检查此答案(半年前由Spring Security发布潜在客户开发人员):
Unfortunately, there isn't any. Check this answer (posted half year ago by Spring Security lead dev):
一种选择是参与非官方项目- Scalasec -提供基于Scala的配置并且在 SpringSource博客上的这篇文章中进行了描述一个>.同样,不建议将其用于生产,因为项目似乎已被放弃.我想有一天尝试这个项目,但目前没有空闲时间:(
One option is to contribute to an unofficial project - Scalasec - which provides Scala-based configuration and was described in this post on SpringSource blog. Again, this is not recommended for production since project seems to be abandoned. I want to experiment with this project some day but have no spare time currently :(
这篇关于春季:等效于安全性:身份验证管理器和安全性:全局方法安全性的注释的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!