领先一步
VMware 提供培训和认证,助您加速进步。
了解更多我代表社区高兴地宣布 Spring Security 5.1.0.RC1 发布。此版本解决了 50+ 个问题。
一如既往,我们期待听到您的反馈!您可以在下面找到亮点:
资源服务器现在可以通过任何支持 Open Id Provider Configuration 的颁发者端点进行配置。
@Bean
JwtDecoder jwtDecoder() {
return JwtDecoders.createDefaultFromIssuer("https://issuer-endpoint");
}
用户可以通过暴露一个 JwtDecoder
bean 来添加自己的验证规则,应用于 Jwt
。
@Bean
JwtDecoder jwtDecoder() {
String jwkSetUri = "https://issuer-endpoint/.well-known/jwks.json";
NimbusJwtDecoderJwkSupport jwtDecoder =
new NimbusJwkDecoderJwkSupport(jwkSetUri);
OAuth2TokenValidator<Jwt> validator =
new DelegatingOAuth2TokenValidator(
JwtValidators.createDefault(),
new MyCustomValidator());
jwtDecoder.setJwtValidator(validator);
return jwtDecoder;
}
用户可以自定义如何从 Jwt
中提取 GrantedAuthority
。
@Bean
JwtDecoder jwtDecoder() {
String jwkSetUri = "https://issuer-endpoint/.well-known/jwks.json";
NimbusJwtDecoderJwkSupport jwtDecoder =
new NimbusJwkDecoderJwkSupport(jwkSetUri);
JwtAuthenticationConverter jwtAuthenticationConverter =
new JwtAuthenticationConverter() {
protected Collection<GrantedAuthority> extractAuthorities(Jwt jwt) {
return Arrays.asList(new SimpleGrantedAuthority("app:read"));
}
};
jwtDecoder.setJwtAuthenticationConverter(jwtAuthenticationConverter);
return jwtDecoder;
}
已添加对 Client Credentials Grant Type 的基本支持。
已添加对 Feature-Policy 的基本支持。
http
.headers()
.featurePolicy("geolocation 'none'");
已添加对基于响应式的 OAuth2 资源服务器的基本支持。请参阅 oauth2resourceserver-webflux
已添加对基于响应式的授权码授权流程的基本支持。请参阅 authcodegrant-webflux
已添加对自定义发送给授权服务器的认证请求的支持。这在授权服务器需要发送自定义参数时非常方便。在多租户场景下,请求中的主机名等元素可能会改变发送到授权服务器的请求方式,这时它也很有用。
已添加对自定义已授权客户端在请求之间的持久化存储的支持。
http
.oauth2()
.client()
.authorizedClientRepository(new MyCookieBasedClientRepository());
WebFlux 已添加对以下安全头的支持:
Content-Security-Policy
Referrer-Policy
Feature-Policy
Webflux 已添加对 CORS 的支持。
我们已经更新了依赖,以确保我们的传递性依赖是最新的。