[java-oidc-common] branch main updated: JCOMOIDC-104 - Enable dynamic type header naming when signing tokens
Henri Mikkonen
henri.mikkonen at iki.fi
Fri Mar 22 10:23:07 UTC 2024
This is an automated email from the git hooks/post-receive script.
hjmikkon pushed a commit to branch main
in repository java-oidc-common.
View the commit online:
http://git.shibboleth.net/view/?p=java-oidc-common.git;a=commit;h=8afb3bc4b0a2837ce7911fc4cb9032810a09dfd6
The following commit(s) were added to refs/heads/main by this push:
new 8afb3bc JCOMOIDC-104 - Enable dynamic type header naming when signing tokens
8afb3bc is described below
commit 8afb3bc4b0a2837ce7911fc4cb9032810a09dfd6
Author: Henri Mikkonen <henri.mikkonen at iki.fi>
AuthorDate: Fri Mar 22 12:22:25 2024 +0200
JCOMOIDC-104 - Enable dynamic type header naming when signing tokens
https://shibboleth.atlassian.net/browse/JCOMOIDC-104
Add typeHeaderLookupStrategy with setter and modified setTypeHeader to use that.
---
.../oidc/security/impl/SignJWTHandler.java | 28 +++++++++++++++++-----
1 file changed, 22 insertions(+), 6 deletions(-)
diff --git a/oidc-common-crypto-impl/src/main/java/net/shibboleth/oidc/security/impl/SignJWTHandler.java b/oidc-common-crypto-impl/src/main/java/net/shibboleth/oidc/security/impl/SignJWTHandler.java
index cc25c42..ab739b0 100644
--- a/oidc-common-crypto-impl/src/main/java/net/shibboleth/oidc/security/impl/SignJWTHandler.java
+++ b/oidc-common-crypto-impl/src/main/java/net/shibboleth/oidc/security/impl/SignJWTHandler.java
@@ -39,6 +39,7 @@ import net.shibboleth.shared.annotation.constraint.NonnullBeforeExec;
import net.shibboleth.shared.annotation.constraint.NotEmpty;
import net.shibboleth.shared.component.ComponentInitializationException;
import net.shibboleth.shared.logic.Constraint;
+import net.shibboleth.shared.logic.FunctionSupport;
import net.shibboleth.shared.primitive.LoggerFactory;
import net.shibboleth.shared.primitive.StringSupport;
@@ -62,9 +63,9 @@ public class SignJWTHandler extends AbstractMessageHandler {
/** The stashed claims to sign.*/
@NonnullBeforeExec private JWTClaimsSet jwtClaimSetToSign;
- /** Optional "typ" header to insert while signing. */
- @Nullable private String typeHeader;
-
+ /** Strategy used to locate the optional "typ" header to insert while signing. */
+ @Nonnull private Function<MessageContext, String> typeHeaderLookupStrategy;
+
/** A friendly name to log as the subject of signing.*/
@Nonnull @NotEmpty private String logName;
@@ -74,7 +75,8 @@ public class SignJWTHandler extends AbstractMessageHandler {
/** Constructor.*/
public SignJWTHandler() {
logName = "not-specified";
- securityParametersLookupStrategy = new ChildContextLookup<>(SecurityParametersContext.class);
+ securityParametersLookupStrategy = new ChildContextLookup<>(SecurityParametersContext.class);
+ typeHeaderLookupStrategy = FunctionSupport.constant(null);
}
/**
@@ -130,7 +132,7 @@ public class SignJWTHandler extends AbstractMessageHandler {
public void setTypeHeader(@Nullable @NotEmpty final String type) {
checkSetterPreconditions();
- typeHeader = StringSupport.trimOrNull(type);
+ typeHeaderLookupStrategy = FunctionSupport.constant(StringSupport.trimOrNull(type));
}
/**
@@ -145,7 +147,20 @@ public class SignJWTHandler extends AbstractMessageHandler {
securityParametersLookupStrategy =
Constraint.isNotNull(strategy, "SecurityParameterContext lookup strategy cannot be null");
}
-
+
+ /**
+ * Sets the strategy used to locate the optional "typ" header to insert while signing
+ *
+ * @param strategy lookup strategy
+ *
+ * @since 3.1.0
+ */
+ public void setTypeHeaderLookupStrategy(@Nonnull final Function<MessageContext, String> strategy) {
+ checkSetterPreconditions();
+
+ typeHeaderLookupStrategy = Constraint.isNotNull(strategy, "Type header lookup strategy cannot be null");
+ }
+
/** {@inheritDoc} */
@Override
protected boolean doPreInvoke(@Nonnull final MessageContext messageContext) throws MessageHandlerException {
@@ -183,6 +198,7 @@ public class SignJWTHandler extends AbstractMessageHandler {
@Override
protected void doInvoke(@Nonnull final MessageContext messageContext) throws MessageHandlerException {
+ final String typeHeader = typeHeaderLookupStrategy.apply(messageContext);
try {
assert jwtClaimSetToSign != null;
final SignedJWT signedJWT = signer.sign(jwtClaimSetToSign, typeHeader);
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the commits
mailing list