在 XML 配置中,我可以使用security
命名空间以启用安全支持,例如:
<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" />
我尝试使用 Spring 而不使用 XML,只使用@Configuration
类。与上面的 XML 示例这样的配置的普通 Java 等效项是什么?
EDIT: 2013 年 12 月Spring Security 3.2 发布 https://spring.io/blog/2013/12/16/spring-security-3-2-0-release-released and Java配置已实现 http://docs.spring.io/spring-security/site/docs/3.2.x/reference/htmlsingle/#jc,所以上面的 XML 大致相当于:
@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年的旧答案:
不幸的是,没有。检查这个答案 https://stackoverflow.com/a/8852347/708434(Spring Security 半年前发布lead dev https://jira.springsource.org/secure/ViewProfile.jspa?name=rwinch):
目前没有简单的方法来进行 Spring Security 配置
与Java配置。你必须知道命名空间背后是做什么的
这些场景使其变得困难且容易出错。为此,我
建议坚持使用 Spring Security 命名空间
配置。
一种选择是为非官方项目做出贡献 -Scalasec https://github.com/tekul/scalasec/- 提供基于 Scala 的配置,并在SpringSource 博客上的这篇文章 http://blog.springsource.org/2011/08/01/spring-security-configuration-with-scala/。同样,不建议将其用于生产,因为项目似乎已被放弃。我想有一天尝试这个项目,但目前没有空闲时间:(
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)