Class SignJWTHandler
- java.lang.Object
-
- net.shibboleth.utilities.java.support.component.AbstractInitializableComponent
-
- org.opensaml.messaging.handler.AbstractMessageHandler
-
- net.shibboleth.oidc.security.impl.SignJWTHandler
-
- All Implemented Interfaces:
Component,DestructableComponent,InitializableComponent,MessageHandler
public class SignJWTHandler extends AbstractMessageHandler
Message handler that signs a JWT and sets it back to the message context via an update consumer.
-
-
Field Summary
Fields Modifier and Type Field Description private Function<MessageContext,com.nimbusds.jwt.JWTClaimsSet>claimsToSignLookupStrategyStrategy used to locate the payload to encrypt.private Credentialcredentialresolved credential.private com.nimbusds.jwt.JWTClaimsSetjwtClaimSetToSignThe claims to sign.private BiConsumer<com.nimbusds.jwt.JWT,MessageContext>jwtUpdateConsumerA consumer that takes the Signed JWT and updates the correct object inside the MessageContext.private org.slf4j.LoggerlogClass logger.private StringlogNameA friendly name to log as the subject of signing.private Function<MessageContext,SecurityParametersContext>securityParametersLookupStrategyStrategy used to locate theSecurityParametersContextto use for signing.private SignatureSigningParameterssignatureSigningParametersThe signature signing parameters.private StringtypeHeader"typ" header to insert while signing.
-
Constructor Summary
Constructors Constructor Description SignJWTHandler()Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voiddoInitialize()protected voiddoInvoke(MessageContext messageContext)protected booleandoPreInvoke(MessageContext messageContext)private com.nimbusds.jose.JWSSignergetSigner(com.nimbusds.jose.Algorithm jwsAlgorithm)Returns correct implementation of signer based on algorithm type.protected com.nimbusds.jose.JWSAlgorithmresolveAlgorithm()Resolves JWS algorithm from signature signing parameters.voidsetClaimsToSignLookupStrategy(Function<MessageContext,com.nimbusds.jwt.JWTClaimsSet> strategy)Set the strategy used to locate theJWTClaimsSetto sign.voidsetJwtUpdateConsumer(BiConsumer<com.nimbusds.jwt.JWT,MessageContext> consumer)Set the consumer used to update the MessageContext with the supplied EncryptedJWT.voidsetLogName(String name)Set the friendly name to log as the subject of signing.voidsetSecurityParametersLookupStrategy(Function<MessageContext,SecurityParametersContext> strategy)Set the strategy used to locate theSecurityParametersContextto use.voidsetTypeHeader(String type)Sets the value to be inserted as a "typ" header for the JWS.-
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, 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.
-
securityParametersLookupStrategy
@Nonnull private Function<MessageContext,SecurityParametersContext> securityParametersLookupStrategy
Strategy used to locate theSecurityParametersContextto use for signing.
-
jwtUpdateConsumer
@NonnullAfterInit private BiConsumer<com.nimbusds.jwt.JWT,MessageContext> jwtUpdateConsumer
A consumer that takes the Signed JWT and updates the correct object inside the MessageContext.
-
claimsToSignLookupStrategy
@NonnullAfterInit private Function<MessageContext,com.nimbusds.jwt.JWTClaimsSet> claimsToSignLookupStrategy
Strategy used to locate the payload to encrypt.
-
signatureSigningParameters
@Nonnull private SignatureSigningParameters signatureSigningParameters
The signature signing parameters.
-
credential
@Nullable private Credential credential
resolved credential.
-
jwtClaimSetToSign
@Nullable private com.nimbusds.jwt.JWTClaimsSet jwtClaimSetToSign
The claims to sign.
-
-
Method Detail
-
setLogName
public void setLogName(@Nonnull @NotEmpty String name)
Set the friendly name to log as the subject of signing.- Parameters:
name- the friendly name
-
doInitialize
protected void doInitialize() throws ComponentInitializationException- Overrides:
doInitializein classAbstractInitializableComponent- Throws:
ComponentInitializationException
-
setClaimsToSignLookupStrategy
public void setClaimsToSignLookupStrategy(@Nonnull Function<MessageContext,com.nimbusds.jwt.JWTClaimsSet> strategy)Set the strategy used to locate theJWTClaimsSetto sign.- Parameters:
strategy- the strategy
-
setJwtUpdateConsumer
public void setJwtUpdateConsumer(BiConsumer<com.nimbusds.jwt.JWT,MessageContext> consumer)
Set the consumer used to update the MessageContext with the supplied EncryptedJWT.- Parameters:
consumer- the consumer
-
setTypeHeader
public void setTypeHeader(@Nullable @NotEmpty String type)
Sets the value to be inserted as a "typ" header for the JWS.- Parameters:
type- header value
-
setSecurityParametersLookupStrategy
public void setSecurityParametersLookupStrategy(@Nonnull Function<MessageContext,SecurityParametersContext> strategy)Set the strategy used to locate theSecurityParametersContextto use.- Parameters:
strategy- lookup strategy
-
doPreInvoke
protected boolean doPreInvoke(@Nonnull MessageContext messageContext) throws MessageHandlerException- Overrides:
doPreInvokein classAbstractMessageHandler- Throws:
MessageHandlerException
-
doInvoke
protected void doInvoke(@Nonnull MessageContext messageContext) throws MessageHandlerException- Specified by:
doInvokein classAbstractMessageHandler- Throws:
MessageHandlerException
-
getSigner
private com.nimbusds.jose.JWSSigner getSigner(com.nimbusds.jose.Algorithm jwsAlgorithm) throws com.nimbusds.jose.JOSEExceptionReturns correct implementation of signer based on algorithm type.- Parameters:
jwsAlgorithm- JWS algorithm- Returns:
- signer for algorithm and private key
- Throws:
com.nimbusds.jose.JOSEException- if algorithm cannot be supported
-
resolveAlgorithm
protected com.nimbusds.jose.JWSAlgorithm resolveAlgorithm()
Resolves JWS algorithm from signature signing parameters.- Returns:
- JWS algorithm
-
-