This document summarizes a microservices meetup hosted by @mosa_siru. Key points include:
1. @mosa_siru is an engineer at DeNA and CTO of Gunosy.
2. The meetup covered Gunosy's architecture with over 45 GitHub repositories, 30 stacks, 10 Go APIs, and 10 Python batch processes using AWS services like Kinesis, Lambda, SQS and API Gateway.
3. Challenges discussed were managing 30 microservices, ensuring API latency below 50ms across availability zones, and handling 10 requests per second with nginx load balancing across 20 servers.
The document discusses implementing an event-driven architecture using events instead of synchronous APIs. It explains that events decouple services by allowing them to communicate asynchronously through a centralized event routing system. This loose coupling makes services more independent and resilient, as failures in downstream services do not block upstream ones. It also improves scalability and maintainability by reducing dependencies between services. The document provides examples to illustrate how an event-driven system has less coupling between producers and consumers compared to a synchronous API approach.
The document discusses graph databases and their properties. Graph databases are structured to store graph-based data by using nodes and edges to represent entities and their relationships. They are well-suited for applications with complex relationships between entities that can be modeled as graphs, such as social networks. Key graph database technologies mentioned include Neo4j, OrientDB, and TinkerPop which provides graph traversal capabilities.
This document summarizes a microservices meetup hosted by @mosa_siru. Key points include:
1. @mosa_siru is an engineer at DeNA and CTO of Gunosy.
2. The meetup covered Gunosy's architecture with over 45 GitHub repositories, 30 stacks, 10 Go APIs, and 10 Python batch processes using AWS services like Kinesis, Lambda, SQS and API Gateway.
3. Challenges discussed were managing 30 microservices, ensuring API latency below 50ms across availability zones, and handling 10 requests per second with nginx load balancing across 20 servers.
The document discusses implementing an event-driven architecture using events instead of synchronous APIs. It explains that events decouple services by allowing them to communicate asynchronously through a centralized event routing system. This loose coupling makes services more independent and resilient, as failures in downstream services do not block upstream ones. It also improves scalability and maintainability by reducing dependencies between services. The document provides examples to illustrate how an event-driven system has less coupling between producers and consumers compared to a synchronous API approach.
The document discusses graph databases and their properties. Graph databases are structured to store graph-based data by using nodes and edges to represent entities and their relationships. They are well-suited for applications with complex relationships between entities that can be modeled as graphs, such as social networks. Key graph database technologies mentioned include Neo4j, OrientDB, and TinkerPop which provides graph traversal capabilities.
1. GraalVM Native Image allows ahead-of-time compilation of Java code to a standalone native executable.
2. The Spring Native Image project adds support for Spring applications by providing handlers that address reflection, proxies, initialization, and resources during native image generation.
3. A demonstration shows building a Spring Boot application into a native image, including the use of Spring Feature to integrate the Spring framework with Native Image.
The document contains code snippets and configuration examples related to Spring Security OAuth 2.0 client integration for authenticating with external OAuth providers like Facebook and XXX. It includes dependency and configuration properties for OAuth client registration and authorization code grant flow. Code snippets show interfaces for CRUD repositories and examples of tailing MongoDB queries with reactive repositories.
1. Copyright?2017 NTT corp. All Rights Reserved.
Spring Security 5.0 解剖速報
2017年11?24?
Spring Fest 2017@KFC Hall & Rooms
岩塚 卓弥,堅? 淳也
NTT ソフトウェアイノベーションセンタ
4. 4Copyright?2017 NTT corp. All Rights Reserved.
Spring Framework 5.0 Released!
https://spring.io/blog/2017/09/28/spring-framework-5-0-goes-ga
5. 5Copyright?2017 NTT corp. All Rights Reserved.
Spring Data “Kay” (2017/10/2)
Spring Security 5.0 (2017/11/27)
Spring Session 2.0 (2017/11/27)
Spring Integration 5.0
Spring Batch 4.0
Spring Boot 2.0
Spring Cloud “Finchley”
Major version up of the Spring Projects
6. 6Copyright?2017 NTT corp. All Rights Reserved.
? WebFlux対応
Spring Securityが提供する各種Security Filter等を
Spring Framework 5.0にて導?されたWeb Fluxに
対応させる
? OAuth 2.0対応
OAuth 2.0/OpenID Connect による認証機能を追加
? 他
? PasswordEncoder周りの改善
What?s new in the Spring Security 5.0
8. 8Copyright?2017 NTT corp. All Rights Reserved.
? Spring Framework 5.0 で追加された仕組み
? リアクティブプログラミングをサポートする新しい
Webフレームワーク
? ?同期 & ノンブロッキングでリクエストを処理
? 少ないスレッドで多くリクエストを処理可能
? → システムリソースの節約
? クライアントの数が多い / 低速な場合に特に有効
? IoT
? Mobile
? Microservices
What is WebFlux?
9. 9Copyright?2017 NTT corp. All Rights Reserved.
Spring MVC vs Spring WebFlux
@Controller, @RequestMapping
spring-webmvc
Servlet API
Servlet Container
spring-webflux
HTTP / Reactive Streams
Tomcat, Jetty, Netty, Undertow
Router Functions
Spring MVC の横に存在
Netty等のServlet以外の環境にも対応
→ spring-webflux は Servlet API に依存しない
10. 10Copyright?2017 NTT corp. All Rights Reserved.
? ControllerのメソッドからReactive Typeを返却
? Mono<T>???0個または1個の値を発?
? Flux<T>???0個以上の値を発?
Controller (WebFlux)
@RestController
public class UserController {
@Autowired
UserRepository userRepository;
@GetMapping("/listAdult")
public Flux<User> listAdult() {
// 20歳以上のユーザを返す
return userRepository.findAll()
.filter(u -> u.getAge() >= 20);
}
}
public interface UserRepository {
Flux<User> findAll();
}
/listAdult の結果
35. 35Copyright?2017 NTT corp. All Rights Reserved.
Review : OAuth 2.0
Resource Owner
(エンドユーザ等)
Client
(サードパーティ製
アプリ等)
Authorization Server
Resource Server
(Webサービス等)
Protected Resource A
Client の権限を限定して Protected Resource に
アクセスさせるための認可フレームワーク
Protected Resource B
Protected Resource C
AとBの
権限を要求
(認可リクエスト)
36. 36Copyright?2017 NTT corp. All Rights Reserved.
Review : OAuth 2.0
Resource Owner
(エンドユーザ等)
Client
(サードパーティ製
アプリ等)
Authorization Server
Resource Server
(Webサービス等)
Protected Resource A
Client の権限を限定して Protected Resource に
アクセスさせるための認可フレームワーク
Protected Resource B
Protected Resource C
許可をとる
Access Token
を渡す*注
*注 Authorization Code Flowにおける
Authorization Codeのやり取りの説明は割愛
37. 37Copyright?2017 NTT corp. All Rights Reserved.
Review : OAuth 2.0
Resource Owner
(エンドユーザ等)
Client
(サードパーティ製
アプリ等)
Authorization Server
Resource Server
(Webサービス等)
Protected Resource A
Client の権限を限定して Protected Resource に
アクセスさせるための認可フレームワーク
Protected Resource B
Protected Resource C
Access Token
を使う
38. 38Copyright?2017 NTT corp. All Rights Reserved.
? Spring Social
? 各種SNSへのアクセスのためにClient機能を独?実装
? Spring Security OAuth
? Authorization Server, Resource Server, Clientの機能を
実装するためのライブラリ
? Spring Boot
? Spring Security OAuthを利?したSSO機能の提供
? Spring Cloud Security
? トークンリレー機能の提供
OAuth 2.0 in Spring
Spring Security 5 で OAuth 2.0 をサポートし,
各プロジェクトはそれを使?する形に書き換えていく
Spring Security OAuth はメンテナンスモードへ(今後の機能追加なし)
39. 39Copyright?2017 NTT corp. All Rights Reserved.
Implementation scope
Resource Owner
(エンドユーザ等)
Client
(サードパーティ製
アプリ等)
Authorization Server
Resource Server
(Webサービス等)
Protected Resource A
Protected Resource B
Protected Resource C
5.0では OAuth 2.0 / OpenID Connectによる
「認証機能(Client)」を実装
5.1で
提供予定
提供時期
不明
5.0で
「認証機能」提供
40. 40Copyright?2017 NTT corp. All Rights Reserved.
Review : OpenID Connect
End-User
Relying Party
(Client)
OpenID Provider
(Authorization Server)
UserInfo Endpoint
OAuth 2.0 を認証に使?するために拡張したプロトコル
認証リクエスト
41. 41Copyright?2017 NTT corp. All Rights Reserved.
Review : OpenID Connect
End-User
Relying Party
(Client)
OpenID Provider
(Authorization Server)
UserInfo Endpoint
OAuth 2.0 を認証に使?するために拡張したプロトコル
認証する
Access Token
と ID Token
を渡す*注
*注 ここでもAuthorization Codeのやり取りの説明は割愛
ID Tokenを
検証する
42. 42Copyright?2017 NTT corp. All Rights Reserved.
Review : OpenID Connect
End-User
Relying Party
(Client)
OpenID Provider
(Authorization Server)
UserInfo Endpoint
OAuth 2.0 を認証に使?するために拡張したプロトコル
Access Token
を使う
ユーザプロフィールを渡す
43. 43Copyright?2017 NTT corp. All Rights Reserved.
OAuth 2.0のサービスプロバイダがOpenID Connectに
?対応の場合
→ Access Tokenで取得したユーザIDで認証する*注
Authentication with OAuth 2.0??
*注 詳細は割愛するが,?般にOAuth 2.0は認証?的のプロトコルではないため
実装によってはなりすまし攻撃等のセキュリティリスクが有ることに注意すること
Spring Security 5.0では両?をサポート
インタフェースは共通でそれぞれに実装を?意
44. 44Copyright?2017 NTT corp. All Rights Reserved.
Overview of OIDC with Spring Security
Client情報
Endpoint情報
Spring Security
認証機構
End-User OpenID Provider
(Authorization Server)
UserInfo Endpoint
Security Filter
予めClientの情報と
各種Endpointの情報を
設定しておく
45. 45Copyright?2017 NTT corp. All Rights Reserved.
Overview of OIDC with Spring Security
Client情報
Endpoint情報
Spring Security
認証機構
End-User OpenID Provider
(Authorization Server)
UserInfo Endpoint
Security Filter
Authorization Endpointへ
リダイレクト
ログイン試?
46. 46Copyright?2017 NTT corp. All Rights Reserved.
Overview of OIDC with Spring Security
Client情報
Endpoint情報
Spring Security
認証機構
End-User OpenID Provider
(Authorization Server)
UserInfo Endpoint
Security Filter
認証
47. 47Copyright?2017 NTT corp. All Rights Reserved.
Overview of OIDC with Spring Security
Client情報
Endpoint情報
Spring Security
認証機構
End-User OpenID Provider
(Authorization Server)
UserInfo Endpoint
Security Filter
指定されたRedirect URIへ
リダイレクト
認証処理を
委譲
48. 48Copyright?2017 NTT corp. All Rights Reserved.
Overview of OIDC with Spring Security
Client情報
Endpoint情報
Spring Security
認証機構
End-User OpenID Provider
(Authorization Server)
UserInfo Endpoint
Security Filter
Token Endpointに
リクエスト送信 Access Tokenと
ID Tokenを取得
49. 49Copyright?2017 NTT corp. All Rights Reserved.
Overview of OIDC with Spring Security
Client情報
Endpoint情報
Spring Security
認証機構
End-User OpenID Provider
(Authorization Server)
UserInfo Endpoint
Security Filter
検証?公開鍵(JWK Set)を
リクエスト
JWK Setを取得
ID Tokenを検証
50. 50Copyright?2017 NTT corp. All Rights Reserved.
Overview of OIDC with Spring Security
Client情報
Endpoint情報
Spring Security
認証機構
End-User OpenID Provider
(Authorization Server)
UserInfo Endpoint
Security Filter
リクエスト
ユーザプロフィールを取得
51. 51Copyright?2017 NTT corp. All Rights Reserved.
Overview of OIDC with Spring Security
Client情報
Endpoint情報
Spring Security
認証機構
End-User OpenID Provider
(Authorization Server)
UserInfo Endpoint
Security Filter
ユーザ情報作成
認証済みユーザとして
セッションに格納
52. 52Copyright?2017 NTT corp. All Rights Reserved.
Overview of OIDC with Spring Security
Client情報
Endpoint情報
Spring Security
認証機構
End-User OpenID Provider
(Authorization Server)
UserInfo Endpoint
Security Filter
予めClientの情報と
各種Endpointの情報を
設定しておく
54. 54Copyright?2017 NTT corp. All Rights Reserved.
? ClientRegistrationのID (registerID)
? Client名
? Client ID
? Client Secret
? Clientの認証?法 (Basic or Post)
? Grant Type (Authorization Code or Implicit)
? End-User認証後のRedirect URI
? 要求するScope
ClientRegistration
61. 61Copyright?2017 NTT corp. All Rights Reserved.
Overview of OIDC with Spring Security
Client情報
Endpoint情報
Spring Security
認証機構
End-User OpenID Provider
(Authorization Server)
UserInfo Endpoint
Security Filter
ユーザ情報作成
認証済みユーザとして
セッションに格納
62. 62Copyright?2017 NTT corp. All Rights Reserved.
OAuth2User
<<interface>>
AuthenticatedPrincipal
<<interface>>
OAuth2User
DefaultOAuth2User
<<interface>>
OidcUser
DefaultOidcUser
OAuth 2.0?
OpenID Connect?
UserInfo, ID Token等を持つ
63. 63Copyright?2017 NTT corp. All Rights Reserved.
Save authenticated user information
OAuth2Login
AuthenticationFilter
<<interface>>
OAuth2AuthorizedClientService
OAuth2AuthenticationTokenOAuth2AuthorizedClient
OAuth2AccessToken
Save
Save
SecurityContextから
取得できるようになる
OAuth2AuthorizedClientService経由で
取得できるようになる
<<interface>>
OAuth2User
64. 64Copyright?2017 NTT corp. All Rights Reserved.
1. 以下の依存ライブラリを追加 (pom.xml等)
? spring-boot-starter-web
? pring-security-config
? pring-security-oauth2-client
? pring-security-oauth2-jose
2. Client情報,Endpoint情報の設定 (application.yml
等)
? spring.security.oauth2.client.registration.{registrationId}の
下にClient情報を設定
? spring.security.oauth2.client.provider.{providerId}の下に
Endpoint情報を設定
? Facebook, Google, GitHub, Oktaの場合は設定不要
Use OIDC with Spring Boot
AutoConfigurationでデフォルトのBeanが作成される
65. 65Copyright?2017 NTT corp. All Rights Reserved.
? ログインページのカスタマイズ
? InMemory実装の置換
? GrantedAuthorityのカスタマイズ
Customize points
66. 66Copyright?2017 NTT corp. All Rights Reserved.
Customize login page
1. WebSecurityConfigurerAdapter を拡張して設定
2. Controllerの実装
3. ログインページの実装