參考文件:
Spring OAuth 2 Developers Guide
如果你有很多系統但想用同一個方式登入,存取資源的話,建立 OAuth2 Server是一個好方法,可以參考 spring-security-oauth的方式來建立。 但目前很多範例是用 Spring Boot來建立,我參考的 Secure Spring REST With Spring Security and OAuth2 (github source code) 就是。
幾個點跟大家分享:
儲存 token, user帳號、宓碼會有三種方式
1.InMemory的方式,也是預設的方式
2.把資訊記錄在資料庫內,使用 jdbc data store,參考的範例內有 H2和 Postgresql,其它分享有用 MySQL的方式,如果是用 H2的話,一開始應該會放在本機,如果要用 remote模式要參考 Allow remote access to H2 Database設定,宓碼變更請參考 set password
3.jwt方式,spring security 5.1開始就只支援這種方式
文章有提到會建立 Authorization Server, Resource Server,實際上是建立相關的 configuration class設定的動作,基本上有三個,也可以只寫一個 class extends 三個類別
2019年1月29日 星期二
2019年1月28日 星期一
Spring Boot
Spring Boot出來很久了,但因為工作上沒有使用到,所以一直沒有學習,最近又想了解 OAuth2才知道它的存在,短暫的學習心得,發現它跟 .Net Core有類似,用大量 annotation, dependency injection,還有以前的 xml設定檔,現在都用 class替代了,有興趣的人可以參考如下網站
Spring Boot 基础
Adding Classpath Dependencies
Building microservices with Netflix OSS, Apache Kafka and Spring Boot – Part 1: Service registry and Config server
Deploy a Spring Boot MicroService with Netflix OSS stack in Docker Container
Spring Boot 基础
Adding Classpath Dependencies
Building microservices with Netflix OSS, Apache Kafka and Spring Boot – Part 1: Service registry and Config server
Deploy a Spring Boot MicroService with Netflix OSS stack in Docker Container
訂閱:
文章 (Atom)