Class InitializeOAuth2ClientAuthenticationMethodHandler
- java.lang.Object
-
- net.shibboleth.utilities.java.support.component.AbstractInitializableComponent
-
- org.opensaml.messaging.handler.AbstractMessageHandler
-
- net.shibboleth.idp.plugin.authn.oidc.rp.impl.InitializeOAuth2ClientAuthenticationMethodHandler
-
- All Implemented Interfaces:
Component,DestructableComponent,InitializableComponent,MessageHandler
public class InitializeOAuth2ClientAuthenticationMethodHandler extends AbstractMessageHandler
Anactionthat resolves the Client Authentication method for the chosen upstream OpenID Provider (issuer) from the profile configuration, and adds it to theOAuth2ClientAuthenticationContext.If a JWT client authentication type, the security parameters context is used create a signed JWT client assertion.
- Event:
EventIds.PROCEED_EVENT_ID,IdPEventIds.INVALID_PROFILE_CONFIG,EventIds.INVALID_PROFILE_CTX,IdPEventIds.INVALID_RELYING_PARTY_CONFIG- Postcondition:
- Add the
ClientAuthenticationMethodto theOAuth2ClientAuthenticationContext
-
-
Field Summary
Fields Modifier and Type Field Description private StringclientAuthMethodThe stashed client authentication method to use.private ClientSecretCredentialclientCredentialThe stashed client_secret to use if required.private StringclientIdThe stashed client identifier for this request.private SecurityParametersContextjwtBearerClientAuthSecurityParametersStashed security parameters context for JWT Bearer Token client authentication methods.private DurationjwtBearerExpiryOffsetThe offset to add to the 'exp' claim time for JWT client authentication methods.private org.slf4j.LoggerlogClass logger.private OAuth2ClientAuthenticationContextoauth2ClientAuthenticationContextThe stashed OAuth2 client authentication context.private Function<MessageContext,OAuth2ClientAuthenticationContext>oauth2ClientAuthenticationContextLookupStrategyThe strategy used to lookup or create theOAuth2ClientAuthenticationContextfor storing the client authentication.private static ParentProfileRequestContextLookup<MessageContext>PRC_LOOKUPLookup function for parent ProfileRequestContext.private OIDCAuthenticationRelyingPartyProfileConfigurationprofileConfigurationApplicable stashed profile configuration.private com.nimbusds.openid.connect.sdk.op.OIDCProviderMetadataproviderMetadataThe stashed provider metadata.private Function<MessageContext,OIDCProviderMetadataContext>providerMetadataLookupStrategyLookup strategy to locate the OP metadata to use.private Function<ProfileRequestContext,RelyingPartyContext>relyingPartyContextLookupStrategyLookup function for relying party context.private Function<MessageContext,SecurityParametersContext>securityParametersContextLookupStrategyStrategy used to look up theSecurityParametersContextto set the parameters for.
-
Constructor Summary
Constructors Constructor Description InitializeOAuth2ClientAuthenticationMethodHandler()Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private com.nimbusds.jwt.SignedJWTbuildClientAuthenticationJwt()Build a signed JWT bearer token for client authentication using the populated security parameters.private com.nimbusds.jwt.JWTClaimsSetbuildClientAuthenticationJwtClaims()Build the claim values required for a client authentication bearer JWT.private StringconvertSecretKeyToString(SecretKey key)Convert the encoded byte array representing the secret into a UTF-8 String.protected voiddoInvoke(MessageContext messageContext)protected booleandoPreInvoke(MessageContext messageContext)private com.nimbusds.jose.JWSSignergetSigner(com.nimbusds.jose.Algorithm jwsAlgorithm, Credential credential)Returns correct implementation of signer based on algorithm type.protected com.nimbusds.jose.JWSAlgorithmresolveAlgorithm(SignatureSigningParameters params)Resolves JWS algorithm from signature signing parameters.voidsetJwtBearerExpiryOffset(Duration expiry)Set the JWT expiry time offset for appropriate client authentication methods.voidsetOAuth2ClientAuthenticationContextLookupStrategy(Function<MessageContext,OAuth2ClientAuthenticationContext> strgy)Set the strategy to lookup theOAuth2ClientAuthenticationContextfrom theMessageContext.voidsetProviderMetadataLookupStrategy(Function<MessageContext,OIDCProviderMetadataContext> strategy)Set the lookup strategy to locate the OpenID providers metadata.voidsetRelyingPartyContextLookupStrategy(Function<ProfileRequestContext,RelyingPartyContext> strategy)Set lookup strategy for relying party context.voidsetSecurityParametersContextLookupStrategy(Function<MessageContext,SecurityParametersContext> strategy)Set the strategy used to look up theSecurityParametersContext.private com.nimbusds.jwt.SignedJWTsignClaims(com.nimbusds.jwt.JWTClaimsSet jwtClaimSetToSign, SecurityParametersContext secContext)Sign the given JWT claims set using the signing parameters from the context.private voidverifySuitableClientSecretJWTSecurityContext()Check the populated security context is using the correct algorithm family for client_secret_jwt client authentication.private voidverifySuitablePrivateKetJWTSecurityContext()Check the populated security context is using the correct algorithm family for private_key_jwt client authentication.-
Methods inherited from class org.opensaml.messaging.handler.AbstractMessageHandler
doPostInvoke, doPostInvoke, getActivationCondition, getLogPrefix, invoke, setActivationCondition
-
Methods inherited from class net.shibboleth.utilities.java.support.component.AbstractInitializableComponent
destroy, doDestroy, doInitialize, initialize, isDestroyed, isInitialized
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface net.shibboleth.utilities.java.support.component.InitializableComponent
initialize, isInitialized
-
-
-
-
Field Detail
-
log
@Nonnull private final org.slf4j.Logger log
Class logger.
-
PRC_LOOKUP
@Nonnull private static final ParentProfileRequestContextLookup<MessageContext> PRC_LOOKUP
Lookup function for parent ProfileRequestContext.
-
oauth2ClientAuthenticationContextLookupStrategy
@Nonnull private Function<MessageContext,OAuth2ClientAuthenticationContext> oauth2ClientAuthenticationContextLookupStrategy
The strategy used to lookup or create theOAuth2ClientAuthenticationContextfor storing the client authentication.
-
oauth2ClientAuthenticationContext
@Nullable private OAuth2ClientAuthenticationContext oauth2ClientAuthenticationContext
The stashed OAuth2 client authentication context.
-
providerMetadataLookupStrategy
@Nonnull private Function<MessageContext,OIDCProviderMetadataContext> providerMetadataLookupStrategy
Lookup strategy to locate the OP metadata to use.
-
relyingPartyContextLookupStrategy
@Nonnull private Function<ProfileRequestContext,RelyingPartyContext> relyingPartyContextLookupStrategy
Lookup function for relying party context.
-
profileConfiguration
@Nullable private OIDCAuthenticationRelyingPartyProfileConfiguration profileConfiguration
Applicable stashed profile configuration.
-
securityParametersContextLookupStrategy
@Nonnull private Function<MessageContext,SecurityParametersContext> securityParametersContextLookupStrategy
Strategy used to look up theSecurityParametersContextto set the parameters for.
-
jwtBearerExpiryOffset
@Nonnull private Duration jwtBearerExpiryOffset
The offset to add to the 'exp' claim time for JWT client authentication methods. Default is 30 seconds.
-
jwtBearerClientAuthSecurityParameters
@Nullable private SecurityParametersContext jwtBearerClientAuthSecurityParameters
Stashed security parameters context for JWT Bearer Token client authentication methods. Can benullif those client authentication methods are not used.
-
providerMetadata
@Nullable private com.nimbusds.openid.connect.sdk.op.OIDCProviderMetadata providerMetadata
The stashed provider metadata.
-
clientCredential
@Nullable private ClientSecretCredential clientCredential
The stashed client_secret to use if required.
-
clientAuthMethod
@Nullable private String clientAuthMethod
The stashed client authentication method to use.
-
clientId
@Nullable private String clientId
The stashed client identifier for this request.
-
-
Method Detail
-
setJwtBearerExpiryOffset
public void setJwtBearerExpiryOffset(@Nonnull Duration expiry)Set the JWT expiry time offset for appropriate client authentication methods.- Parameters:
expiry- the JWT 'exp' claim offset
-
setProviderMetadataLookupStrategy
public void setProviderMetadataLookupStrategy(@Nonnull Function<MessageContext,OIDCProviderMetadataContext> strategy)Set the lookup strategy to locate the OpenID providers metadata.- Parameters:
strategy- the strategy.
-
setSecurityParametersContextLookupStrategy
public void setSecurityParametersContextLookupStrategy(@Nonnull Function<MessageContext,SecurityParametersContext> strategy)Set the strategy used to look up theSecurityParametersContext.- Parameters:
strategy- lookup strategy
-
setRelyingPartyContextLookupStrategy
public void setRelyingPartyContextLookupStrategy(@Nonnull Function<ProfileRequestContext,RelyingPartyContext> strategy)Set lookup strategy for relying party context.- Parameters:
strategy- lookup strategy
-
setOAuth2ClientAuthenticationContextLookupStrategy
public void setOAuth2ClientAuthenticationContextLookupStrategy(@Nonnull Function<MessageContext,OAuth2ClientAuthenticationContext> strgy)Set the strategy to lookup theOAuth2ClientAuthenticationContextfrom theMessageContext.- Parameters:
strgy- the strategy.
-
doPreInvoke
protected boolean doPreInvoke(@Nonnull MessageContext messageContext) throws MessageHandlerException- Overrides:
doPreInvokein classAbstractMessageHandler- Throws:
MessageHandlerException
-
doInvoke
protected void doInvoke(MessageContext messageContext) throws MessageHandlerException
- Specified by:
doInvokein classAbstractMessageHandler- Throws:
MessageHandlerException
-
verifySuitableClientSecretJWTSecurityContext
private void verifySuitableClientSecretJWTSecurityContext() throws MessageHandlerExceptionCheck the populated security context is using the correct algorithm family for client_secret_jwt client authentication.- Throws:
MessageHandlerException- if the wrong algorithm family is specified in the security context
-
verifySuitablePrivateKetJWTSecurityContext
private void verifySuitablePrivateKetJWTSecurityContext() throws MessageHandlerExceptionCheck the populated security context is using the correct algorithm family for private_key_jwt client authentication.- Throws:
MessageHandlerException- if the wrong algorithm family is specified in the security context
-
buildClientAuthenticationJwtClaims
private com.nimbusds.jwt.JWTClaimsSet buildClientAuthenticationJwtClaims()
Build the claim values required for a client authentication bearer JWT.- Returns:
- the constructed JWT claims set
-
buildClientAuthenticationJwt
@Nullable private com.nimbusds.jwt.SignedJWT buildClientAuthenticationJwt()
Build a signed JWT bearer token for client authentication using the populated security parameters. Relies on the correct alg and credential existing in the security context ahead of time for the correct SignedJWT to be returned e.g. for either client_secret_jwt or private_key_jwt.- Returns:
- a signed JWT bearer token, or
nullif there was an error during construction
-
signClaims
@Nullable private com.nimbusds.jwt.SignedJWT signClaims(@Nonnull com.nimbusds.jwt.JWTClaimsSet jwtClaimSetToSign, @Nonnull SecurityParametersContext secContext)Sign the given JWT claims set using the signing parameters from the context.- Parameters:
jwtClaimSetToSign- the claims to signsecContext- the security context to determine the signing algorithm and keys- Returns:
- a signed JWT or
nullif an error occurs.
-
getSigner
private com.nimbusds.jose.JWSSigner getSigner(com.nimbusds.jose.Algorithm jwsAlgorithm, Credential credential) throws com.nimbusds.jose.JOSEExceptionReturns correct implementation of signer based on algorithm type.- Parameters:
jwsAlgorithm- JWS algorithmcredential- the credential to use- Returns:
- signer for algorithm and private key
- Throws:
com.nimbusds.jose.JOSEException- if algorithm cannot be supported
-
resolveAlgorithm
protected com.nimbusds.jose.JWSAlgorithm resolveAlgorithm(@Nonnull SignatureSigningParameters params)Resolves JWS algorithm from signature signing parameters.- Parameters:
params- the signature signing parameters- Returns:
- JWS algorithm
-
-