[java-identity-provider] 02/02: IDP-1743 Support use of dynamic scope in AttributeDefinition
Rod Widdowson
rdw at steadingsoftware.com
Wed Feb 3 16:09:07 UTC 2021
This is an automated email from the git hooks/post-receive script.
rdw pushed a commit to branch main
in repository java-identity-provider.
View the commit online:
http://git.shibboleth.net/view/?p=java-identity-provider.git;a=commit;h=a8429a43739a970b672abf51eceb874fb859cb94
commit a8429a43739a970b672abf51eceb874fb859cb94
Author: Rod Widdowson <rdw at steadingsoftware.com>
AuthorDate: Wed Feb 3 16:08:31 2021 +0000
IDP-1743 Support use of dynamic scope in AttributeDefinition
https://issues.shibboleth.net/jira/browse/IDP-1743
Parser (and schema) changes.
---
.../ad/impl/ScopedAttributeDefinitionParser.java | 12 +++++++--
.../ad/ScopedAttributeDefinitionParserTest.java | 29 +++++++++++++++++++++-
.../resolver/spring/ad/resolver/scopedBoth.xml | 7 ++++++
.../resolver/spring/ad/resolver/scopedSource.xml | 7 ++++++
.../schema/shibboleth-attribute-resolver.xsd | 7 +++++-
5 files changed, 58 insertions(+), 4 deletions(-)
diff --git a/idp-attribute-resolver-spring/src/main/java/net/shibboleth/idp/attribute/resolver/spring/ad/impl/ScopedAttributeDefinitionParser.java b/idp-attribute-resolver-spring/src/main/java/net/shibboleth/idp/attribute/resolver/spring/ad/impl/ScopedAttributeDefinitionParser.java
index 17cab354b..dd6ffb13e 100644
--- a/idp-attribute-resolver-spring/src/main/java/net/shibboleth/idp/attribute/resolver/spring/ad/impl/ScopedAttributeDefinitionParser.java
+++ b/idp-attribute-resolver-spring/src/main/java/net/shibboleth/idp/attribute/resolver/spring/ad/impl/ScopedAttributeDefinitionParser.java
@@ -55,7 +55,15 @@ public class ScopedAttributeDefinitionParser extends BaseAttributeDefinitionPars
super.doParse(config, parserContext, builder);
final String scope = StringSupport.trimOrNull(config.getAttributeNS(null, "scope"));
- log.debug("{} Setting scope to '{}'.", getLogPrefix(), scope);
- builder.addPropertyValue("scope", scope);
+ if (scope != null) {
+ log.debug("{} Setting scope to '{}'.", getLogPrefix(), scope);
+ builder.addPropertyValue("scope", scope);
+ }
+
+ final String scopeSource = StringSupport.trimOrNull(config.getAttributeNS(null, "scopeFromDependency"));
+ if (scopeSource != null) {
+ log.debug("{} Setting scope source to '{}'.", getLogPrefix(), scopeSource);
+ builder.addPropertyValue("scopeSource", scopeSource);
+ }
}
}
\ No newline at end of file
diff --git a/idp-attribute-resolver-spring/src/test/java/net/shibboleth/idp/attribute/resolver/spring/ad/ScopedAttributeDefinitionParserTest.java b/idp-attribute-resolver-spring/src/test/java/net/shibboleth/idp/attribute/resolver/spring/ad/ScopedAttributeDefinitionParserTest.java
index 7651e1fb0..88421c0b2 100644
--- a/idp-attribute-resolver-spring/src/test/java/net/shibboleth/idp/attribute/resolver/spring/ad/ScopedAttributeDefinitionParserTest.java
+++ b/idp-attribute-resolver-spring/src/test/java/net/shibboleth/idp/attribute/resolver/spring/ad/ScopedAttributeDefinitionParserTest.java
@@ -17,6 +17,11 @@
package net.shibboleth.idp.attribute.resolver.spring.ad;
+import static org.testng.Assert.assertNull;
+import static org.testng.Assert.fail;
+
+import org.springframework.beans.factory.BeanCreationException;
+
import static org.testng.Assert.assertEquals;
import org.testng.annotations.Test;
@@ -24,16 +29,38 @@ import org.testng.annotations.Test;
import net.shibboleth.idp.attribute.resolver.ad.impl.ScopedAttributeDefinition;
import net.shibboleth.idp.attribute.resolver.spring.ad.impl.SAML1NameIdentifierAttributeDefinitionParser;
import net.shibboleth.idp.attribute.resolver.spring.testing.BaseAttributeDefinitionParserTest;
+import net.shibboleth.utilities.java.support.component.ComponentInitializationException;
/**
* Test for {@link SAML1NameIdentifierAttributeDefinitionParser}.
*/
+ at SuppressWarnings("javadoc")
public class ScopedAttributeDefinitionParserTest extends BaseAttributeDefinitionParserTest {
- @SuppressWarnings("javadoc") @Test public void defaultCase() {
+ @Test public void scope() {
ScopedAttributeDefinition attrDef = getAttributeDefn("resolver/scoped.xml", ScopedAttributeDefinition.class);
assertEquals(attrDef.getId(), "scoped");
assertEquals(attrDef.getScope(), "mYsCoPe");
+ assertNull(attrDef.getScopeSource());
+ }
+
+ @Test public void source() {
+ ScopedAttributeDefinition attrDef = getAttributeDefn("resolver/scopedSource.xml", ScopedAttributeDefinition.class);
+
+ assertEquals(attrDef.getId(), "scopedSource");
+ assertEquals(attrDef.getScopeSource(), "TheScopeSourceAttribute");
+ assertNull(attrDef.getScope());
+ }
+
+ @Test public void both() {
+ try {
+ getAttributeDefn("resolver/scopedBoth.xml", ScopedAttributeDefinition.class);
+ } catch (final BeanCreationException e) {
+ assertEquals(e.getRootCause().getClass(), ComponentInitializationException.class);
+ return;
+ }
+ fail("Did not catch impossible setup");
}
+
}
diff --git a/idp-attribute-resolver-spring/src/test/resources/net/shibboleth/idp/attribute/resolver/spring/ad/resolver/scopedBoth.xml b/idp-attribute-resolver-spring/src/test/resources/net/shibboleth/idp/attribute/resolver/spring/ad/resolver/scopedBoth.xml
new file mode 100644
index 000000000..614430602
--- /dev/null
+++ b/idp-attribute-resolver-spring/src/test/resources/net/shibboleth/idp/attribute/resolver/spring/ad/resolver/scopedBoth.xml
@@ -0,0 +1,7 @@
+<AttributeDefinition xmlns="urn:mace:shibboleth:2.0:resolver"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" scope="mYsCoPe"
+ xsi:type="Scoped" id="scoped" scopeFromDependency="TheScopeSourceAttribute"
+ xsi:schemaLocation="urn:mace:shibboleth:2.0:resolver http://shibboleth.net/schema/idp/shibboleth-attribute-resolver.xsd">
+ <InputAttributeDefinition ref="TheOrphan" />
+ <InputAttributeDefinition ref="TheScopeSourceAttribute" />
+</AttributeDefinition>
diff --git a/idp-attribute-resolver-spring/src/test/resources/net/shibboleth/idp/attribute/resolver/spring/ad/resolver/scopedSource.xml b/idp-attribute-resolver-spring/src/test/resources/net/shibboleth/idp/attribute/resolver/spring/ad/resolver/scopedSource.xml
new file mode 100644
index 000000000..8bdb7d416
--- /dev/null
+++ b/idp-attribute-resolver-spring/src/test/resources/net/shibboleth/idp/attribute/resolver/spring/ad/resolver/scopedSource.xml
@@ -0,0 +1,7 @@
+<AttributeDefinition xmlns="urn:mace:shibboleth:2.0:resolver"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" scopeFromDependency="TheScopeSourceAttribute"
+ xsi:type="Scoped" id="scopedSource"
+ xsi:schemaLocation="urn:mace:shibboleth:2.0:resolver http://shibboleth.net/schema/idp/shibboleth-attribute-resolver.xsd">
+ <InputAttributeDefinition ref="TheOrphan" />
+ <InputAttributeDefinition ref="TheScopeSourceAttribute" />
+</AttributeDefinition>
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 7fc6f0207..d4ed6073d 100644
--- a/idp-schema/src/main/resources/schema/shibboleth-attribute-resolver.xsd
+++ b/idp-schema/src/main/resources/schema/shibboleth-attribute-resolver.xsd
@@ -561,11 +561,16 @@
<element name="DisplayDescription" type="resolver:LocalizedStringType"/>
<element ref="resolver:AttributeEncoder"/>
</choice>
- <attribute name="scope" type="resolver:string" use="required">
+ <attribute name="scope" type="resolver:string">
<annotation>
<documentation>Value to use for scoping the attribute.</documentation>
</annotation>
</attribute>
+ <attribute name="scopeFromDependency" type="resolver:string">
+ <annotation>
+ <documentation>Attribute whose values will be used for scoping the attribute.</documentation>
+ </annotation>
+ </attribute>
</extension>
</complexContent>
</complexType>
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the commits
mailing list