[java-plugin-shibd] branch main updated: JSHIBD-9 - Add templated generation of issuer value
Codeberg
noreply at shibboleth.net
Tue Jun 2 20:37:25 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.
View the commit online:
https://codeberg.org/Shibboleth/java-plugin-shibd/commit/b5ae72ab7237a34c3988b5f914e7845a1ec07c63
The following commit(s) were added to refs/heads/main by this push:
new b5ae72a JSHIBD-9 - Add templated generation of issuer value
b5ae72a is described below
commit b5ae72ab7237a34c3988b5f914e7845a1ec07c63
Author: Scott Cantor <scott at restingparrotsoftware.com>
AuthorDate: Tue Jun 2 14:38:23 2026 -0400
JSHIBD-9 - Add templated generation of issuer value
https://shibboleth.atlassian.net/browse/JSHIBD-9
Implemented a generic Velocity-based lookup function.
---
.../util/TemplatedStringLookupStrategy.java | 171 +++++++++++++++++++++
.../shibboleth/sp/profile/util/package-info.java | 18 +++
2 files changed, 189 insertions(+)
diff --git a/sp-server-api/src/main/java/net/shibboleth/sp/profile/util/TemplatedStringLookupStrategy.java b/sp-server-api/src/main/java/net/shibboleth/sp/profile/util/TemplatedStringLookupStrategy.java
new file mode 100644
index 0000000..639869c
--- /dev/null
+++ b/sp-server-api/src/main/java/net/shibboleth/sp/profile/util/TemplatedStringLookupStrategy.java
@@ -0,0 +1,171 @@
+/*
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package net.shibboleth.sp.profile.util;
+
+import java.nio.charset.StandardCharsets;
+import java.util.function.Function;
+
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
+
+import org.apache.velocity.VelocityContext;
+import org.apache.velocity.app.VelocityEngine;
+import org.apache.velocity.exception.VelocityException;
+import org.opensaml.profile.context.ProfileRequestContext;
+import org.slf4j.Logger;
+
+import com.google.common.escape.Escaper;
+import com.google.common.net.UrlEscapers;
+
+import net.shibboleth.shared.annotation.constraint.NonnullAfterInit;
+import net.shibboleth.shared.annotation.constraint.NotEmpty;
+import net.shibboleth.shared.component.AbstractInitializableComponent;
+import net.shibboleth.shared.component.ComponentInitializationException;
+import net.shibboleth.shared.logic.Constraint;
+import net.shibboleth.shared.primitive.LoggerFactory;
+import net.shibboleth.shared.primitive.StringSupport;
+import net.shibboleth.shared.velocity.Template;
+import net.shibboleth.sp.context.AgentRequestContext;
+
+/**
+ * General strategy function for producing a String value from a String-based Velocity
+ * template.
+ *
+ * <p>Specialized inputs to the Velocity context are provided based on relevant inputs
+ * to operations by Agents.</p>
+ */
+public class TemplatedStringLookupStrategy extends AbstractInitializableComponent implements Function<ProfileRequestContext,String> {
+
+ /** Class logger. */
+ @Nonnull private final Logger log = LoggerFactory.getLogger(TemplatedStringLookupStrategy.class);
+
+ /** Template to be evaluated. */
+ @NonnullAfterInit private Template template;
+
+ /** Text of template to be evaluated. */
+ @NonnullAfterInit private String templateText;
+
+ /** VelocityEngine. */
+ @NonnullAfterInit private VelocityEngine engine;
+
+ /** Escaper for form parameters. */
+ @Nonnull private final Escaper paramEscaper;
+
+ /** Escaper for fragments. */
+ @Nonnull private final Escaper fragmentEscaper;
+
+ /** Escaper for path segments. */
+ @Nonnull private final Escaper pathEscaper;
+
+ /** A custom object to inject into the template. */
+ @Nullable private Object customObject;
+
+ /** Constructor. */
+ @SuppressWarnings("null")
+ public TemplatedStringLookupStrategy() {
+ paramEscaper = UrlEscapers.urlFormParameterEscaper();
+ fragmentEscaper = UrlEscapers.urlFragmentEscaper();
+ pathEscaper = UrlEscapers.urlPathSegmentEscaper();
+ }
+
+ /**
+ * Set the template to be evaluated.
+ *
+ * @param text template to be evaluated
+ */
+ public void setTemplateText(@Nullable final String text) {
+ checkSetterPreconditions();
+
+ templateText = StringSupport.trimOrNull(text);
+ }
+
+ /**
+ * Set the {@link VelocityEngine} to be used.
+ *
+ * @param velocityEngine engine to be used
+ */
+ public void setVelocityEngine(@Nonnull final VelocityEngine velocityEngine) {
+ checkSetterPreconditions();
+
+ engine = Constraint.isNotNull(velocityEngine, "Velocity engine cannot be null");
+ }
+
+
+ /**
+ * Set the custom (externally provided) object.
+ *
+ * @param object the custom object
+ */
+ public void setCustomObject(@Nullable final Object object) {
+ checkSetterPreconditions();
+
+ customObject = object;
+ }
+
+ /** {@inheritDoc} */
+ @Override protected void doInitialize() throws ComponentInitializationException {
+ super.doInitialize();
+
+ final VelocityEngine localEngine = engine;
+ final String localTemplateText = templateText;
+
+ if (null == localEngine) {
+ throw new ComponentInitializationException("Velocity engine cannot be null");
+ }
+
+ if (null == localTemplateText) {
+ throw new ComponentInitializationException("Template text cannot be null");
+ }
+
+ template = Template.fromTemplate(localEngine, localTemplateText, StandardCharsets.UTF_8);
+ }
+
+ /**
+ * Invokes {@link Template#merge(org.apache.velocity.context.Context)} on the supplied context.
+ *
+ * @param context to merge
+ *
+ * @return result of the merge operation
+ */
+ @Nonnull @NotEmpty protected String merge(@Nonnull final VelocityContext context) {
+ final String result = template.merge(context);
+ log.debug("Template text {} yields {}", templateText, result);
+ return result;
+ }
+
+ /** {@inheritDoc} */
+ @Nullable public String apply(@Nullable final ProfileRequestContext profileRequestContext) {
+
+ final VelocityContext context = new VelocityContext();
+
+ context.put("profileRequestContext", profileRequestContext);
+ context.put("paramEscaper", paramEscaper);
+ context.put("fragmentEscaper", fragmentEscaper);
+ context.put("pathEscaper", pathEscaper);
+ context.put("custom", customObject);
+
+ if (profileRequestContext != null) {
+ context.put("agentRequestContext", profileRequestContext.getSubcontext(AgentRequestContext.class));
+ }
+
+ try {
+ return merge(context);
+ } catch (final VelocityException e) {
+ log.error("Error running template engine: {}", e);
+ return null;
+ }
+ }
+
+}
\ No newline at end of file
diff --git a/sp-server-api/src/main/java/net/shibboleth/sp/profile/util/package-info.java b/sp-server-api/src/main/java/net/shibboleth/sp/profile/util/package-info.java
new file mode 100644
index 0000000..62735c1
--- /dev/null
+++ b/sp-server-api/src/main/java/net/shibboleth/sp/profile/util/package-info.java
@@ -0,0 +1,18 @@
+/*
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * Utility classes meant for external use.
+ */
+package net.shibboleth.sp.profile.util;
\ No newline at end of file
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the commits
mailing list