[java-identity-provider] branch master updated: IDP-680 Change how attribute names are specified
Rod Widdowson
rdw at steadingsoftware.com
Tue Sep 11 11:32:00 EDT 2018
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=f43258524cd33a86e6fc8ebc4aa8f23532573c2f
The following commit(s) were added to refs/heads/master by this push:
new f432585 IDP-680 Change how attribute names are specified
f432585 is described below
commit f43258524cd33a86e6fc8ebc4aa8f23532573c2f
Author: Rod Widdowson <rdw at steadingsoftware.com>
AuthorDate: Tue Sep 11 16:30:49 2018 +0100
IDP-680 Change how attribute names are specified
https://issues.shibboleth.net/jira/browse/IDP-680
---
.../spring/impl/InputDataConnectorParser.java | 40 +++++++++++++++++++---
.../resolver/spring/DependencyTypesTest.java | 15 ++++++--
.../resolver/spring/inputDataConnector1.xml | 2 +-
...tDataConnector1.xml => inputDataConnector5.xml} | 8 +++--
.../schema/shibboleth-attribute-resolver.xsd | 15 +++++++-
5 files changed, 68 insertions(+), 12 deletions(-)
diff --git a/idp-attribute-resolver-spring/src/main/java/net/shibboleth/idp/attribute/resolver/spring/impl/InputDataConnectorParser.java b/idp-attribute-resolver-spring/src/main/java/net/shibboleth/idp/attribute/resolver/spring/impl/InputDataConnectorParser.java
index 83593ce..f975774 100644
--- a/idp-attribute-resolver-spring/src/main/java/net/shibboleth/idp/attribute/resolver/spring/impl/InputDataConnectorParser.java
+++ b/idp-attribute-resolver-spring/src/main/java/net/shibboleth/idp/attribute/resolver/spring/impl/InputDataConnectorParser.java
@@ -17,20 +17,26 @@
package net.shibboleth.idp.attribute.resolver.spring.impl;
+import java.util.List;
+
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import javax.xml.namespace.QName;
+import net.shibboleth.ext.spring.util.SpringSupport;
import net.shibboleth.idp.attribute.resolver.ResolverDataConnectorDependency;
import net.shibboleth.idp.attribute.resolver.ResolverPluginDependency;
import net.shibboleth.idp.attribute.resolver.spring.ResolverPluginDependencyParser;
import net.shibboleth.utilities.java.support.primitive.StringSupport;
+import net.shibboleth.utilities.java.support.xml.ElementSupport;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.BeanCreationException;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
+import org.springframework.beans.factory.support.ManagedList;
import org.springframework.beans.factory.xml.ParserContext;
+import org.w3c.dom.Attr;
import org.w3c.dom.Element;
/** Bean definition parser for a {@link ResolverPluginDependency}. */
@@ -40,6 +46,10 @@ public class InputDataConnectorParser extends ResolverPluginDependencyParser {
@Nonnull public static final QName ELEMENT_NAME =
new QName(AttributeResolverNamespaceHandler.NAMESPACE, "InputDataConnector");
+ /** Child Element Name. */
+ @Nonnull @Deprecated public static final QName SOURCE_ATTRIBUTES =
+ new QName(AttributeResolverNamespaceHandler.NAMESPACE, "SourceAttribute");
+
/** Class logger. */
@Nonnull private final Logger log = LoggerFactory.getLogger(InputDataConnectorParser.class);
@@ -53,21 +63,41 @@ public class InputDataConnectorParser extends ResolverPluginDependencyParser {
@Nonnull final BeanDefinitionBuilder builder) {
super.doParse(config, parserContext, builder);
- final String attributes = StringSupport.trimOrNull(config.getAttributeNS(null, "attributeNames"));
+ final Attr attributes = config.getAttributeNodeNS(null, "attributeNames");
final String allAttributes = StringSupport.trimOrNull(config.getAttributeNS(null, "allAttributes"));
+ final List<Element> attributeElements = ElementSupport.getChildElements(config, SOURCE_ATTRIBUTES);
if (attributes != null) {
if (allAttributes != null) {
log.error("attributeNames and allAttributes are mutually exclusive");
throw new BeanCreationException(ELEMENT_NAME.getLocalPart()
+ ": attributeNames and allAttributes are mutually exclusive");
}
- builder.addPropertyValue("attributeNames", attributes);
+ if (!attributeElements.isEmpty()) {
+ log.error("attributeNames and <SourceAttribute> are mutually exclusive");
+ throw new BeanCreationException(ELEMENT_NAME.getLocalPart()
+ + ": attributeNames and child elements are mutually exclusive");
+ }
+ builder.addPropertyValue("attributeNames", SpringSupport.getAttributeValueAsList(attributes));
} else if (allAttributes != null) {
- builder.addPropertyValue("allAttributes", allAttributes);
+ if (!attributeElements.isEmpty()) {
+ log.error("allAttributes and <SourceAttribute> are mutually exclusive");
+ throw new BeanCreationException(ELEMENT_NAME.getLocalPart()
+ + ": attributeNames and allAttributes are mutually exclusive");
+ }
+ final BeanDefinitionBuilder boolBuilder =
+ BeanDefinitionBuilder.rootBeanDefinition(Boolean.class, "toBoolean");
+ boolBuilder.addConstructorArgValue(allAttributes);
+ builder.addPropertyValue("allAttributes", boolBuilder.getBeanDefinition());
+ } else if (!attributeElements.isEmpty()) {
+ final ManagedList<String> elementNameList = new ManagedList<>(attributeElements.size());
+ for (final Element el:attributeElements) {
+ elementNameList.add(el.getTextContent());
+ }
+ builder.addPropertyValue("attributeNames", elementNameList);
} else {
- log.error("One of attributeNames or allAttributes must be specified");
+ log.error("One of attributeNames, allAttributes or <SourceAttribute> must be specified");
throw new BeanCreationException(ELEMENT_NAME.getLocalPart()
- + ": One of attributeNames or allAttributes must be specified");
+ + ": One of attributeNames, allAttributes or <SourceAttribute> must be specified ");
}
}
diff --git a/idp-attribute-resolver-spring/src/test/java/net/shibboleth/idp/attribute/resolver/spring/DependencyTypesTest.java b/idp-attribute-resolver-spring/src/test/java/net/shibboleth/idp/attribute/resolver/spring/DependencyTypesTest.java
index c76eecc..e966c2c 100644
--- a/idp-attribute-resolver-spring/src/test/java/net/shibboleth/idp/attribute/resolver/spring/DependencyTypesTest.java
+++ b/idp-attribute-resolver-spring/src/test/java/net/shibboleth/idp/attribute/resolver/spring/DependencyTypesTest.java
@@ -31,7 +31,7 @@ import org.testng.annotations.Test;
*/
public class DependencyTypesTest extends BaseAttributeDefinitionParserTest {
- @Test public void springList() {
+ @Test public void xmlList() {
final ResolverDataConnectorDependency re = getBean(BEAN_FILE_PATH + "inputDataConnector1.xml", ResolverDataConnectorDependency.class, new GenericApplicationContext());
Assert.assertEquals(re.getDependencyPluginId(), "DC1");
@@ -41,7 +41,18 @@ public class DependencyTypesTest extends BaseAttributeDefinitionParserTest {
Assert.assertTrue(re.getAttributeNames().contains("2"));
Assert.assertTrue(re.getAttributeNames().contains("3"));
}
-
+
+ @Test public void elementList() {
+ final ResolverDataConnectorDependency re = getBean(BEAN_FILE_PATH + "inputDataConnector5.xml", ResolverDataConnectorDependency.class, new GenericApplicationContext());
+
+ Assert.assertEquals(re.getDependencyPluginId(), "DC1");
+ Assert.assertFalse(re.isAllAttributes());
+ Assert.assertEquals(re.getAttributeNames().size(), 3);
+ Assert.assertTrue(re.getAttributeNames().contains("1"));
+ Assert.assertTrue(re.getAttributeNames().contains("2"));
+ Assert.assertTrue(re.getAttributeNames().contains("3"));
+ }
+
@Test public void allAttributeDataConnector() {
final ResolverDataConnectorDependency re = getBean(BEAN_FILE_PATH + "inputDataConnector2.xml", ResolverDataConnectorDependency.class, new GenericApplicationContext());
diff --git a/idp-attribute-resolver-spring/src/test/resources/net/shibboleth/idp/attribute/resolver/spring/inputDataConnector1.xml b/idp-attribute-resolver-spring/src/test/resources/net/shibboleth/idp/attribute/resolver/spring/inputDataConnector1.xml
index ca647aa..b328c32 100644
--- a/idp-attribute-resolver-spring/src/test/resources/net/shibboleth/idp/attribute/resolver/spring/inputDataConnector1.xml
+++ b/idp-attribute-resolver-spring/src/test/resources/net/shibboleth/idp/attribute/resolver/spring/inputDataConnector1.xml
@@ -2,5 +2,5 @@
<InputDataConnector 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"
ref="DC1"
- attributeNames="#{ {'1', '2', '3'} }"
+ attributeNames="1 2 3"
/>
diff --git a/idp-attribute-resolver-spring/src/test/resources/net/shibboleth/idp/attribute/resolver/spring/inputDataConnector1.xml b/idp-attribute-resolver-spring/src/test/resources/net/shibboleth/idp/attribute/resolver/spring/inputDataConnector5.xml
similarity index 66%
copy from idp-attribute-resolver-spring/src/test/resources/net/shibboleth/idp/attribute/resolver/spring/inputDataConnector1.xml
copy to idp-attribute-resolver-spring/src/test/resources/net/shibboleth/idp/attribute/resolver/spring/inputDataConnector5.xml
index ca647aa..d829771 100644
--- a/idp-attribute-resolver-spring/src/test/resources/net/shibboleth/idp/attribute/resolver/spring/inputDataConnector1.xml
+++ b/idp-attribute-resolver-spring/src/test/resources/net/shibboleth/idp/attribute/resolver/spring/inputDataConnector5.xml
@@ -1,6 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<InputDataConnector 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"
- ref="DC1"
- attributeNames="#{ {'1', '2', '3'} }"
-/>
+ ref="DC1">
+ <SourceAttribute>1</SourceAttribute>
+ <SourceAttribute>2</SourceAttribute>
+ <SourceAttribute>3</SourceAttribute>
+</InputDataConnector>
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 f221785..1cef233 100644
--- a/idp-schema/src/main/resources/schema/shibboleth-attribute-resolver.xsd
+++ b/idp-schema/src/main/resources/schema/shibboleth-attribute-resolver.xsd
@@ -343,12 +343,25 @@
<annotation>
<documentation>
Defines a dependency on a specific Data Connector.
+
+ attributeNames is a space separated list of attribute names. Property replacement done
+ before "listification""
+
+ allAttributes means take all attributes. Property replacement done before conversion
+
+ the SourceAtttribute elementslist serves the same purpose but allows space.
+ Since spaces in attribute names are deprecated this is also deprecated
+
+ One one of the abovr are allowed.
</documentation>
</annotation>
<complexType>
<complexContent>
<extension base="resolver:PluginDependencyType">
- <attribute name="allAttributes" type="boolean"/>
+ <sequence maxOccurs="unbounded" minOccurs="0">
+ <element name="SourceAttribute" type="string"/>
+ </sequence>
+ <attribute name="allAttributes" type="string"/>
<attribute name="attributeNames" type="string"/>
</extension>
</complexContent>
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the commits
mailing list