[java-identity-provider] 03/03: IDP-1235 Add support to pre-resolve attributes
Rod Widdowson
rdw at steadingsoftware.com
Tue Sep 24 12:19:18 EDT 2019
This is an automated email from the git hooks/post-receive script.
rdw 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=6c8949c7824a4d955792e1b605c79c3381e2d619
commit 6c8949c7824a4d955792e1b605c79c3381e2d619
Author: Rod Widdowson <rdw at steadingsoftware.com>
AuthorDate: Tue Sep 24 16:56:07 2019 +0100
IDP-1235 Add support to pre-resolve attributes
https://issues.shibboleth.net/jira/browse/IDP-1235
Add spring support and a full stack test for the preresolution.
---
.../spring/ad/BaseAttributeDefinitionParser.java | 5 +++
.../resolver/spring/AttributeResolverTest.java | 40 ++++++++++++++++++++++
.../spring/ad/SimpleAttributeParserTest.java | 7 ++--
.../ad/resolver/simpleAttributePopulated.xml | 2 +-
.../ad/resolver/simpleAttributePopulated2.xml | 2 +-
.../spring/attribute-resolver-preresolve.xml | 34 ++++++++++++++++++
.../schema/shibboleth-attribute-resolver.xsd | 10 ++++++
7 files changed, 96 insertions(+), 4 deletions(-)
diff --git a/idp-attribute-resolver-spring/src/main/java/net/shibboleth/idp/attribute/resolver/spring/ad/BaseAttributeDefinitionParser.java b/idp-attribute-resolver-spring/src/main/java/net/shibboleth/idp/attribute/resolver/spring/ad/BaseAttributeDefinitionParser.java
index 6b7c771..e75993e 100644
--- a/idp-attribute-resolver-spring/src/main/java/net/shibboleth/idp/attribute/resolver/spring/ad/BaseAttributeDefinitionParser.java
+++ b/idp-attribute-resolver-spring/src/main/java/net/shibboleth/idp/attribute/resolver/spring/ad/BaseAttributeDefinitionParser.java
@@ -60,6 +60,11 @@ public abstract class BaseAttributeDefinitionParser extends BaseResolverPluginPa
log.debug("{} Setting dependencyOnly {}", getLogPrefix(), dependencyOnly);
builder.addPropertyValue("dependencyOnly", dependencyOnly);
}
+ if (config.hasAttributeNS(null, "preRequested")) {
+ final String preRequested = StringSupport.trimOrNull(config.getAttributeNS(null, "preRequested"));
+ log.debug("{} Setting preRequested {}", getLogPrefix(), preRequested);
+ builder.addPropertyValue("preRequested", preRequested);
+ }
}
/**
diff --git a/idp-attribute-resolver-spring/src/test/java/net/shibboleth/idp/attribute/resolver/spring/AttributeResolverTest.java b/idp-attribute-resolver-spring/src/test/java/net/shibboleth/idp/attribute/resolver/spring/AttributeResolverTest.java
index 19c8e25..1c25485 100644
--- a/idp-attribute-resolver-spring/src/test/java/net/shibboleth/idp/attribute/resolver/spring/AttributeResolverTest.java
+++ b/idp-attribute-resolver-spring/src/test/java/net/shibboleth/idp/attribute/resolver/spring/AttributeResolverTest.java
@@ -390,6 +390,46 @@ public class AttributeResolverTest extends OpenSAMLInitBaseTestCase {
assertTrue(resolutionContext.getResolvedIdPAttributes().isEmpty());
}
+ @Test public void preResolve() throws ResolutionException {
+ final GenericApplicationContext context = new GenericApplicationContext();
+ setTestContext(context);
+ context.setDisplayName("ApplicationContext: " + AttributeResolverTest.class);
+
+ final SchemaTypeAwareXMLBeanDefinitionReader beanDefinitionReader =
+ new SchemaTypeAwareXMLBeanDefinitionReader(context);
+
+ beanDefinitionReader.loadBeanDefinitions(new ClassPathResource(
+ "net/shibboleth/idp/attribute/resolver/spring/attribute-resolver-preresolve.xml"));
+ context.refresh();
+
+ final AttributeResolver resolver = BaseAttributeDefinitionParserTest.getResolver(context);
+ AttributeResolutionContext resolutionContext =
+ TestSources.createResolutionContext("PETER", "issuer", "recipient");
+
+ resolver.resolveAttributes(resolutionContext);
+ assertEquals(resolutionContext.getResolvedIdPAttributes().size(), 2);
+ final IdPAttribute pre = resolutionContext.getResolvedIdPAttributes().get("pre");
+ /*
+ * pre:
+ * if (null == resolutionContext.getSubcontext("net.shibboleth.idp.attribute.context.AttributeContext", false))
+ * pre.addValue("preValueOnly");
+ * else
+ pre.addValue("postValueOnly")
+ *
+ * it is preresolved so...
+ */
+ assertEquals(pre.getValues().size(), 1);
+ assertEquals(pre.getValues().get(0).getDisplayValue(), "preValueOnly");
+ final IdPAttribute postOnly = resolutionContext.getResolvedIdPAttributes().get("postOnly");
+ /*
+ * PostOnly:
+ * ac = resolutionContext.getSubcontext("net.shibboleth.idp.attribute.context.AttributeContext", false);
+ * postOnly.getValues().addAll(ac.getIdPAttributes().get("preOnly").getValues());
+ */
+ assertEquals(postOnly.getValues().size(), 1);
+ assertEquals(postOnly.getValues().get(0).getDisplayValue(), "preOnly");
+ }
+
@Test public void selectiveNavigate() throws ResolutionException {
final GenericApplicationContext context = new GenericApplicationContext();
setTestContext(context);
diff --git a/idp-attribute-resolver-spring/src/test/java/net/shibboleth/idp/attribute/resolver/spring/ad/SimpleAttributeParserTest.java b/idp-attribute-resolver-spring/src/test/java/net/shibboleth/idp/attribute/resolver/spring/ad/SimpleAttributeParserTest.java
index e21596a..26a0a82 100644
--- a/idp-attribute-resolver-spring/src/test/java/net/shibboleth/idp/attribute/resolver/spring/ad/SimpleAttributeParserTest.java
+++ b/idp-attribute-resolver-spring/src/test/java/net/shibboleth/idp/attribute/resolver/spring/ad/SimpleAttributeParserTest.java
@@ -52,7 +52,8 @@ public class SimpleAttributeParserTest extends BaseAttributeDefinitionParserTest
getAttributeDefn("resolver/simpleAttributeUnpopulated.xml", SimpleAttributeDefinition.class);
assertEquals(attrDef.getId(), "simpleUnpopulated");
- assertFalse(attrDef.isDependencyOnly(), "isDependencyOnly");
+ assertFalse(attrDef.isDependencyOnly());
+ assertFalse(attrDef.isPreRequested());
assertEquals(attrDef.getAttributeDependencies().size(), 1);
assertTrue(pendingTeardownContext.getBeansOfType(Collection.class).isEmpty());
@@ -65,7 +66,8 @@ public class SimpleAttributeParserTest extends BaseAttributeDefinitionParserTest
attrDef.initialize();
assertEquals(attrDef.getId(), "simplePopulated");
- assertTrue(attrDef.isDependencyOnly(), "isDependencyOnly");
+ assertTrue(attrDef.isDependencyOnly());
+ assertTrue(attrDef.isPreRequested());
Set<ResolverAttributeDefinitionDependency> adDeps = attrDef.getAttributeDependencies();
assertEquals(adDeps.size(), 2, "getAttributeDependencies");
@@ -87,6 +89,7 @@ public class SimpleAttributeParserTest extends BaseAttributeDefinitionParserTest
assertEquals(attrDef.getId(), "simplePopulated2");
assertFalse(attrDef.isDependencyOnly(), "isDependencyOnly");
+ assertFalse(attrDef.isPreRequested());
final Set<ResolverAttributeDefinitionDependency> attrDeps = attrDef.getAttributeDependencies();
assertEquals(attrDeps.size(), 1, "getAttributeDependencies");
diff --git a/idp-attribute-resolver-spring/src/test/resources/net/shibboleth/idp/attribute/resolver/spring/ad/resolver/simpleAttributePopulated.xml b/idp-attribute-resolver-spring/src/test/resources/net/shibboleth/idp/attribute/resolver/spring/ad/resolver/simpleAttributePopulated.xml
index b6c8c6e..add2ef6 100644
--- a/idp-attribute-resolver-spring/src/test/resources/net/shibboleth/idp/attribute/resolver/spring/ad/resolver/simpleAttributePopulated.xml
+++ b/idp-attribute-resolver-spring/src/test/resources/net/shibboleth/idp/attribute/resolver/spring/ad/resolver/simpleAttributePopulated.xml
@@ -1,7 +1,7 @@
<AttributeDefinition
xmlns="urn:mace:shibboleth:2.0:resolver"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- dependencyOnly="1"
+ dependencyOnly="1" preRequested="true"
xsi:type="Simple" id="simplePopulated"
xsi:schemaLocation="urn:mace:shibboleth:2.0:resolver http://shibboleth.net/schema/idp/shibboleth-attribute-resolver.xsd">
diff --git a/idp-attribute-resolver-spring/src/test/resources/net/shibboleth/idp/attribute/resolver/spring/ad/resolver/simpleAttributePopulated2.xml b/idp-attribute-resolver-spring/src/test/resources/net/shibboleth/idp/attribute/resolver/spring/ad/resolver/simpleAttributePopulated2.xml
index 82cf76d..bf74be0 100644
--- a/idp-attribute-resolver-spring/src/test/resources/net/shibboleth/idp/attribute/resolver/spring/ad/resolver/simpleAttributePopulated2.xml
+++ b/idp-attribute-resolver-spring/src/test/resources/net/shibboleth/idp/attribute/resolver/spring/ad/resolver/simpleAttributePopulated2.xml
@@ -1,7 +1,7 @@
<AttributeDefinition
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="urn:mace:shibboleth:2.0:resolver"
- dependencyOnly="false"
+ dependencyOnly="false" preRequested="0"
xsi:type="Simple" id="simplePopulated2"
xsi:schemaLocation="urn:mace:shibboleth:2.0:resolver http://shibboleth.net/schema/idp/shibboleth-attribute-resolver.xsd">
diff --git a/idp-attribute-resolver-spring/src/test/resources/net/shibboleth/idp/attribute/resolver/spring/attribute-resolver-preresolve.xml b/idp-attribute-resolver-spring/src/test/resources/net/shibboleth/idp/attribute/resolver/spring/attribute-resolver-preresolve.xml
new file mode 100644
index 0000000..c834a96
--- /dev/null
+++ b/idp-attribute-resolver-spring/src/test/resources/net/shibboleth/idp/attribute/resolver/spring/attribute-resolver-preresolve.xml
@@ -0,0 +1,34 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<AttributeResolver xmlns="urn:mace:shibboleth:2.0:resolver" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="urn:mace:shibboleth:2.0:resolver http://shibboleth.net/schema/idp/shibboleth-attribute-resolver.xsd">
+
+ <!-- ========================================== -->
+ <!-- Attribute Definitions -->
+ <!-- ========================================== -->
+
+ <AttributeDefinition xsi:type="ScriptedAttribute" id="preOnly" dependencyOnly="true" preRequested="true">
+ <Script>
+ if (null == resolutionContext.getSubcontext("net.shibboleth.idp.attribute.context.AttributeContext", false)) preOnly.addValue("preOnly");
+
+ </Script>
+ </AttributeDefinition>
+
+ <AttributeDefinition xsi:type="ScriptedAttribute" id="pre" preRequested="true">
+ <Script>
+ if (null == resolutionContext.getSubcontext("net.shibboleth.idp.attribute.context.AttributeContext", false))
+ pre.addValue("preValueOnly");
+ else
+ pre.addValue("postValueOnly")
+ </Script>
+ </AttributeDefinition>
+
+ <AttributeDefinition xsi:type="ScriptedAttribute" id="postOnly" >
+ <Script>
+ ac = resolutionContext.getSubcontext("net.shibboleth.idp.attribute.context.AttributeContext", false);
+ postOnly.getValues().addAll(ac.getIdPAttributes().get("preOnly").getValues());
+ </Script>
+ <InputAttributeDefinition ref="preOnly"/>
+ </AttributeDefinition>
+
+
+</AttributeResolver>
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 28df94b..9275811 100644
--- a/idp-schema/src/main/resources/schema/shibboleth-attribute-resolver.xsd
+++ b/idp-schema/src/main/resources/schema/shibboleth-attribute-resolver.xsd
@@ -61,6 +61,16 @@
</documentation>
</annotation>
</attribute>
+ <attribute name="preRequested" type="resolver:string">
+ <annotation>
+ <documentation>
+ A boolean flag that indicates whether this attribute definition and
+ its dependencies are to be resolved in a "first pass", prior to the
+ main resolution. These attributes will be populated into a child
+ context so as to be available to activationConditions.
+ </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