|
此版本仍在开发中,尚未被视为稳定版本。对于最新的稳定版本,请使用 Spring Security 6.3.3! |
|
此版本仍在开发中,尚未被视为稳定版本。对于最新的稳定版本,请使用 Spring Security 6.3.3! |
Spring Security 6.4 提供了许多新功能。 以下是该版本的亮点,或者您可以查看发行说明,了解每项功能和错误修复的详细列表。
方法安全性
-
所有方法安全注解现在都支持 Framework 的
@AliasFor -
@AuthenticationPrincipal现在支持注释模板。@CurrentSecurityContext这意味着您现在可以像这样使用 Spring 的元注释支持:
-
Java
-
Kotlin
@Target(TargetType.TYPE) @Retention(RetentionPolicy.RUNTIME) @AuthenticationPrincipal("claims['{claim}']") @interface CurrentUsername { String claim() default "sub"; } // ... @GetMapping public String method(@CurrentUsername("username") String username) { // ... }annotation CurrentUsername(val claim: String = "sub") // ... @GetMapping fun method(@CurrentUsername("username") val username: String): String { // ... } -
-
进行了多项改进,以使 Security 的注释搜索与 的算法保持一致。 这有助于从早期版本的 Spring Security 迁移。
AbstractFallbackMethodSecurityMetadataSource
OAuth 2.0 版本
-
oauth2Login()现在接受OAuth2AuthorizationRequestResolver作为@Bean -
添加到 reactive 中的 DSL 中
loginPage()oauth2Login() -
OIDC 反向通道支持现在接受
logout+jwt类型的注销令牌 -
RestClient现在可以配置为发出受保护的资源请求OAuth2ClientHttpRequestInterceptor -
添加了 的基于 的实现,以便对访问令牌请求进行更一致的配置。
RestClientOAuth2AccessTokenResponseClient要选择使用支持,只需为每个授权类型发布一个 bean,如下例所示:
RestClient-
Java
-
Kotlin
@Configuration public class SecurityConfig { @Bean public OAuth2AccessTokenResponseClient<OAuth2AuthorizationCodeGrantRequest> authorizationCodeAccessTokenResponseClient() { return new RestClientAuthorizationCodeTokenResponseClient(); } @Bean public OAuth2AccessTokenResponseClient<OAuth2RefreshTokenGrantRequest> refreshTokenAccessTokenResponseClient() { return new RestClientRefreshTokenTokenResponseClient(); } @Bean public OAuth2AccessTokenResponseClient<OAuth2ClientCredentialsGrantRequest> clientCredentialsAccessTokenResponseClient() { return new RestClientClientCredentialsTokenResponseClient(); } @Bean public OAuth2AccessTokenResponseClient<JwtBearerGrantRequest> jwtBearerAccessTokenResponseClient() { return new RestClientJwtBearerTokenResponseClient(); } @Bean public OAuth2AccessTokenResponseClient<TokenExchangeGrantRequest> tokenExchangeAccessTokenResponseClient() { return new RestClientTokenExchangeTokenResponseClient(); } }@Configuration class SecurityConfig { @Bean fun authorizationCodeAccessTokenResponseClient(): OAuth2AccessTokenResponseClient<OAuth2AuthorizationCodeGrantRequest> { return RestClientAuthorizationCodeTokenResponseClient() } @Bean fun refreshTokenAccessTokenResponseClient(): OAuth2AccessTokenResponseClient<OAuth2RefreshTokenGrantRequest> { return RestClientRefreshTokenTokenResponseClient() } @Bean fun clientCredentialsAccessTokenResponseClient(): OAuth2AccessTokenResponseClient<OAuth2ClientCredentialsGrantRequest> { return RestClientClientCredentialsTokenResponseClient() } @Bean fun jwtBearerAccessTokenResponseClient(): OAuth2AccessTokenResponseClient<JwtBearerGrantRequest> { return RestClientJwtBearerTokenResponseClient() } @Bean fun tokenExchangeAccessTokenResponseClient(): OAuth2AccessTokenResponseClient<TokenExchangeGrantRequest> { return RestClientTokenExchangeTokenResponseClient() } } -
-
已弃用的 实现
Default*OAuth2AccessTokenResponseClient
SAML 2.0 版本
-
添加了 OpenSAML 5 支持。 现在,您可以使用 OpenSAML 4 或 OpenSAML 5;默认情况下,Spring Security 将根据 Classpath 上的内容选择写入实现。
-
使用 EntityID 可以简化。
registrationId一种常见模式是通过 . 在以前的版本中,这需要直接配置 . 现在,请求解析程序除了在路径中查找 as 请求参数外,还会默认查找 as 请求参数。 这允许您使用或不需要修改值或自定义请求解析程序。
entityIDOpenSamlAuthenticationRequestResolverregistrationIdRelyingPartyRegistrationsOpenSaml4/5AssertingPartyMetadataRepositoryregistrationId与此相关,您现在可以将 your 配置为包含 query 参数
authenticationRequestUri -
现在,可以根据元数据的到期时间在后台刷新断言方。
例如,您现在可以使用
OpenSaml5AssertingPartyMetadataRepository来执行以下操作:-
Java
-
Kotlin
@Component public class RefreshableRelyingPartyRegistrationRepository implements IterableRelyingPartyRegistrationRepository { private final AssertingPartyMetadataRepository assertingParties = OpenSaml5AssertingPartyMetadataRepository .fromTrustedMetadataLocation("https://idp.example.org").build(); @Override public RelyingPartyRegistration findByRegistrationId(String registrationId) { AssertingPartyMetadata assertingParty = this.assertingParties.findByEntityId(registrationId); return RelyingPartyRegistration.withAssertingPartyMetadata(assertingParty) // relying party configurations .build(); } // ... }@Component open class RefreshableRelyingPartyRegistrationRepository: IterableRelyingPartyRegistrationRepository { private val assertingParties: AssertingPartyMetadataRepository = OpenSaml5AssertingPartyMetadataRepository .fromTrustedMetadataLocation("https://idp.example.org").build() override fun findByRegistrationId(String registrationId): RelyingPartyRegistration { val assertingParty = this.assertingParties.findByEntityId(registrationId) return RelyingPartyRegistration.withAssertingPartyMetadata(assertingParty) // relying party configurations .build() } // ... }此实现还支持元数据签名的验证。
-
-
您现在可以对信赖方元数据进行签名
-
RelyingPartyRegistrationRepository现在可以缓存结果。 如果要将注册值的加载推迟到应用程序启动后,这将非常有用。 如果要控制元数据的刷新时间,此功能也很有用。 -
为了与 SAML 2.0 标准保持一致,元数据端点现在使用
application/samlmetadata+xmlMIME 类型
Web
-
CSRF BREACH 令牌现在更加一致
-
现在,“记住我”Cookie 的可自定义性更强
-
安全过滤器链现已得到改进。 具体来说,以下安排是无效的,因为 any request 过滤器链位于所有其他过滤器链之前:
-
Java
-
Kotlin
@Bean @Order(0) SecurityFilterChain api(HttpSecurity http) throws Exception { http .authorizeHttpRequests(...) .httpBasic(...) return http.build(); } @Bean @Order(1) SecurityFilterChain app(HttpSecurity http) throws Exception { http .securityMatcher("/app/**") .authorizeHttpRequests(...) .formLogin(...) return http.build(); }@Bean @Order(0) fun api(val http: HttpSecurity): SecurityFilterChain { http { authorizeHttpRequests { // ... } } return http.build() } @Bean @Order(1) fun app(val http: HttpSecurity): SecurityFilterChain { http { securityMatcher("/app/**") authorizeHttpRequests { // ... } } return http.build() }您可以在 相关票证 中阅读更多内容。
-
一次性令牌登录
Spring Security 现在支持通过 DSL 进行一次性令牌登录。oneTimeTokenLogin()
Kotlin
-
Kotlin DSL 现在支持 SAML 2.0 以及
GrantedAuthorityDefaults和RoleHierarchy@Bean -
@PreFilter现在在 Kotlin 中受支持@PostFilter -
Kotlin 反应式 DSL 现在支持
SecurityContextRepository
阿克尔
-
AclAuthorizationStrategyImpl现在支持RoleHierarchy