Comprehensive guides and references for the OpenFrame platform
The Authorization Server Keys And Persistence module is responsible for:
It forms the cryptographic and persistence backbone of the Authorization Server, ensuring:
This module works closely with:
flowchart TD
Client["OAuth2 Client"] -->|"Authorization Request"| AuthServer["Authorization Server"]
subgraph keys["Tenant Key Management"]
TenantKeyService["TenantKeyService"] --> KeyRepo["TenantKeyRepository"]
TenantKeyService --> Encryption["EncryptionService"]
TenantKeyService --> KeyGen["RsaAuthenticationKeyPairGenerator"]
end
subgraph clients["Client Persistence"]
ClientRepoAdapter["MongoRegisteredClientRepository"] --> ClientMongoRepo["RegisteredClientMongoRepository"]
end
subgraph authz["Authorization Persistence"]
AuthService["MongoAuthorizationService"] --> AuthRepo["MongoOAuth2AuthorizationRepository"]
AuthService --> AuthMapper["MongoAuthorizationMapper"]
end
AuthServer --> TenantKeyService
AuthServer --> ClientRepoAdapter
AuthServer --> AuthService
AuthRepo --> MongoDB[("MongoDB")]
ClientMongoRepo --> MongoDB
KeyRepo --> MongoDB
The module is structured into three main concerns:
Each tenant in the system must have its own signing key to:
The TenantKeyService ensures there is always exactly one active signing key per tenant.
PemUtilRsaAuthenticationKeyPairGeneratorTenantKeyServiceflowchart TD
Request["Request for Signing Key"] --> Check["Find Active Key"]
Check -->|"Found"| Load["Load Public + Decrypt Private"]
Check -->|"Not Found"| Generate["Generate RSA 2048 Key Pair"]
Generate --> Encrypt["Encrypt Private Key"]
Encrypt --> Store["Store TenantKey Document"]
Store --> Load
Load --> Build["Build RSAKey with kid"]
Build --> Return["Return RSAKey"]
Responsibilities:
TenantKeyRepositoryRSAKey objects (Nimbus JOSE) for signingKey behaviors:
EncryptionServicekid-<uuid>KeyPairGenerator with RSAPemUtilHandles:
RSAPublicKey / RSAPrivateKeyThis utility ensures compatibility with standard X509 (public) and PKCS8 (private) formats.
The Authorization Server requires persistent storage of registered OAuth2 clients.
MongoRegisteredClientRepository acts as an adapter between:
RegisteredClientMongoRegisteredClientflowchart LR
SpringAuth["Spring Authorization Server"] --> Adapter["MongoRegisteredClientRepository"]
Adapter --> MongoRepo["RegisteredClientMongoRepository"]
MongoRepo --> MongoDB[("MongoDB")]
Implements:
RegisteredClientRepositoryResponsibilities:
RegisteredClient → MongoRegisteredClientMongoRegisteredClient → RegisteredClientrequireProofKeyrequireAuthorizationConsentThis design allows dynamic client registration and runtime rehydration.
The Authorization Server must persist:
MongoAuthorizationService provides a Mongo-backed implementation of OAuth2AuthorizationService.
flowchart TD
SpringAuth["Spring Authorization Server"] --> Service["MongoAuthorizationService"]
Service --> Mapper["MongoAuthorizationMapper"]
Mapper --> Entity["MongoOAuth2Authorization"]
Entity --> Repo["MongoOAuth2AuthorizationRepository"]
Repo --> MongoDB[("MongoDB")]
Implements:
OAuth2AuthorizationServiceKey operations:
save(authorization)remove(authorization)findById(id)findByToken(token, tokenType)flowchart TD
Input["findByToken(token, type)"] --> CheckType
CheckType -->|"null"| TryAll["Access → Refresh → Code → State"]
CheckType -->|"ACCESS_TOKEN"| AccessOnly
CheckType -->|"REFRESH_TOKEN"| RefreshOnly
CheckType -->|"code"| CodeOnly
TryAll --> Result
AccessOnly --> Result
RefreshOnly --> Result
CodeOnly --> Result
Result["Return OAuth2Authorization"]
This flexible resolution ensures compatibility with different validation flows.
This class handles complex bidirectional mapping between:
OAuth2Authorization (Spring domain model)MongoOAuth2Authorization (Mongo document)OAuth2AuthorizationRequestSpecial handling ensures:
code_challengecode_challenge_methodare stored in:
and correctly restored when loading from Mongo.
This guarantees PKCE validation works after server restarts.
This module relies on MongoDB document models defined in:
Key documents:
TenantKeyMongoRegisteredClientMongoOAuth2AuthorizationThese provide:
sequenceDiagram
participant Client
participant AuthServer as "Authorization Server"
participant KeyService as "TenantKeyService"
participant AuthService as "MongoAuthorizationService"
participant MongoDB
Client->>AuthServer: Authorization Request with PKCE
AuthServer->>AuthService: Save Authorization Code
AuthService->>MongoDB: Persist MongoOAuth2Authorization
Client->>AuthServer: Token Request with Code
AuthServer->>AuthService: Load Authorization by Code
AuthService->>MongoDB: Fetch Entity
AuthService->>AuthServer: Rehydrated Authorization
AuthServer->>KeyService: Get Signing Key
KeyService->>MongoDB: Load or Create TenantKey
AuthServer->>Client: Signed JWT Access Token
The Authorization Server Keys And Persistence module provides:
It is the critical persistence and cryptographic layer that ensures the Authorization Server remains secure, multi-tenant aware, and stateless at runtime while retaining durable authorization state in MongoDB.