Spring Security 5.1.0.M2 发布,Spring 安全框架

栏目: 软件资讯 · 发布时间: 7年前

内容简介:Spring Security 5.1.0.M2 已发布,该版本关闭了超过 100 个 issue。下面说说值得关注的更新: OAuth2 OAuth2 Resource Server 添加了对 OAuth2 资源服务器的基本支持。见 oauth2resourceserver Authorization ...

Spring Security 5.1.0.M2 已发布,该版本关闭了超过 100 个 issue。下面说说值得关注的更新:

OAuth2

OAuth2 Resource Server

添加了对 OAuth2 资源服务器的基本支持。见 oauth2resourceserver

Authorization Code Flow

用户现在可以使用OAuth 2.0 Authorization Code grant 获取访问令牌(access token)。请查看 authcodegrant 示例。

支持 WebClient 和 OAuth2

现在内置了对 OAuth2 和 WebClient 的支持,该支持将允许:

  • 将访问令牌添加到请求中

  • 访问令牌过期时自动刷新

  • 解析要使用的访问令牌

例如,在 servlet 环境中,你可以配置一个如下所示的 Bean:

@Bean
WebClient webClient(OAuth2AuthorizedClientRepository repository) {
    ServletOAuth2AuthorizedClientExchangeFilterFunction filter =
        new ServletOAuth2AuthorizedClientExchangeFilterFunction(repository);
    return WebClient.builder()
        .filter(new OAuth2AuthorizedClientExchangeFilterFunction())
        .apply(filter.oauth2Configuration())
        .build();
 }

现在,你可以通过多种不同方式添加 OAuth 令牌。如果需要,可以使用 Spring MVC 支持来解析 OAuth2AuthorizedClient。如果授权服务器返回已刷新的令牌并且访问令牌即将过期,则 Spring Security 将透明地更新访问令牌并提交已更新的访问令牌。

@GetMapping("/users")
Mono<String> users(@RegisteredOAuth2AuthorizedClient("client-id")
        OAuth2AuthorizedClient authorizedClient) {
    return this.webClient.get()
        .uri("https://api.example.com/user")
        .attributes(oauth2AuthorizedClient(authorizedClient))
        .retrieve()
        .bodyToMono(String.class);
}

你可以通过 WebClient 来解析访问令牌,例如

Mono<String> users() {
    return this.webClient.get()
        .uri("https://api.example.com/user")
        .attributes(clientRegistrationId("client-id"))
        .retrieve()
        .bodyToMono(String.class);
}

如果使用 OAuth2 Log In 或 OIDC 进行身份验证,则可以应用默认的访问令牌而无需用户交互。

Mono<String> users() {
    // if Authenticated with OIDC
    // OAuth2 Log In use the access token associated to log in
    return this.webClient.get()
        .uri("https://api.example.com/user")
        .retrieve()
        .bodyToMono(String.class);
}

WebFlux OAuth2 Log In Supports OIDC

WebFlux 应用程序现在可以使用 OAuth2 和 OIDC 进行身份验证。有关详细示例,请查看 oauth2login-webflux

配置改进

改进默认登录页面,更现代化

默认登录页面实用了 HTML5,变得更现代化,看起来更具视觉吸引力。

默认注销页面

由于添加了 CSRF 注销保护,因此默认应用程序无法注销。现在,如果正在使用默认登录页面(例如没有配置登录页面),那么还会有一个默认的注销页面,它显示了一个注销表单。

简化 RequestCache 配置

用户现在可以配置默认的 RequestCache,用于将其暴露给@Bean。

本次更新内容较多,详情请查看发布说明
源码下载 >>> https://github.com/spring-projects/spring-security/releases/tag/5.1.0.M2


【声明】文章转载自:开源中国社区 [http://www.oschina.net]


以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

Learn Python the Hard Way

Learn Python the Hard Way

Zed A. Shaw / Addison-Wesley Professional / 2013-10-11 / USD 39.99

Master Python and become a programmer-even if you never thought you could! This breakthrough book and CD can help practically anyone get started in programming. It's called "The Hard Way," but it's re......一起来看看 《Learn Python the Hard Way》 这本书的介绍吧!

HTML 压缩/解压工具
HTML 压缩/解压工具

在线压缩/解压 HTML 代码

在线进制转换器
在线进制转换器

各进制数互转换器

Markdown 在线编辑器
Markdown 在线编辑器

Markdown 在线编辑器