日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 前端技术 > javascript >内容正文

javascript

使用OAuth 2 / OpenID Connect的SSO的Spring Boot 2本机方法

發布時間:2023/12/3 javascript 36 豆豆
生活随笔 收集整理的這篇文章主要介紹了 使用OAuth 2 / OpenID Connect的SSO的Spring Boot 2本机方法 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

這篇文章是3篇系列文章的最后一部分,該系列文章探討了如何為基于Spring Boot 2的應用程序啟用OAuth2提供程序SSO。 3個帖子是:

  • 引導兼容OpenID Connect的OAuth2授權服務器/ OpenID提供程序的方法
  • 與OAuth2授權服務器/ OpenID提供程序集成的舊版Spring Boot / Spring 5方法
  • 與OAuth2授權服務器/ OpenID Connect提供商集成的更新的Spring Boot 2 / Spring 5方法–這篇文章
  • 這篇文章將探討使用Spring Security中的本機OAuth2支持為Spring Boot 2應用程序啟用SSO的嶄新方法。

    該文章再次假定第一篇文章中描述的所有內容均已完成。

    Spring Boot 2自動配置

    Spring Boot 2為Spring Security中的本機OAuth2支持提供了自動配置(請參見org.springframework.boot.autoconfigure.security.oauth2.client.OAuth2ClientAutoConfiguration類)。

    通過以下gradle坐標可用的“ spring-security-oauth2-client”庫激活了自動配置:

    compile "org.springframework.security:spring-security-oauth2-client"

    此自動配置會處理一組屬性,對于已啟動的UAA身份提供程序,該組屬性如下:

    uaa-base-url: http://localhost:8080/uaaspring:security:oauth2:client:registration:uaa:client-id: client1client-secret: client1authorizationGrantType: authorization_coderedirect_uri_template: "{baseUrl}/login/oauth2/code/{registrationId}"scope: resource.read,resource.write,openid,profileclientName: oauth2-sample-clientprovider:uaa:token-uri: ${uaa-base-url}/oauth/tokenauthorization-uri: ${uaa-base-url}/oauth/authorizeuser-info-uri: ${uaa-base-url}/userinfojwk-set-uri: ${uaa-base-url}/token_keysuserNameAttribute: user_name

    如果要依靠Spring Boot 2自動配置支持來實現對本機OAuth2的支持,并實現應用程序的啟動,那么在訪問應用程序時將看到以下頁面:

    請注意,此登錄頁面是由Spring Security OAuth2創建的默認頁面,默認情況下會顯示注冊列表。

    單擊“ oauth2-sample-client”,將顯示身份提供者(在這種情況下,UAA)的登錄頁面:

    對于基于OpenID Connect的流程,應用程序將獲得ID令牌以及我正在解碼并呈現在頁面上的Access令牌:

    客制化

    我要進行的快速自定義之一是在訪問通過“ / secured” uri模式指定的任何受保護頁面時重定向到UAA,以下是一組應啟用此配置的配置:

    package sample.oauth2.configimport org.springframework.context.annotation.Configuration import org.springframework.security.config.annotation.web.builders.HttpSecurity import org.springframework.security.config.annotation.web.builders.WebSecurity import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter@Configuration class OAuth2SecurityConfig : WebSecurityConfigurerAdapter() {override fun configure(web: WebSecurity) {super.configure(web)web.ignoring().mvcMatchers("/favicon.ico","/webjars/**","/css/**")}override fun configure(http: HttpSecurity) {http.csrf().disable()http.authorizeRequests().antMatchers("/secured/**").authenticated().antMatchers("/", "/custom_login").permitAll().anyRequest().authenticated().and().oauth2Login().loginPage("/custom_login")} }

    請參閱上面設置為“ / custom_login”的URI,依次將控制權簡單地移交給OAuth2控制的端點,這些端點知道設置適當的參數并重定向到UAA:

    @Controller class LoginController {@RequestMapping("/custom_login")fun loginPage(): String {return "redirect:/oauth2/authorization/uaa"} }

    到此結束對Spring Boo2應用程序中對本機OAuth2支持的探索。

    所有示例都可以在我的github存儲庫中找到 – https://github.com/bijukunjummen/oauth2-boot2

    以下參考資料有助于理解OAuth2支持:

    1. Spring安全性文檔 – https://docs.spring.io/spring-security/site/docs/current/reference/html/

    2. Joe Grandja的 Spring One Platform 2017演示文稿 – https://www.youtube.com/watch?v=WhrOCurxFWU

    翻譯自: https://www.javacodegeeks.com/2018/03/spring-boot-2-native-approach-sso-oauth-2-openid-connect.html

    總結

    以上是生活随笔為你收集整理的使用OAuth 2 / OpenID Connect的SSO的Spring Boot 2本机方法的全部內容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。