Class DefaultProviderResolver
- All Implemented Interfaces:
ProviderResolver
ProviderResolver.
The provider is read from the OauthAuthenticationMapper.PROVIDER_KEY attribute when present. The attribute is set
by this application during the authorization code flow and by the UserInfo token validator; an ID token carrying a
claim with that name is rejected by IdTokenClaimsValidator, so with
micronaut.security.authentication=idtoken the attribute never comes from the token which authenticated the request.
Otherwise the provider is inferred from the token claims: the OpenID clients whose configured issuer matches the iss
claim are the candidates. If several clients match the issuer (for example two Oracle Cloud identity domains, whose ID tokens
share the same iss claim) the aud claim, and if needed the azp claim, are compared with the clients'
client-id to pick the client the token was issued to. If exactly one client cannot be determined, no provider is
resolved. OpenID clients whose OAuth 2.0 client is disabled are ignored.
- Since:
- 1.2.0
- Author:
- James Kleeh
-
Constructor Summary
ConstructorsConstructorDescriptionDefaultProviderResolver(List<OpenIdClientConfiguration> openIdClientConfigurations) Deprecated.DefaultProviderResolver(List<OpenIdClientConfiguration> openIdClientConfigurations, Collection<OauthClientConfiguration> oauthClientConfigurations) -
Method Summary
Modifier and TypeMethodDescriptionopenIdClientNamesWhichMatchIssuer(@NonNull String issuer) openIdClientNameWhichMatchesAudience(@NonNull Authentication authentication, @NonNull List<String> candidateNames) Picks, among the open id clients whose issuer matches the token, the one whoseclient-idthe token was issued to.openIdClientNameWhichMatchesIssClaim(Authentication authentication) Resolves the provider from theissclaim.openIdClientNameWhichMatchesIssuer(@NonNull String issuer) The issuer matches an open id client when it is identical to the expected issuer of the client; only the case of the scheme and a single trailing slash are tolerated.resolveProvider(Authentication authentication) Resolves the provider.
-
Constructor Details
-
DefaultProviderResolver
@Inject public DefaultProviderResolver(List<OpenIdClientConfiguration> openIdClientConfigurations, Collection<OauthClientConfiguration> oauthClientConfigurations) - Parameters:
openIdClientConfigurations- OpenID client configurationsoauthClientConfigurations- OAuth 2.0 client configurations. OpenID clients whose OAuth 2.0 client is disabled are ignored.
-
DefaultProviderResolver
@Deprecated(since="5.5.2") public DefaultProviderResolver(List<OpenIdClientConfiguration> openIdClientConfigurations) Deprecated.UseDefaultProviderResolver(List, Collection)instead, which ignores disabled OAuth 2.0 clients. Without the OAuth 2.0 client configurations theaudclaim cannot be used to tell apart OpenID clients whose issuers overlap, and no provider is resolved in that case.- Parameters:
openIdClientConfigurations- OpenID client configurations
-
-
Method Details
-
resolveProvider
Description copied from interface:ProviderResolverResolves the provider.- Specified by:
resolveProviderin interfaceProviderResolver- Parameters:
authentication- The authentication- Returns:
- An optional provider name
-
openIdClientNameWhichMatchesIssClaim
Resolves the provider from theissclaim.openIdClientNameWhichMatchesIssuer(String)decides whether the issuer maps to a client: if it returns no client, no provider is resolved. If it returns one of several clients which match the issuer,openIdClientNameWhichMatchesAudience(Authentication, List)picks among them the client the token was issued to.- Parameters:
authentication- State of authentication- Returns:
- Optional#empty() if iss claim not found, if the iss claim does not match the issuer of any open id client, or if the iss claim matches several open id clients and the aud and azp claims do not single out one of them. If exactly one open id client matches, its name is returned wrapped in an optional
-
openIdClientNameWhichMatchesIssuer
The issuer matches an open id client when it is identical to the expected issuer of the client; only the case of the scheme and a single trailing slash are tolerated. SeeIssuerUtils.equivalent(String, String). When several clients match the issuer, the first one is returned andopenIdClientNameWhichMatchesIssClaim(Authentication)uses theaudclaim to pick among them.Subclasses may override this method to customize how the issuer is mapped to a client. If it returns no client, no provider is resolved. A client which is not one of the clients matching the issuer is used as is.
- Parameters:
issuer- Token Issuer- Returns:
- Optional#empty() if the issuer does not match the expected issuer (
OpenIdClientConfiguration.getIssuerIdentifier()) of any open id client. If it matches, the open id client is returned wrapped in an optional
-
openIdClientNamesWhichMatchIssuer
- Parameters:
issuer- Token Issuer- Returns:
- The names of every open id client whose expected issuer (
OpenIdClientConfiguration.getIssuerIdentifier()) matches the token issuer - Since:
- 5.5.2
-
openIdClientNameWhichMatchesAudience
protected @NonNull Optional<String> openIdClientNameWhichMatchesAudience(@NonNull Authentication authentication, @NonNull List<String> candidateNames) Picks, among the open id clients whose issuer matches the token, the one whoseclient-idthe token was issued to. Theaudclaim must contain the client id. If theaudclaim contains the client id of several candidates, theazpclaim must be equal to the client id of exactly one of them.- Parameters:
authentication- State of authenticationcandidateNames- Names of the open id clients whose issuer matches the token issuer- Returns:
- The name of the only candidate the token was issued to, or Optional#empty() if the token audience does not single out one candidate
- Since:
- 5.5.2
-
DefaultProviderResolver(List, Collection)instead, which ignores disabled OAuth 2.0 clients.