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

编程入门 行业动态 更新时间:2024-10-24 20:23:04
本文介绍了春季:等效于安全性:身份验证管理器和安全性:全局方法安全性的注释的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

在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):

当前没有简单的方法来进行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 :(

更多推荐

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

本文发布于:2023-10-29 09:49:40,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1539379.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:安全性   管理器   注释   全局   身份验证

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!