当前位置: 首页 > news >正文

Spring Security 的 Java Config Preview(Java 配置预览)是 Spring Security 3.2 引入的重要特性

Spring Security 的 Java Config Preview(Java 配置预览)是 Spring Security 3.2 引入的重要特性,标志着从传统的 XML 配置向纯 Java 类配置(基于@Configuration@EnableWebSecurity)的全面过渡。它通过注解驱动的方式简化安全配置,提升类型安全性、IDE 支持和可测试性。

核心组件包括:

  • @EnableWebSecurity:启用 Spring Security Web 安全支持;
  • WebSecurityConfigurerAdapter(已自 Spring Security 5.7 起弃用,推荐直接实现SecurityFilterChainBean);
  • SecurityFilterChain(现代方式):通过@Bean定义过滤器链,明确配置 HTTP 安全规则(如authorizeHttpRequests()formLogin()csrf()等);
  • UserDetailsServicePasswordEncoder等策略接口的灵活定制。

示例(Spring Security 6+ 推荐写法):

@Configuration@EnableMethodSecuritypublicclassSecurityConfig{@BeanpublicSecurityFilterChainfilterChain(HttpSecurityhttp)throwsException{http.authorizeHttpRequests(authz->authz.requestMatchers("/public/**").permitAll().requestMatchers("/admin/**").hasRole("ADMIN").anyRequest().authenticated()).formLogin(withDefaults()).logout(withDefaults());returnhttp.build();}@BeanpublicPasswordEncoderpasswordEncoder(){returnnewBCryptPasswordEncoder();}}

该预览版为后续 Spring Security 4.0+ 的零 XML、函数式 DSL 配置奠定了基础,显著提升了开发体验与配置可维护性。
Spring Security Java Config Preview: Introduction

Yesterday I announced the release of Spring Security Java Configuration support and the release of Spring Security 3.2.0.M2 which contains Java Configuration support.

Spring Security’s Java Configuration support is intended to provide a complete replacement of the XML namespace configuration. It is also designed to be extensible, so that Spring Security’s extension projects can work nicely with the Java Configuration support.

In this first post of a five part Spring Security Java Configuration blog series, I discuss the logistics of the Spring Security Java Configuration project.

“Required Versions”
Regardless of how you decide to integrate with Spring Security, it is important to ensure you are using Spring 3.2.3.RELEASE+ to ensure that you avoid SPR-10546.

Availability

Before we get started, I’d like to talk about the two modules that Spring Security’s Java Configuration can be found.
Availability in Spring Security 3.2.0.M2+

Spring Security Java Configuration has been copied into the Spring Security 3.2.0.M2+ code base. This means if you are using Spring Security 3.2.0.M2+ you should ensure to have the spring-security-config jar on your classpath. For example, you might have the following entries in your Maven pom.xml:

org.springframework.security spring-security-config 3.2.0.M2 … repository.springsource.milestone SpringSource Milestone Repository http://repo.springsource.org/milestone

“Future Availability”
Currently there are no plans to provide any updates to spring-security-javaconfig. Instead, users will be encouraged to update to Spring Security 3.2 when it is released.

Availability for Spring Security 3.1.4.RELEASE+

In order to encourage users to try Spring Security Java Configuration, it is also available as a standalone module called spring-security-javaconfig. For example, you might have the following entries in your Maven pom.xml:

org.springframework.security spring-security-javaconfig 1.0.0.M1 … repository.springsource.milestone SpringSource Milestone Repository http://repo.springsource.org/milestone

SpringOne2GX 2013
Want to learn more about Spring Security 3.2 release? Register for SpringOne2GX 2013, September 9-12 in Santa Clara, California where I will be discussing Spring Security 3.2 in more detail! There conference will have tons of great sessions to quickly catch you up with everything that is happening in the Spring, Groovy, and Grails communities! Don’t forget to register by Aug 9th to save Want to learn more about Spring Security 3.2 release? Register for SpringOne2GX 2013, September 9-12 in Santa Clara, California where I will be discussing Spring Security 3.2 in more detail! There conference will have tons of great sessions to quickly catch you up with everything that is happening in the Spring, Groovy, and Grails communities! Don’t forget to register by Aug 9th to save $200 with the Early discount!
00 with the Early discount!

