跳到主要内容
版本:7.0.2

Spring Security 7.0 的新特性

DeepSeek V3 中英对照 What’s New What’s New in Spring Security 7.0

Spring Security 7.0 提供了多项新功能。以下是该版本的主要亮点,您也可以查看发布说明以获取每个功能和错误修复的详细列表。

移除操作

作为一次重大版本更新,Spring Security 7 移除了大量已弃用的 API。以下各部分将重点说明各模块中较为显著的移除项以及新增功能。

模块

核心

配置

  • ServletsWebFlux 中支持模块化配置

  • HttpSecurity DSL 中移除了 and(),转而使用 lambda 方法

  • 移除了 authorizeRequests,改用 authorizeHttpRequests

  • 简化了 authorizeRequests 的表达式迁移

  • 新增了对基于 SPA 的 CSRF 配置的支持

  • 新增了对将缺失的权限绑定到认证机制的支持。

    Java

    http.csrf((csrf) -> csrf.spa());

加密

  • 新增基于 Password4j 的密码编码器,为常用哈希算法提供替代实现:

    • Argon2Password4jPasswordEncoder - Argon2

    • BcryptPassword4jPasswordEncoder - BCrypt

    • ScryptPassword4jPasswordEncoder - SCrypt

    • Pbkdf2Password4jPasswordEncoder - PBKDF2

    • BalloonHashingPassword4jPasswordEncoder - Balloon Hashing

数据

  • 新增对Spring Data类型的Authorized对象支持

LDAP

  • 移除了 ApacheDsContainer 及相关 Apache DS 支持,转而采用 UnboundID

OAuth 2.0

  • 移除了对密码授权(password grant)的支持

  • HTTP 服务客户端 添加了 OAuth2 支持

  • NimbusJwtDecoder 中添加了对自定义 JwkSource 的支持,允许使用 Nimbus 的 JwkSourceBuilder API

  • NimbusJwtEncoder 添加了构建器,支持指定 EC 或 RSA 密钥对或密钥

  • 类型级别 添加了对 @ClientRegistrationId 的支持,消除了在方法级别重复声明的需要

  • 添加了对 OAuth 2.0 动态注册协议 的支持

  • 在 OAuth 2.0 授权服务器中 默认启用了 PKCE

SAML 2.0

  • 移除了基于 AssertingPartyDetails 类的 API 方法,转而支持 AssertingPartyMetadata 接口

  • 移除了 Saml2AuthenticationTokenConverter 中的 GET 请求支持

  • 新增了基于 JDBC 的 AssertingPartyMetadataRepository

  • 调整了 SLO 逻辑,使其在验证失败时仍返回 <saml2:LogoutResponse>

  • 移除了对 Open SAML 4 的支持;应用应迁移至 Open SAML 5

测试

Web

  • 移除了 MvcRequestMatcherAntPathRequestMatcher,改用 PathPatternRequestMatcher

  • 新增了 SubjectX500PrincipalExtractor

  • 新增了对通过 Spring MVC 控制器传播 Authorized 代理中异常的支持

  • 新增了对 Spring MVC 类型的 Authorized 对象的支持

  • 新增了对默认登录页面的支持,以根据 factor.typefactor.reason 参数显示因素

  • 将 LoginUrlAuthenticationEntryPoint 默认改为优先使用相对重定向