且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

春季:等效于安全性:身份验证管理器和安全性:全局方法安全性的注释

更新时间:2023-11-30 22:53:58

编辑:2013年12月已实现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):

当前没有简单的方法来进行Spring Security配置 Java配置.您必须知道名称空间的作用 场景使工作变得困难且容易出错.因此,我 建议坚持使用Spring Security命名空间 配置.

There currently is no easy way to do Spring Security configuration with Java configuration. You must know what the namespace does behind the scenes making it difficult and error prone. For this reason, I would recommend sticking with the Spring Security namespace configuration.

一种选择是参与非官方项目- 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 :(