Class ResourceServerFactory
java.lang.Object
io.leandev.appfuse.security.resourceserver.ResourceServerFactory
雙模式資源伺服器的組裝核心(ADR-009 點 1、機制上框架)
「模式 → 用哪個 JwtDecoder / converter」的切換邏輯集中於此(住框架 jar),
消費端只需依自身政策提供輸入(本地公鑰、issuer-uri),把產物套進自己的
oauth2ResourceServer().jwt()——維持「框架給積木、應用組裝 filter chain」
的設計原則(見 10-java.md)。
兩模式二擇一,於 validateMode(AuthMode, String) 啟動 fail-fast 互斥驗證。
-
Method Summary
Modifier and TypeMethodDescriptionstatic org.springframework.core.convert.converter.Converter<org.springframework.security.oauth2.jwt.Jwt, org.springframework.security.authentication.AbstractAuthenticationToken> 依模式建立 JWT → Authentication 轉換器,兩模式皆吐同一套resource:action權限詞彙(ADR-009 點 2)。FEDERATED 使用預設 roles claim(roles)。static org.springframework.security.oauth2.jwt.JwtDecoderjwtDecoder(AuthMode mode, PublicKey localKey, String issuerUri) 依模式建立對應的JwtDecoder(建立前先validateMode(AuthMode, String))static voidvalidateMode(AuthMode mode, String issuerUri) 驗證模式與設定互斥(fail-fast,ADR-009 風險表「兩模式設定誤用」緩解)
-
Method Details
-
validateMode
驗證模式與設定互斥(fail-fast,ADR-009 風險表「兩模式設定誤用」緩解)
- FEDERATED:必須提供
issuer-uri(否則無從驗證 IdP token)。 - STANDALONE:不得同時提供
issuer-uri(避免本地金鑰與 IdP 同時生效的歧義)。
- Throws:
IllegalStateException- 設定與模式不一致時
- FEDERATED:必須提供
-
jwtDecoder
public static org.springframework.security.oauth2.jwt.JwtDecoder jwtDecoder(AuthMode mode, PublicKey localKey, String issuerUri) 依模式建立對應的
JwtDecoder(建立前先validateMode(AuthMode, String))- STANDALONE:以本地 RSA 公鑰驗章(對映自簽 token,預設 RS256,
與
JwtTokenProvider.signWith(RSA privateKey)一致)。 - FEDERATED:以
issuer-uri經 OIDC discovery 取得 JWKS 驗章。
- Parameters:
mode- 認證模式localKey- STANDALONE 模式的本地公鑰(須為 RSA;FEDERATED 可為 null)issuerUri- FEDERATED 模式的 IdP issuer(STANDALONE 須為 null/空白)
- STANDALONE:以本地 RSA 公鑰驗章(對映自簽 token,預設 RS256,
與
-
authenticationConverter
public static org.springframework.core.convert.converter.Converter<org.springframework.security.oauth2.jwt.Jwt, org.springframework.security.authentication.AbstractAuthenticationToken> authenticationConverter(AuthMode mode) 依模式建立 JWT → Authentication 轉換器,兩模式皆吐同一套resource:action權限詞彙(ADR-009 點 2)。FEDERATED 使用預設 roles claim(roles)。
-