[java-identity-provider] branch master updated: Add inline scripting to AttributeEncoder.
Scott Cantor
cantor.2 at osu.edu
Wed May 10 17:36:27 EDT 2017
This is an automated email from the git hooks/post-receive script.
scantor pushed a commit to branch master
in repository java-identity-provider.
View the commit online:
http://git.shibboleth.net/view/?p=java-identity-provider.git;a=commit;h=86f49a1a61fb1bad6edec292bbdfb17a895ccbf6
The following commit(s) were added to refs/heads/master by this push:
new 86f49a1 Add inline scripting to AttributeEncoder.
86f49a1 is described below
commit 86f49a1a61fb1bad6edec292bbdfb17a895ccbf6
Author: Scott Cantor <cantor.2 at osu.edu>
AuthorDate: Wed May 10 17:36:25 2017 -0400
Add inline scripting to AttributeEncoder.
---
.../spring/enc/BaseAttributeEncoderParser.java | 16 ++++--
.../enc/SAML2StringAttributeEncoderParserTest.java | 12 +++++
.../resolver/spring/enc/resolver/saml2String.xml | 7 ++-
.../schema/shibboleth-attribute-resolver.xsd | 57 ++++++++++++++++++++--
4 files changed, 85 insertions(+), 7 deletions(-)
diff --git a/idp-attribute-resolver-spring/src/main/java/net/shibboleth/idp/attribute/resolver/spring/enc/BaseAttributeEncoderParser.java b/idp-attribute-resolver-spring/src/main/java/net/shibboleth/idp/attribute/resolver/spring/enc/BaseAttributeEncoderParser.java
index e06b4c0..78a8b04 100644
--- a/idp-attribute-resolver-spring/src/main/java/net/shibboleth/idp/attribute/resolver/spring/enc/BaseAttributeEncoderParser.java
+++ b/idp-attribute-resolver-spring/src/main/java/net/shibboleth/idp/attribute/resolver/spring/enc/BaseAttributeEncoderParser.java
@@ -22,9 +22,12 @@ import javax.xml.namespace.QName;
import net.shibboleth.idp.attribute.resolver.spring.enc.impl.AttributeEncoderNamespaceHandler;
import net.shibboleth.idp.attribute.resolver.spring.impl.AttributeResolverNamespaceHandler;
+import net.shibboleth.idp.profile.logic.ScriptedPredicate;
+import net.shibboleth.idp.profile.spring.relyingparty.metadata.ScriptTypeBeanParser;
import net.shibboleth.utilities.java.support.annotation.constraint.NotEmpty;
import net.shibboleth.utilities.java.support.primitive.StringSupport;
import net.shibboleth.utilities.java.support.xml.DOMTypeSupport;
+import net.shibboleth.utilities.java.support.xml.ElementSupport;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -35,7 +38,7 @@ import org.springframework.beans.factory.xml.ParserContext;
import org.w3c.dom.Element;
/**
- * Base class for Spring bean definition parser for Shibboleth attribute encoders.
+ * Base class for Spring bean definition parser for attribute encoders.
*/
public abstract class BaseAttributeEncoderParser extends AbstractSingleBeanDefinitionParser {
@@ -68,8 +71,8 @@ public abstract class BaseAttributeEncoderParser extends AbstractSingleBeanDefin
}
/** {@inheritDoc} */
- @Override protected void doParse(@Nonnull final Element config, @Nonnull final ParserContext parserContext,
- @Nonnull final BeanDefinitionBuilder builder) {
+ @Override protected void doParse(final Element config, final ParserContext parserContext,
+ final BeanDefinitionBuilder builder) {
super.doParse(config, parserContext, builder);
@@ -98,6 +101,13 @@ public abstract class BaseAttributeEncoderParser extends AbstractSingleBeanDefin
if (config.hasAttributeNS(null, "activationConditionRef")) {
builder.addPropertyReference("activationCondition",
StringSupport.trimOrNull(config.getAttributeNS(null, "activationConditionRef")));
+ } else {
+ final Element child = ElementSupport.getFirstChildElement(config);
+ if (child != null && ElementSupport.isElementNamed(child,
+ AttributeResolverNamespaceHandler.NAMESPACE, "ActivationConditionScript")) {
+ builder.addPropertyValue("activationCondition",
+ ScriptTypeBeanParser.parseScriptType(ScriptedPredicate.class, child).getBeanDefinition());
+ }
}
if (config.hasAttributeNS(null, "encodeType")) {
diff --git a/idp-attribute-resolver-spring/src/test/java/net/shibboleth/idp/attribute/resolver/spring/enc/SAML2StringAttributeEncoderParserTest.java b/idp-attribute-resolver-spring/src/test/java/net/shibboleth/idp/attribute/resolver/spring/enc/SAML2StringAttributeEncoderParserTest.java
index 60aeed9..11b9893 100644
--- a/idp-attribute-resolver-spring/src/test/java/net/shibboleth/idp/attribute/resolver/spring/enc/SAML2StringAttributeEncoderParserTest.java
+++ b/idp-attribute-resolver-spring/src/test/java/net/shibboleth/idp/attribute/resolver/spring/enc/SAML2StringAttributeEncoderParserTest.java
@@ -19,6 +19,7 @@ package net.shibboleth.idp.attribute.resolver.spring.enc;
import net.shibboleth.idp.attribute.resolver.spring.BaseAttributeDefinitionParserTest;
import net.shibboleth.idp.attribute.resolver.spring.enc.impl.SAML2StringAttributeEncoderParser;
+import net.shibboleth.idp.profile.logic.ScriptedPredicate;
import net.shibboleth.idp.saml.attribute.encoding.impl.SAML2StringAttributeEncoder;
import org.opensaml.saml.saml2.core.Attribute;
@@ -80,4 +81,15 @@ public class SAML2StringAttributeEncoderParserTest extends BaseAttributeDefiniti
Assert.assertFalse(encoder.getActivationCondition().apply(null));
}
+ @Test public void conditionalScript() {
+ final GenericApplicationContext context = new GenericApplicationContext();
+ setTestContext(context);
+
+ final SAML2StringAttributeEncoder encoder =
+ getAttributeEncoder("resolver/saml2String.xml", SAML2StringAttributeEncoder.class, context);
+
+ Assert.assertTrue(encoder.getActivationCondition() instanceof ScriptedPredicate);
+ Assert.assertFalse(encoder.getActivationCondition().apply(null));
+ }
+
}
\ No newline at end of file
diff --git a/idp-attribute-resolver-spring/src/test/resources/net/shibboleth/idp/attribute/resolver/spring/enc/resolver/saml2String.xml b/idp-attribute-resolver-spring/src/test/resources/net/shibboleth/idp/attribute/resolver/spring/enc/resolver/saml2String.xml
index fb9e761..1300dd2 100644
--- a/idp-attribute-resolver-spring/src/test/resources/net/shibboleth/idp/attribute/resolver/spring/enc/resolver/saml2String.xml
+++ b/idp-attribute-resolver-spring/src/test/resources/net/shibboleth/idp/attribute/resolver/spring/enc/resolver/saml2String.xml
@@ -5,4 +5,9 @@
name="Saml2String_ATTRIBUTE_NAME"
nameFormat="Saml2String_ATTRIBUTE_NAME_FORMAT"
friendlyName="Saml2String_ATTRIBUTE_FRIENDLY_NAME"
- xsi:schemaLocation="urn:mace:shibboleth:2.0:resolver http://shibboleth.net/schema/idp/shibboleth-attribute-resolver.xsd" />
\ No newline at end of file
+ xsi:schemaLocation="urn:mace:shibboleth:2.0:resolver http://shibboleth.net/schema/idp/shibboleth-attribute-resolver.xsd">
+
+ <ActivationConditionScript>
+ <Script>false</Script>
+ </ActivationConditionScript>
+</AttributeEncoder>
\ No newline at end of file
diff --git a/idp-schema/src/main/resources/schema/shibboleth-attribute-resolver.xsd b/idp-schema/src/main/resources/schema/shibboleth-attribute-resolver.xsd
index 21de95d..067c622 100644
--- a/idp-schema/src/main/resources/schema/shibboleth-attribute-resolver.xsd
+++ b/idp-schema/src/main/resources/schema/shibboleth-attribute-resolver.xsd
@@ -130,10 +130,20 @@
<complexType name="BaseAttributeEncoderType">
<annotation>
<documentation>
- An attribute encoder is responsible for converting an attribute, and it's values,
- into a protocol specific representation such as a SAML 1 Attribute or a SAML 2 NameID.
+ An attribute encoder is responsible for converting an attribute, and its values,
+ into a protocol specific representation such as a SAML 1 or SAML 2 Attribute.
+ The use of them to produce a SAML NameIdentifier/NameID is DEPRECATED.
</documentation>
</annotation>
+ <sequence>
+ <element name="ActivationConditionScript" type="resolver:ScriptType" minOccurs="0">
+ <annotation>
+ <documentation>
+ A scripted predicate which controls whether this encoder will run
+ </documentation>
+ </annotation>
+ </element>
+ </sequence>
<attribute name="name" type="string" />
<attribute name="encodeType" type="string">
<annotation>
@@ -146,7 +156,7 @@
<attribute name="activationConditionRef" type="string">
<annotation>
<documentation>
- The reference to a Predicate which controls whether this encoder will run
+ A reference to a Predicate which controls whether this encoder will run
</documentation>
</annotation>
</attribute>
@@ -1983,4 +1993,45 @@
</extension>
</complexContent>
</complexType>
+
+ <!-- Reusable type for inline scripting. -->
+
+ <complexType name="ScriptType">
+ <annotation>
+ <documentation>
+ A type for elements that allow for scripts to be declared inline or via a resource.
+ </documentation>
+ </annotation>
+ <choice>
+ <element name="Script" type="string">
+ <annotation>
+ <documentation>The script to evaluate to construct the attribute.</documentation>
+ </annotation>
+ </element>
+ <element name="ScriptFile" type="string">
+ <annotation>
+ <documentation>
+ Path of a local resource containing the script to evaluate to construct the attribute.
+ </documentation>
+ </annotation>
+ </element>
+ </choice>
+ <attribute name="language" type="string">
+ <annotation>
+ <documentation>
+ The JSR-233 name for the scripting language that will be used.
+ By default "javascript" is assumed.
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="customObjectRef" type="string">
+ <annotation>
+ <documentation>
+ The name of a bean defined somewhere else which will be injected into the script as an
+ object called "custom". If not supplied, nothing is injected.
+ </documentation>
+ </annotation>
+ </attribute>
+ </complexType>
+
</schema>
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the commits
mailing list