Class ResourceServerFactory

java.lang.Object
io.leandev.appfuse.security.resourceserver.ResourceServerFactory

public final class ResourceServerFactory extends Object

雙模式資源伺服器的組裝核心(ADR-009 點 1、機制上框架)

「模式 → 用哪個 JwtDecoder / converter」的切換邏輯集中於此(住框架 jar), 消費端只需依自身政策提供輸入(本地公鑰、issuer-uri),把產物套進自己的 oauth2ResourceServer().jwt()——維持「框架給積木、應用組裝 filter chain」 的設計原則(見 10-java.md)。

兩模式二擇一,於 validateMode(AuthMode, String) 啟動 fail-fast 互斥驗證。

  • Method Summary

    Modifier and Type
    Method
    Description
    static 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.JwtDecoder
    jwtDecoder(AuthMode mode, PublicKey localKey, String issuerUri)
    依模式建立對應的 JwtDecoder(建立前先 validateMode(AuthMode, String)
    static void
    validateMode(AuthMode mode, String issuerUri)
    驗證模式與設定互斥(fail-fast,ADR-009 風險表「兩模式設定誤用」緩解)

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • validateMode

      public static void validateMode(AuthMode mode, String issuerUri)

      驗證模式與設定互斥(fail-fast,ADR-009 風險表「兩模式設定誤用」緩解)

      • FEDERATED:必須提供 issuer-uri(否則無從驗證 IdP token)。
      • STANDALONE:不得同時提供 issuer-uri(避免本地金鑰與 IdP 同時生效的歧義)。
      Throws:
      IllegalStateException - 設定與模式不一致時
    • 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/空白)
    • 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)。