[java-plugin-shibd-saml] branch main updated: Add access resolved keys when using Velocity to generate metadata.
Codeberg
noreply at shibboleth.net
Mon Nov 16 21:16:38 UTC 2026
This is an automated email from the git hooks/post-receive script.
codeberg pushed a commit to branch main
in repository java-plugin-shibd-saml.
View the commit online:
https://codeberg.org/Shibboleth/java-plugin-shibd-saml/commit/59d4a069bfee58dd612095a8e834cd37a82cd6bd
The following commit(s) were added to refs/heads/main by this push:
new 59d4a06 Add access resolved keys when using Velocity to generate metadata.
59d4a06 is described below
commit 59d4a069bfee58dd612095a8e834cd37a82cd6bd
Author: Scott Cantor <scott at restingparrotsoftware.com>
AuthorDate: Mon Nov 16 16:15:46 2026 -0500
Add access resolved keys when using Velocity to generate metadata.
---
.../MetadataPublishingProfileConfiguration.java | 20 +++-
.../idp/flows/sp/metadata/saml2/saml2-beans.xml | 1 +
.../net/shibboleth/sp/service/agent/postconfig.xml | 1 +
.../idp/module/conf/sp/saml-test-agents.xml | 1 +
.../MetadataPublishingProfileConfiguration.java | 37 ++++++-
.../sp/saml/saml2/profile/impl/AddMetadata.java | 112 ++++++++++++++++-----
.../impl/BasicSignatureSigningConfiguration.java | 6 +-
7 files changed, 146 insertions(+), 32 deletions(-)
diff --git a/sp-saml-api/src/main/java/net/shibboleth/sp/saml/saml2/profile/config/MetadataPublishingProfileConfiguration.java b/sp-saml-api/src/main/java/net/shibboleth/sp/saml/saml2/profile/config/MetadataPublishingProfileConfiguration.java
index ee71979..5adb45f 100644
--- a/sp-saml-api/src/main/java/net/shibboleth/sp/saml/saml2/profile/config/MetadataPublishingProfileConfiguration.java
+++ b/sp-saml-api/src/main/java/net/shibboleth/sp/saml/saml2/profile/config/MetadataPublishingProfileConfiguration.java
@@ -21,7 +21,9 @@ import javax.annotation.Nullable;
import org.opensaml.profile.context.ProfileRequestContext;
import org.opensaml.saml.metadata.resolver.MetadataResolver;
+import org.opensaml.saml.saml2.metadata.KeyDescriptor;
import org.opensaml.security.credential.Credential;
+import org.opensaml.security.credential.CredentialResolver;
import net.shibboleth.profile.config.ProfileConfiguration;
import net.shibboleth.shared.annotation.ConfigurationSetting;
@@ -92,9 +94,25 @@ public interface MetadataPublishingProfileConfiguration extends ProfileConfigura
*
* @return a signing credential or null
*/
- @ConfigurationSetting(name="credentialResolver")
+ @ConfigurationSetting(name="signingCredential")
@Nullable Credential getSigningCredential(@Nullable final ProfileRequestContext profileRequestContext);
+ /**
+ * Gets whether to resolve signing and encryption keys from the configured {@link CredentialResolver}
+ * to publish into the Velocity context if that feature is enabled.
+ *
+ * <p>Defaults to false.</p>
+ *
+ * <p>If true, this does not automatically remove any existing {@link KeyDescriptor} elements nor add
+ * any automatically, but provides the information to help do so.</p>
+ *
+ * @param profileRequestContext
+ *
+ * @return true iff the credentials should be resolved for Velocity to access
+ */
+ @ConfigurationSetting(name="resolveKeys")
+ boolean isResolveKeys(@Nullable final ProfileRequestContext profileRequestContext);
+
/**
* Gets the optional lifetime from which to compute and set the root element's <code>validUntil</code>
* attribute.
diff --git a/sp-saml-conf-impl/src/main/resources/META-INF/net/shibboleth/idp/flows/sp/metadata/saml2/saml2-beans.xml b/sp-saml-conf-impl/src/main/resources/META-INF/net/shibboleth/idp/flows/sp/metadata/saml2/saml2-beans.xml
index c8e51d8..9ea19b3 100644
--- a/sp-saml-conf-impl/src/main/resources/META-INF/net/shibboleth/idp/flows/sp/metadata/saml2/saml2-beans.xml
+++ b/sp-saml-conf-impl/src/main/resources/META-INF/net/shibboleth/idp/flows/sp/metadata/saml2/saml2-beans.xml
@@ -50,6 +50,7 @@
class="net.shibboleth.sp.saml.saml2.profile.impl.AddMetadata" scope="prototype"
p:velocityEngine-ref="shibboleth.VelocityEngine"
p:parserPool-ref="shibboleth.ParserPool"
+ p:credentialResolver-ref="shibboleth.sp.CredentialResolverService"
p:httpServletRequestSupplier-ref="shibboleth.RemotedHttpServletRequestSupplier" />
<bean id="SignMetadata"
diff --git a/sp-saml-conf-impl/src/main/resources/META-INF/net/shibboleth/sp/service/agent/postconfig.xml b/sp-saml-conf-impl/src/main/resources/META-INF/net/shibboleth/sp/service/agent/postconfig.xml
index 6c228a2..468c096 100644
--- a/sp-saml-conf-impl/src/main/resources/META-INF/net/shibboleth/sp/service/agent/postconfig.xml
+++ b/sp-saml-conf-impl/src/main/resources/META-INF/net/shibboleth/sp/service/agent/postconfig.xml
@@ -68,6 +68,7 @@
p:templatePath="%{sp.saml.metadata.templatePath:}"
p:useVelocity="%{sp.saml.metadata.useVelocity:false}"
p:signMetadata="%{sp.saml.metadata.sign:false}"
+ p:resolveKeys="%{sp.saml.metadata.resolveKeys:false}"
p:lifetime="%{sp.saml.metadata.lifetime:PT0S}"
p:cacheDuration="%{sp.saml.metadata.cacheDuration:PT0S}" />
diff --git a/sp-saml-conf-impl/src/test/resources/net/shibboleth/idp/module/conf/sp/saml-test-agents.xml b/sp-saml-conf-impl/src/test/resources/net/shibboleth/idp/module/conf/sp/saml-test-agents.xml
index 29b3b6c..86cc82e 100644
--- a/sp-saml-conf-impl/src/test/resources/net/shibboleth/idp/module/conf/sp/saml-test-agents.xml
+++ b/sp-saml-conf-impl/src/test/resources/net/shibboleth/idp/module/conf/sp/saml-test-agents.xml
@@ -95,6 +95,7 @@
p:useVelocity="true"
p:signMetadata="true"
p:signingCredential-ref="MetadataSigningCredential"
+ p:resolveKeys="true"
p:lifetime="P7D"
p:cacheDuration="P1D" />
</util:list>
diff --git a/sp-saml-impl/src/main/java/net/shibboleth/sp/saml/saml2/profile/config/impl/MetadataPublishingProfileConfiguration.java b/sp-saml-impl/src/main/java/net/shibboleth/sp/saml/saml2/profile/config/impl/MetadataPublishingProfileConfiguration.java
index 2c9b1ba..b9c4f35 100644
--- a/sp-saml-impl/src/main/java/net/shibboleth/sp/saml/saml2/profile/config/impl/MetadataPublishingProfileConfiguration.java
+++ b/sp-saml-impl/src/main/java/net/shibboleth/sp/saml/saml2/profile/config/impl/MetadataPublishingProfileConfiguration.java
@@ -23,6 +23,7 @@ import javax.annotation.Nullable;
import org.opensaml.profile.context.ProfileRequestContext;
import org.opensaml.security.credential.Credential;
+import org.opensaml.security.credential.CredentialResolver;
import net.shibboleth.shared.annotation.constraint.NonNegative;
import net.shibboleth.shared.annotation.constraint.NotEmpty;
@@ -51,6 +52,9 @@ public class MetadataPublishingProfileConfiguration extends AbstractConditionalP
/** Lookup strategy for signing credential. */
@Nonnull private Function<ProfileRequestContext,Credential> signingCredentialLookupStrategy;
+ /** Predicate used to determine whether to resolve keys for Velocity. */
+ @Nonnull Predicate<ProfileRequestContext> resolveKeysPredicate;
+
/** Lookup strategy for lifetime to apply via validUntil. */
@Nonnull private Function<ProfileRequestContext,Duration> lifetimeLookupStrategy;
@@ -74,6 +78,7 @@ public class MetadataPublishingProfileConfiguration extends AbstractConditionalP
useVelocityPredicate = PredicateSupport.alwaysFalse();
signMetadataPredicate = PredicateSupport.alwaysFalse();
signingCredentialLookupStrategy = FunctionSupport.constant(null);
+ resolveKeysPredicate = PredicateSupport.alwaysFalse();
lifetimeLookupStrategy = FunctionSupport.constant(null);
cacheDurationLookupStrategy = FunctionSupport.constant(null);
}
@@ -155,7 +160,8 @@ public class MetadataPublishingProfileConfiguration extends AbstractConditionalP
}
/**
- * Sets an optional Credential to use to sign the metadata if isSignMetadata(ProfileRequestContext) is true.
+ * Sets an optional {@link Credential} to use to sign the metadata if {@link #isSignMetadata(ProfileRequestContext)}
+ * is true.
*
* @param credential credential to set
*/
@@ -164,8 +170,8 @@ public class MetadataPublishingProfileConfiguration extends AbstractConditionalP
}
/**
- * Sets a lookup strategy for an optional Credential to use to sign the metadata if
- * isSignMetadata(ProfileRequestContext) is true.
+ * Sets a lookup strategy for an optional {@link Credential} to use to sign the metadata if
+ * {@link #isSignMetadata(ProfileRequestContext)} is true.
*
* @param strategy lookup strategy
*/
@@ -173,6 +179,31 @@ public class MetadataPublishingProfileConfiguration extends AbstractConditionalP
signingCredentialLookupStrategy =
Constraint.isNotNull(strategy, "Signing credential lookup strategy cannot be null");
}
+
+ /** {@inheritDoc} */
+ public boolean isResolveKeys(@Nullable final ProfileRequestContext profileRequestContext) {
+ return resolveKeysPredicate.test(profileRequestContext);
+ }
+
+ /**
+ * Sets whether to resolve signing and encryption keys from the configured {@link CredentialResolver}
+ * to publish into the Velocity context if that feature is enabled.
+ *
+ * @param flag flag to set
+ */
+ public void setResolveKeys(final boolean flag) {
+ resolveKeysPredicate = flag ? PredicateSupport.alwaysTrue() : PredicateSupport.alwaysFalse();
+ }
+
+ /**
+ * Sets a condition to determine whether to resolve signing and encryption keys from the configured
+ * {@link CredentialResolver} to publish into the Velocity context if that feature is enabled.
+ *
+ * @param condition condition to set
+ */
+ public void setResolveKeysPredicate(@Nonnull final Predicate<ProfileRequestContext> condition) {
+ resolveKeysPredicate = Constraint.isNotNull(condition, "Key resolution condition cannot be null");
+ }
/** {@inheritDoc} */
@Nullable @NonNegative public Duration getLifetime(@Nullable final ProfileRequestContext profileRequestContext) {
diff --git a/sp-saml-impl/src/main/java/net/shibboleth/sp/saml/saml2/profile/impl/AddMetadata.java b/sp-saml-impl/src/main/java/net/shibboleth/sp/saml/saml2/profile/impl/AddMetadata.java
index 1fddbd4..1df18cb 100644
--- a/sp-saml-impl/src/main/java/net/shibboleth/sp/saml/saml2/profile/impl/AddMetadata.java
+++ b/sp-saml-impl/src/main/java/net/shibboleth/sp/saml/saml2/profile/impl/AddMetadata.java
@@ -18,7 +18,6 @@ import java.io.StringReader;
import java.nio.charset.StandardCharsets;
import java.time.Duration;
import java.time.Instant;
-import java.util.Map;
import java.util.function.Function;
import javax.annotation.Nonnull;
@@ -31,12 +30,13 @@ import net.shibboleth.profile.context.navigate.IssuerLookupFunction;
import net.shibboleth.shared.annotation.constraint.NonnullAfterInit;
import net.shibboleth.shared.annotation.constraint.NonnullBeforeExec;
import net.shibboleth.shared.annotation.constraint.NotEmpty;
-import net.shibboleth.shared.collection.CollectionSupport;
import net.shibboleth.shared.component.ComponentInitializationException;
import net.shibboleth.shared.logic.Constraint;
import net.shibboleth.sp.Agent;
import net.shibboleth.sp.Application;
import net.shibboleth.sp.context.AgentRequestContext;
+import net.shibboleth.sp.criteria.AgentIDCriterion;
+import net.shibboleth.sp.criteria.ApplicationIDCriterion;
import net.shibboleth.sp.ddf.DDF;
import net.shibboleth.sp.profile.AbstractApplicationAction;
import net.shibboleth.sp.saml.saml2.SAML2ProtocolSupportService;
@@ -54,8 +54,15 @@ import org.opensaml.messaging.context.MessageContext;
import org.opensaml.profile.action.ActionSupport;
import org.opensaml.profile.action.EventIds;
import org.opensaml.profile.context.ProfileRequestContext;
+import org.opensaml.profile.criterion.ProfileRequestContextCriterion;
+import org.opensaml.saml.common.xml.SAMLConstants;
+import org.opensaml.saml.criterion.ProtocolCriterion;
import org.opensaml.saml.metadata.resolver.MetadataResolver;
import org.opensaml.saml.saml2.metadata.EntityDescriptor;
+import org.opensaml.security.credential.Credential;
+import org.opensaml.security.credential.CredentialResolver;
+import org.opensaml.security.credential.UsageType;
+import org.opensaml.security.criteria.UsageCriterion;
import org.slf4j.Logger;
import org.springframework.core.io.Resource;
import org.springframework.webflow.execution.RequestContext;
@@ -64,6 +71,7 @@ import jakarta.servlet.http.HttpServletRequest;
import net.shibboleth.shared.primitive.LoggerFactory;
import net.shibboleth.shared.resolver.CriteriaSet;
import net.shibboleth.shared.resolver.ResolverException;
+import net.shibboleth.shared.service.ReloadableService;
import net.shibboleth.shared.service.ServiceException;
import net.shibboleth.shared.service.ServiceableComponent;
import net.shibboleth.shared.velocity.Template;
@@ -109,6 +117,12 @@ public class AddMetadata extends AbstractApplicationAction {
/** The Velocity context variable name for the {@link HttpServletRequest}. */
@Nonnull @NotEmpty public static final String CONTEXT_KEY_REQUEST = "request";
+
+ /** The Velocity context variable name for the iterable signing keys. */
+ @Nonnull @NotEmpty public static final String CONTEXT_KEY_SIGNING = "signingKeys";
+
+ /** The Velocity context variable name for the iterable encryption keys. */
+ @Nonnull @NotEmpty public static final String CONTEXT_KEY_ENCRYPTION = "encryptionKeys";
/** Class logger. */
@Nonnull private Logger log = LoggerFactory.getLogger(AddMetadata.class);
@@ -119,12 +133,12 @@ public class AddMetadata extends AbstractApplicationAction {
/** Velocity engine. */
@NonnullAfterInit private VelocityEngine velocityEngine;
+ /** Source of keys to be published into the metadata. */
+ @Nullable private ReloadableService<CredentialResolver> credentialResolver;
+
/** Strategy used to obtain the request issuer value. */
@Nullable private Function<ProfileRequestContext,String> issuerLookupStrategy;
- /** Map of agent binding tokens to SAML binding constants. */
- @Nonnull private Map<String,String> inboundBindingMap;
-
/** Applicable profile configuration. */
@NonnullBeforeExec private MetadataPublishingProfileConfiguration profileConfiguration;
@@ -137,8 +151,6 @@ public class AddMetadata extends AbstractApplicationAction {
/** Constructor. */
public AddMetadata() {
issuerLookupStrategy = new IssuerLookupFunction();
-
- inboundBindingMap = CollectionSupport.emptyMap();
}
/**
@@ -164,32 +176,24 @@ public class AddMetadata extends AbstractApplicationAction {
}
/**
- * Set the strategy used to locate the issuer value to use.
+ * Sets the {@link CredentialResolver} to use for obtaining keys to export to Velocity if enabled.
*
- * @param strategy lookup strategy
+ * @param resolver
*/
- public void setIssuerLookupStrategy(@Nullable final Function<ProfileRequestContext,String> strategy) {
+ public void setCredentialResolver(@Nullable final ReloadableService<CredentialResolver> resolver) {
checkSetterPreconditions();
- issuerLookupStrategy = strategy;
+
+ credentialResolver = resolver;
}
/**
- * Set mapping of legacy binding tokens to SAML binding constants.
- *
- * <p>This is a legacy compatibility feature allowing binding-specific response endpoints to be supported.
- * Agents will supply a structure that maps endpoints to binding tokens (e.g., POST, Artifact) and this
- * mapping determines the binding constants to use in requests. This is a simplification to avoid contaminating
- * agents with SAML constants.</p>
+ * Set the strategy used to locate the issuer value to use.
*
- * @param map binding map
+ * @param strategy lookup strategy
*/
- public void setInboundBindingMap(@Nullable final Map<String,String> map) {
+ public void setIssuerLookupStrategy(@Nullable final Function<ProfileRequestContext,String> strategy) {
checkSetterPreconditions();
- if (map != null) {
- inboundBindingMap = CollectionSupport.copyToMap(map);
- } else {
- inboundBindingMap = CollectionSupport.emptyMap();
- }
+ issuerLookupStrategy = strategy;
}
/** {@inheritDoc} */
@@ -388,9 +392,69 @@ public class AddMetadata extends AbstractApplicationAction {
ctx.put(CONTEXT_KEY_ENTITY_ID, relyingPartyCtx.getRelyingPartyId());
}
+ final ReloadableService<CredentialResolver> localResolver = credentialResolver;
+ if (localResolver != null && profileConfiguration.isResolveKeys(profileRequestContext)) {
+ final CriteriaSet criteria = buildCriteriaSet(profileRequestContext);
+ criteria.add(new UsageCriterion(UsageType.SIGNING));
+
+ try (final ServiceableComponent<CredentialResolver> service = localResolver.getServiceableComponent()) {
+ final Iterable<Credential> signingKeys = service.getComponent().resolve(criteria);
+ if (signingKeys != null) {
+ ctx.put(CONTEXT_KEY_SIGNING, signingKeys);
+ }
+
+ criteria.remove(criteria.get(UsageCriterion.class));
+ criteria.add(new UsageCriterion(UsageType.ENCRYPTION));
+
+ final Iterable<Credential> encryptionKeys = service.getComponent().resolve(criteria);
+ if (encryptionKeys != null) {
+ ctx.put(CONTEXT_KEY_ENCRYPTION, encryptionKeys);
+ }
+
+ } catch (final ResolverException e) {
+ log.error("{} Error resolving keys to export to Velocity context", getLogPrefix(), e);
+ }
+ }
+
return ctx;
}
+ /**
+ * Construct initial {@link CriteriaSet} to supply to {@link CredentialResolver}.
+ *
+ * @param profileRequestContext profile request context
+ *
+ * @return criteria to use independent of usage.
+ */
+ @Nonnull private CriteriaSet buildCriteriaSet(@Nonnull final ProfileRequestContext profileRequestContext) {
+
+ final CriteriaSet criteria = new CriteriaSet(new ProfileRequestContextCriterion(profileRequestContext),
+ new ProtocolCriterion(SAMLConstants.SAML20P_NS));
+
+ // Add Agent/Application info.
+ final AgentRequestContext arc = ensureAgentRequestContext();
+ if (arc != null) {
+ final Agent agent = arc.getAgent();
+ if (agent != null) {
+ criteria.add(new AgentIDCriterion(agent));
+ }
+ final Application app = arc.getApplication();
+ if (app != null) {
+ criteria.add(new ApplicationIDCriterion(app));
+ }
+ }
+
+ final RelyingPartyContext rpc = profileRequestContext.getSubcontext(RelyingPartyContext.class);
+ if (rpc != null) {
+ final String rpid = rpc.getRelyingPartyId();
+ if (rpid != null) {
+ criteria.add(new EntityIdCriterion(rpid));
+ }
+ }
+
+ return criteria;
+ }
+
/**
* Queries the system's {@link MetadataResolver} for metadata about the issuer.
*
diff --git a/sp-saml-impl/src/main/java/net/shibboleth/sp/xmlsec/config/impl/BasicSignatureSigningConfiguration.java b/sp-saml-impl/src/main/java/net/shibboleth/sp/xmlsec/config/impl/BasicSignatureSigningConfiguration.java
index 28ecbc4..25cf49e 100644
--- a/sp-saml-impl/src/main/java/net/shibboleth/sp/xmlsec/config/impl/BasicSignatureSigningConfiguration.java
+++ b/sp-saml-impl/src/main/java/net/shibboleth/sp/xmlsec/config/impl/BasicSignatureSigningConfiguration.java
@@ -63,16 +63,14 @@ public class BasicSignatureSigningConfiguration extends org.opensaml.xmlsec.impl
/** {@inheritDoc} */
@Override
@Nonnull @Unmodifiable @NotLive public List<Credential> getSigningCredentials() {
- // TODO Auto-generated method stub
final List<Credential> hardwired = super.getSigningCredentials();
if (!hardwired.isEmpty()) {
return hardwired;
}
- // Resolve if possible using:
+ // Resolve using:
// * UsageType = SIGNING
- // * Class = X509Credential
- // * Protocol = if set
+ // * Protocol = SAML
final CriteriaSet criteria = new CriteriaSet(new UsageCriterion(UsageType.SIGNING),
new ProtocolCriterion(SAMLConstants.SAML20P_NS));
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the commits
mailing list