Class DefaultOpenIdAuthenticationMapper
- All Implemented Interfaces:
OpenIdAuthenticationMapper
OpenIdAuthenticationMapper that uses
the subject claim for the username and populates the attributes with the
non JWT standard claims. If an OpenIdAuthenticationMapper bean is created
with a named qualifier that is the same name of the provider, that bean will
be used instead of this one.
The sub claim is only unique within the provider which issued it. When more than one enabled OAuth 2.0 client
(other than client-credentials-only clients) is configured under micronaut.security.oauth2.clients, or when
micronaut.security.oauth2.openid.qualify-username-with-provider is true, the username is qualified
with the provider name as providerName:subject so that users of different providers who share a
sub do not resolve to the same user. This is the same convention the UserInfo endpoint token validator uses.
The unqualified subject remains available in the sub attribute. Note that with
micronaut.security.authentication set to idtoken the ID token itself is the credential of later
requests, so their username is the bare sub claim and is not qualified.
- Since:
- 1.2.0
- Author:
- James Kleeh
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringSeparator between the provider name and thesubclaim in a qualified username.Fields inherited from interface OpenIdAuthenticationMapper
OPENID_TOKEN_KEY -
Constructor Summary
ConstructorsConstructorDescriptionDefaultOpenIdAuthenticationMapper(OpenIdAdditionalClaimsConfiguration openIdAdditionalClaimsConfiguration, AuthenticationModeConfiguration authenticationModeConfiguration) Deprecated, for removal: This API element is subject to removal in a future version.DefaultOpenIdAuthenticationMapper(OpenIdAdditionalClaimsConfiguration openIdAdditionalClaimsConfiguration, AuthenticationModeConfiguration authenticationModeConfiguration, @Nullable OpenIdConfiguration openIdConfiguration, Collection<OauthClientConfiguration> oauthClientConfigurations) -
Method Summary
Modifier and TypeMethodDescriptionbuildAttributes(String providerName, OpenIdTokenResponse tokenResponse, OpenIdClaims openIdClaims) @NonNull org.reactivestreams.Publisher<AuthenticationResponse> createAuthenticationResponse(String providerName, OpenIdTokenResponse tokenResponse, OpenIdClaims openIdClaims, @Nullable State state) getRoles(String providerName, OpenIdTokenResponse tokenResponse, OpenIdClaims openIdClaims) protected StringgetUsername(String providerName, OpenIdTokenResponse tokenResponse, OpenIdClaims openIdClaims) Returns thesubclaim, qualified with the provider name asproviderName:subjectwhenisQualifyUsernameWithProvider()istrue.booleanWhethergetUsername(String, OpenIdTokenResponse, OpenIdClaims)qualifies thesubclaim with the provider name.
-
Field Details
-
PROVIDER_USERNAME_SEPARATOR
Separator between the provider name and thesubclaim in a qualified username.- Since:
- 5.5.2
- See Also:
-
-
Constructor Details
-
DefaultOpenIdAuthenticationMapper
@Deprecated(forRemoval=true, since="5.5.2") public DefaultOpenIdAuthenticationMapper(OpenIdAdditionalClaimsConfiguration openIdAdditionalClaimsConfiguration, AuthenticationModeConfiguration authenticationModeConfiguration) Deprecated, for removal: This API element is subject to removal in a future version.UseDefaultOpenIdAuthenticationMapper(OpenIdAdditionalClaimsConfiguration, AuthenticationModeConfiguration, OpenIdConfiguration, Collection)instead. This constructor never qualifies the username with the provider name.Default constructor.- Parameters:
openIdAdditionalClaimsConfiguration- The additional claims configurationauthenticationModeConfiguration- Authentication Mode Configuration
-
DefaultOpenIdAuthenticationMapper
@Inject public DefaultOpenIdAuthenticationMapper(OpenIdAdditionalClaimsConfiguration openIdAdditionalClaimsConfiguration, AuthenticationModeConfiguration authenticationModeConfiguration, @Nullable OpenIdConfiguration openIdConfiguration, Collection<OauthClientConfiguration> oauthClientConfigurations) - Parameters:
openIdAdditionalClaimsConfiguration- The additional claims configurationauthenticationModeConfiguration- Authentication Mode ConfigurationopenIdConfiguration- OpenID configurationoauthClientConfigurations- The OAuth 2.0 client configurations- Since:
- 5.5.2
-
-
Method Details
-
createAuthenticationResponse
public @NonNull org.reactivestreams.Publisher<AuthenticationResponse> createAuthenticationResponse(String providerName, OpenIdTokenResponse tokenResponse, OpenIdClaims openIdClaims, @Nullable State state) - Specified by:
createAuthenticationResponsein interfaceOpenIdAuthenticationMapper- Parameters:
providerName- The OpenID provider nametokenResponse- The token responseopenIdClaims- The OpenID claimsstate- The state of the response- Returns:
- An authentication response
-
buildAttributes
protected Map<String,Object> buildAttributes(String providerName, OpenIdTokenResponse tokenResponse, OpenIdClaims openIdClaims) - Parameters:
providerName- The OpenID provider nametokenResponse- The token responseopenIdClaims- The OpenID claims- Returns:
- The attributes to set in the
Authentication
-
getRoles
protected List<String> getRoles(String providerName, OpenIdTokenResponse tokenResponse, OpenIdClaims openIdClaims) - Parameters:
providerName- The OpenID provider nametokenResponse- The token responseopenIdClaims- The OpenID claims- Returns:
- The roles to set in the
Authentication
-
getUsername
protected String getUsername(String providerName, OpenIdTokenResponse tokenResponse, OpenIdClaims openIdClaims) Returns thesubclaim, qualified with the provider name asproviderName:subjectwhenisQualifyUsernameWithProvider()istrue.- Parameters:
providerName- The OpenID provider nametokenResponse- The token responseopenIdClaims- The OpenID claims- Returns:
- The username to set in the {
Authentication
-
isQualifyUsernameWithProvider
public boolean isQualifyUsernameWithProvider()WhethergetUsername(String, OpenIdTokenResponse, OpenIdClaims)qualifies thesubclaim with the provider name. This is the value ofmicronaut.security.oauth2.openid.qualify-username-with-providerif set; otherwisetruewhen more than one enabled OAuth 2.0 client, other than client-credentials-only clients, is configured undermicronaut.security.oauth2.clients.- Returns:
- Whether the username is qualified with the provider name
- Since:
- 5.5.2
-
DefaultOpenIdAuthenticationMapper(OpenIdAdditionalClaimsConfiguration, AuthenticationModeConfiguration, OpenIdConfiguration, Collection)instead.