Feedback Please

If you encounter a bug, have an idea for improvement, etc please do not hesitate to bring it up! We want to hear your thoughts so we can ensure we get it right before the code is generally available. Trying out new features early is a good and simple way to give back to the community. This also ensures that the features you want are present and working as you think they should.

Please log any issues or feature requests to the Spring Security JIRA under the category “Java Config”. After logging a JIRA, we encourage (but do not require) you to submit your changes in a pull request. You can read more about how to do this in the Contributor Guidelines

If you have questions on how to do something, please use the Spring Security forums or Stack Overflow with the tag spring-security (I will be monitoring them closely). If you have specific comments questions about this blog, feel free to leave a comment. Using the appropriate tools will help make it easier for everyone.
Conclusion

You should now have a clear idea of why Spring Security Java Configuration exists it multiple places, where you will find updates, and where to log issues to. In the next post, we will walk through using Spring Security Java configuration in a web application.
comments powered by Disqus

http://www.cnnetsun.cn/news/1993788.html

相关文章:

  • 告别网盘限速困扰:8大平台直链下载助手完整指南
  • Spring Data Redis 1.1 M1(里程碑版本)和 1.0.5(维护版本)是 Spring Data 项目在 Redis 数据访问支持方面的两个历史发布版本
  • Python实战:5分钟搞定京东云短信API的发送、状态查询与回复处理
  • 2026届必备的五大降AI率网站推荐榜单
  • 齿轮箱零部件及其装配质检中的TVA技术突破(8)
  • 拆个旧硬盘,用三个MOS管做个无刷电机驱动电路,结果翻车了?
  • Spring Boot 4.0 Agent就绪开发全链路:从JVM Agent注入、Instrumentation到动态热修复(含3大企业级落地模板)
  • 如何免费将PPTX转换为互动网页?5步完成PPTX转HTML转换
  • 终极Windows 11右键菜单自定义指南:释放你的文件管理潜能
  • FileRun vs NextCloud 实战对比:哪个才是更适合你的自建网盘?(基于Docker和群晖环境)
  • 从旋转木马到无人机:图解牛顿-欧拉方程中的科氏力与惯性力
  • AsrTools终极指南:如何快速将音频视频批量转换为精准文字字幕
  • 上海交通大学LaTeX论文模板终极指南:快速掌握学术排版核心技巧
  • Agent就绪≠真正就绪!Spring Boot 4.0上线前必须验证的7项Agent兼容性指标,92%团队忽略第5项
  • 别再乱装CUDA了!Win11+3050 Ti显卡驱动与CUDA 11.3版本匹配的终极指南
  • 实测对比:Windows下用官方安装器 vs pyenv-win管理Python,哪个更适合你?
  • 保姆级教程:用Python和DepthAI库,5分钟搞定OAK-D双摄像头数据采集与显示
  • LX Music桌面版终极指南:免费开源的多平台音乐聚合播放器
  • 从北邮网安复试笔记看考研面试:如何用一个月时间系统梳理计算机核心八股文?
  • 掌握ReactPage中的CSS变量:轻松实现主题定制与样式动态调整
  • OBS Advanced Timer:6种专业计时模式完整指南,让直播时间管理更简单
  • 魔兽争霸3终极优化指南:5分钟解决卡顿、拉伸与兼容性问题
  • Souper性能优化技巧:7个关键配置提升优化效率
  • 游戏开发者必看:TGA文件在OpenGL/Unity/Unreal引擎中的正确打开与使用姿势
  • 大气层破解系统深度优化指南:终极性能调优与稳定运行方案
  • DeepSeek-R1-Distill-Qwen-1.5B省钱实战:低配GPU运行方案
  • WinCC画面图层还能这么玩?打造动态工艺看板的隐藏技巧
  • DHT11数据老跳变?STM32F1读取避坑指南,从时序分析到代码稳定化实战
  • 手把手教你用Docker+CloudDrive2在Ubuntu上挂载115网盘,打造私人流媒体库
  • 别再死记硬背了!用知识图谱思维重新梳理你的嵌入式学习路线(附STM32/Linux实战案例)