Class AbstractClientIdMetadataDocumentExecutor<CONFIG extends AbstractClientIdMetadataDocumentExecutor.Configuration>
- All Implemented Interfaces:
Provider,ClientPolicyExecutorProvider<CONFIG>
- Direct Known Subclasses:
ClientIdMetadataDocumentExecutor
- Author:
- Takashi Norimatsu
- See Also:
-
- OAuth Client ID Metadata Document (CIMD) [Internet Draft]]
Moreover, the abstract class implements Authorization part of Model Context Protocol (MCP) specification (version 2025-11-25).
- Model Context Protocol (MCP) [2025-11-25]]
The abstract class satisfies the following requirements of CIMD and MCP:
- Requirements whose requirement level is MUST or SHOULD.
- Requirements in Security Consideration.
The abstract class provides the following features:
- Client ID Verification: if {client_id} parameter satisfies the requirements of the specifications
- Client ID Validation: if {client_id} parameter is valid according to the policy.
- Fetching Client Metadata: fetch a client metadata by accessing {client_id} URL.
- Client Metadata Verification: if a client metadata satisfies the requirements of the specifications.
- Client Metadata Validation: if a client metadata is valid according to the policy.
- Client Metadata Augmentation in OIDCClientRepresentation: augment a fetched client metadata.
Roles of the abstract class and its concrete class: The abstract class covers the basic checks and processes by following the CIMD and MCP specifications while the concrete class of the abstract class provides additional checks or processes.
For example, regarding Client ID Validation and Client Metadata Validation, the CIMD and MCP specifications allow an authorization server to implement policies that determine the valid {client_id} parameter value and client metadata. The CIMD and MCP specification show some examples of the policies roughly, but what policies are implemented in detail is up to the authorization server implementation. Therefore, the abstract class provides some of the examples and the concrete class can implement additional policies.
Client Metadata Caching: The abstract class does not treat the following processes. It delegates them to ClientIdMetadataDocumentProvider:
- determining if (re-)fetching a client metadata is needed
- concrete process of caching a client metadata: create and update
- update cache expiry time
- augment a client metadata in
ClientRepresentation
PersistentClientIdMetadataDocumentProviderpersists client metadata. In the future, the provider for non-persisting a client metadata can be provided.Client Metadata Format: According to the CIMD specification, the client metadata format is the same as for Dynamic Client Registration except for
client_idproperty. - invalid input: '<a href="https://datatracker.ietf.org/doc/html/rfc7591>OAuth 2.0 Dynamic Client Registration Protocol [RFC 7591]</a> Therefore, OIDCClientRepresentation is used for the client metadata format. The CIMD specification allows the use of additional properties (MAY requirement level), but the class does not treat them. <p>Client Metadata Augmentation in <code>OIDCClientRepresentation</code>: To successfully convert a fetched client metadata to <code>ClientRepresentation</code>, intentionally augment it. The actual example is a public client. The CIMD and MCP specification allows a public client. <code>DescriptionConverter.toInternal</code> recognize a client as a public client if token_endpoint_auth_method is "none" If a client metadata lacks token_endpoint_auth_method, it is converted to "none", meaning it is treated as a public client.'
- OAuth Client ID Metadata Document (CIMD) [Internet Draft]]
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classThe CIMD and MCP specification requires an authorization server to cache a client metadata.static classstatic interfacestatic enumCREATE: a client metadata is not created, so fetching it creating it is needed.static classThe CIMD and MCP specification requires an authorization server to cache a client metadata. -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected CONFIGstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringprotected ClientIdMetadataDocumentProvider<CONFIG>protected final KeycloakSession -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedAbstractClientIdMetadataDocumentExecutor(KeycloakSession session, ClientIdMetadataDocumentExecutorFactoryProviderConfig providerConfig) -
Method Summary
Modifier and TypeMethodDescriptionprotected voidaugmentClientOIDC(OIDCClientRepresentation oidcClient) Augments a re-fetched client metadata to successfully convert it toClientRepresentation.protected booleancheckTrustedDomain(String hostname, String trustedDomain) convertContentFilledList(List<String> list) voidexecuteOnEvent(ClientPolicyContext context) execute actions against the client on the event defined inClientPolicyEvent.fetchClientMetadata(URI clientIdURI, boolean isUpdate, ClientIdMetadataDocumentProvider provider) fetch a client metadata and update cache expiry time if the client metadata has been already created.protected abstract org.jboss.logging.Loggerprotected ClientIdMetadataDocumentProvider<CONFIG>protected static ClientPolicyExceptioninvalidClientIdMetadata(String errorDetail) protected voidvalidateClientId(URI clientIdURI) Validate a value ofclient_idparameter of an authorization request to check if the value meets the policies.protected voidvalidateClientMetadata(URI clientIdURI, URI redirectUriURI, OIDCClientRepresentation clientOIDC) Validate a client metadata to check if the value meets the policies.protected URIverifyAuthorizationRequest(PreAuthorizationRequestContext preAuthorizationRequestContext) Verifies an authorization request to check if the request includes required parameters and follows the expected format.protected URIverifyClientId(String clientId) Verifies a value ofclient_idparameter of an authorization request to check if the value satisfies the requirements of the CIMD and MCP specifications.protected URIverifyClientMetadata(URI clientIdURI, URI redirectUriURI, OIDCClientRepresentation clientOIDC) Verify a client metadata to check if it satisfies the requirements of the CIMD and MCP specifications.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.keycloak.services.clientpolicy.executor.ClientPolicyExecutorProvider
close, getExecutorConfigurationClass, getName, getProviderId, setupConfiguration
-
Field Details
-
session
-
configuration
-
provider
protected ClientIdMetadataDocumentProvider<CONFIG extends AbstractClientIdMetadataDocumentExecutor.Configuration> provider -
providerConfig
-
ERR_INVALID_PARAMETER
- See Also:
-
ERR_CLIENTID_MALFORMED_URL
- See Also:
-
ERR_CLIENTID_INVALID_SCHEME
- See Also:
-
ERR_CLIENTID_EMPTY_PATH
- See Also:
-
ERR_CLIENTID_PATH_TRAVERSAL
- See Also:
-
ERR_CLIENTID_FRAGMENT
- See Also:
-
ERR_CLIENTID_USERINFO
- See Also:
-
ERR_CLIENTID_QUERY
- See Also:
-
ERR_NOTALLOWED_DOMAIN
- See Also:
-
ERR_METADATA_NOCONTENT
- See Also:
-
ERR_METADATA_NOCLIENTID
- See Also:
-
ERR_METADATA_CLIENTID_UNMATCH
- See Also:
-
ERR_METADATA_NOTALLOWED_CLIENTAUTH
- See Also:
-
ERR_METADATA_CLIENTSECRET
- See Also:
-
ERR_METADATA_REDIRECTURI
- See Also:
-
ERR_METADATA_MALFORMED_URL
- See Also:
-
ERR_HOST_UNRESOLVED
- See Also:
-
ERR_METADATA_URIS_SAMEDOMAIN
- See Also:
-
ERR_METADATA_NO_REQUIRED_PROPERTIES
- See Also:
-
ERR_METADATA_NO_ALL_URIS_SAMEDOMAIN
- See Also:
-
ERR_METADATA_FETCH_FAILED
- See Also:
-
NOTALLOWED_ALGORITHMS
-
-
Constructor Details
-
AbstractClientIdMetadataDocumentExecutor
protected AbstractClientIdMetadataDocumentExecutor(KeycloakSession session, ClientIdMetadataDocumentExecutorFactoryProviderConfig providerConfig)
-
-
Method Details
-
getLogger
protected abstract org.jboss.logging.Logger getLogger() -
getProvider
-
getConfiguration
-
executeOnEvent
Description copied from interface:ClientPolicyExecutorProviderexecute actions against the client on the event defined inClientPolicyEvent.- Specified by:
executeOnEventin interfaceClientPolicyExecutorProvider<CONFIG extends AbstractClientIdMetadataDocumentExecutor.Configuration>- Parameters:
context- - the context of the event.- Throws:
ClientPolicyException
-
verifyAuthorizationRequest
protected URI verifyAuthorizationRequest(PreAuthorizationRequestContext preAuthorizationRequestContext) throws ClientPolicyException Verifies an authorization request to check if the request includes required parameters and follows the expected format.- Parameters:
preAuthorizationRequestContext- an authorization request- Returns:
URIredirect_uriparameter value asURI- Throws:
ClientPolicyException- when verification of an authorization request fails.
-
verifyClientId
Verifies a value ofclient_idparameter of an authorization request to check if the value satisfies the requirements of the CIMD and MCP specifications.- Parameters:
clientId- a value ofclient_idparameter of an authorization request- Returns:
URIclient_uriparameter value asURI- Throws:
ClientPolicyException- when verification of an authorization request fails.
-
validateClientId
Validate a value ofclient_idparameter of an authorization request to check if the value meets the policies.- Parameters:
clientIdURI- a value ofclient_idparameter of an authorization request inURI- Throws:
ClientPolicyException- when validation of an authorization request fails.
-
checkTrustedDomain
-
fetchClientMetadata
protected AbstractClientIdMetadataDocumentExecutor.OIDCClientRepresentationWithCacheControl fetchClientMetadata(URI clientIdURI, boolean isUpdate, ClientIdMetadataDocumentProvider provider) throws ClientPolicyException fetch a client metadata and update cache expiry time if the client metadata has been already created.- Parameters:
clientIdURI- a value ofclient_idparameter of an authorization request inURIisUpdate- indicates the client metadata has been already createdprovider-ClientIdMetadataDocumentProviderfor updating cache expiry time- Returns:
OIDCClientRepresentationWithCacheControla combination of a client metadata and Cache-Control header value accompanied by the metadata response.nullif a client metadata was re-fetched but the HTTP response status code is 304 Not Modified.- Throws:
ClientPolicyException- when fetching a client metadata fails.
-
verifyClientMetadata
protected URI verifyClientMetadata(URI clientIdURI, URI redirectUriURI, OIDCClientRepresentation clientOIDC) throws ClientPolicyException Verify a client metadata to check if it satisfies the requirements of the CIMD and MCP specifications.- Parameters:
clientIdURI- a value of {client_id} parameter of an authorization request inURIredirectUriURI- a value of {redirect_uri} parameter of an authorization request inURIclientOIDC- a client metadata- Returns:
URIclient_idproperty of a client metadata inURI- Throws:
ClientPolicyException- when verifying a client metadata fails.
-
validateClientMetadata
protected void validateClientMetadata(URI clientIdURI, URI redirectUriURI, OIDCClientRepresentation clientOIDC) throws ClientPolicyException Validate a client metadata to check if the value meets the policies.- Parameters:
clientIdURI- a value of {client_id} parameter of an authorization request inURIredirectUriURI- a value of {redirect_uri} parameter of an authorization request inURIclientOIDC- a client metadata- Throws:
ClientPolicyException- when validating a client metadata fails.
-
convertContentFilledList
-
augmentClientOIDC
Augments a re-fetched client metadata to successfully convert it toClientRepresentation.- Parameters:
oidcClient- a fetched client metadata
-
invalidClientIdMetadata
-