[java-opensaml] 02/02: IDP-1217 Add support for reqt-attr:RequestedAttributes

Rod Widdowson rdw at steadingsoftware.com
Sat May 12 05:18:07 EDT 2018


This is an automated email from the git hooks/post-receive script.

rdw pushed a commit to branch master
in repository java-opensaml.

View the commit online:
http://git.shibboleth.net/view/?p=java-opensaml.git;a=commit;h=2c77472c44bc10913ccd2b0eaa5099c52d59aad8

commit 2c77472c44bc10913ccd2b0eaa5099c52d59aad8
Author: Rod Widdowson <rdw at steadingsoftware.com>
AuthorDate: Fri May 11 17:14:59 2018 +0100

    IDP-1217 Add support for reqt-attr:RequestedAttributes
    
    https://issues.shibboleth.net/jira/browse/IDP-1217
    
    Schema, Constants, api, XMlObjectSupport and unit tests.
---
 .../opensaml/saml/common/xml/SAMLConstants.java    |  6 ++
 .../saml/ext/reqattr/RequestedAttributes.java      | 54 ++++++++++++
 .../opensaml/saml/ext/reqattr/package-info.java    | 21 +++++
 .../main/resources/schema/sstc-req-attr-ext.xsd    | 42 ++++++++++
 .../config/impl/XMLObjectProviderInitializer.java  |  2 +
 .../reqattr/impl/RequestedAttributesBuilder.java   | 43 ++++++++++
 .../ext/reqattr/impl/RequestedAttributesImpl.java  | 65 +++++++++++++++
 .../impl/RequestedAttributesMarshaller.java        | 26 ++++++
 .../impl/RequestedAttributesUnmarshaller.java      | 45 ++++++++++
 .../saml/ext/reqattr/impl/package-info.java        | 21 +++++
 .../src/main/resources/saml2-req-attr-config.xml   | 17 ++++
 .../ext/reqattr/impl/RequestedAttributesTest.java  | 97 ++++++++++++++++++++++
 .../saml/ext/reqattr/impl/RequestedAttributes.xml  |  2 +
 .../impl/RequestedAttributesChildElements.xml      |  6 ++
 14 files changed, 447 insertions(+)

diff --git a/opensaml-saml-api/src/main/java/org/opensaml/saml/common/xml/SAMLConstants.java b/opensaml-saml-api/src/main/java/org/opensaml/saml/common/xml/SAMLConstants.java
index 0ed3bec..53ea02e 100644
--- a/opensaml-saml-api/src/main/java/org/opensaml/saml/common/xml/SAMLConstants.java
+++ b/opensaml-saml-api/src/main/java/org/opensaml/saml/common/xml/SAMLConstants.java
@@ -161,6 +161,12 @@ public final class SAMLConstants {
     /** SAML 2.0 Protocol Async Logout extension QName prefix. */
     public static final String SAML20PASLO_PREFIX ="aslo";
     
+    /** SAML SAML V2.0 "Protocol Extension For Requesting Attributes Per Request" namespace. */
+    public static final String SAML20PREQ_ATTR_NS = "urn:oasis:names:tc:SAML:protocol:ext:req-attr";
+
+    /** SAML SAML V2.0 "Protocol Extension For Requesting Attributes Per Request" prefix. */
+    public static final String SAML20PREQ_ATTRR_PREFIX = "req-attr";
+
     /** SAML 2.0 Metadata schema Id. */
     public static final String SAML20MD_SCHEMA_LOCATION = SCHEMA_DIR + "saml-schema-metadata-2.0.xsd";
 
diff --git a/opensaml-saml-api/src/main/java/org/opensaml/saml/ext/reqattr/RequestedAttributes.java b/opensaml-saml-api/src/main/java/org/opensaml/saml/ext/reqattr/RequestedAttributes.java
new file mode 100644
index 0000000..54bcd24
--- /dev/null
+++ b/opensaml-saml-api/src/main/java/org/opensaml/saml/ext/reqattr/RequestedAttributes.java
@@ -0,0 +1,54 @@
+/*
+ * Licensed to the University Corporation for Advanced Internet Development,
+ * Inc. (UCAID) under one or more contributor license agreements.  See the
+ * NOTICE file distributed with this work for additional information regarding
+ * copyright ownership. The UCAID licenses this file to You 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 org.opensaml.saml.ext.reqattr;
+
+import java.util.List;
+
+import javax.xml.namespace.QName;
+
+import org.opensaml.saml.common.SAMLObject;
+import org.opensaml.saml.common.xml.SAMLConstants;
+import org.opensaml.saml.saml2.metadata.RequestedAttribute;
+
+/**
+ * SAML V2.0 Protocol Extension For Requesting Attributes Per Request.
+ */
+public interface RequestedAttributes extends SAMLObject {
+
+    /** Name of the element inside the Extensions. */
+    public static final String DEFAULT_ELEMENT_LOCAL_NAME = "RequestedAttributes";
+
+    /** Default element name. */
+    public static final QName DEFAULT_ELEMENT_NAME = new QName(SAMLConstants.SAML20PREQ_ATTR_NS, 
+                    DEFAULT_ELEMENT_LOCAL_NAME, SAMLConstants.SAML20PREQ_ATTRR_PREFIX);
+
+    /** Local name of the supportsRequestedAttributes attribute. */
+    public static final String SUPPORTS_REQUESTED_ATTRIBUTES_LOCAL_NAME = "supportsRequestedAttributes";
+
+    /** QName of the XSI type. */
+    public static final QName SUPPORTS_REQUESTED_ATTRIBUTES = new QName(SAMLConstants.SAML20PREQ_ATTR_NS, 
+            SUPPORTS_REQUESTED_ATTRIBUTES_LOCAL_NAME, SAMLConstants.SAML20PREQ_ATTRR_PREFIX);
+
+    /**
+     * Gets a list of child {@link RequestedAttribute}s.
+     * 
+     * @return list of child RequestedAttribute s
+     */
+    public List<RequestedAttribute> getRequestedAttributes();
+
+}
diff --git a/opensaml-saml-api/src/main/java/org/opensaml/saml/ext/reqattr/package-info.java b/opensaml-saml-api/src/main/java/org/opensaml/saml/ext/reqattr/package-info.java
new file mode 100644
index 0000000..0d2b718
--- /dev/null
+++ b/opensaml-saml-api/src/main/java/org/opensaml/saml/ext/reqattr/package-info.java
@@ -0,0 +1,21 @@
+/*
+ * Licensed to the University Corporation for Advanced Internet Development,
+ * Inc. (UCAID) under one or more contributor license agreements.  See the
+ * NOTICE file distributed with this work for additional information regarding
+ * copyright ownership. The UCAID licenses this file to You 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.
+ */
+/**
+ * Interface for SAML V2.0 Protocol Extension For Requesting Attributes Per Request.
+ */
+
+package org.opensaml.saml.ext.reqattr;
\ No newline at end of file
diff --git a/opensaml-saml-api/src/main/resources/schema/sstc-req-attr-ext.xsd b/opensaml-saml-api/src/main/resources/schema/sstc-req-attr-ext.xsd
new file mode 100644
index 0000000..069dd83
--- /dev/null
+++ b/opensaml-saml-api/src/main/resources/schema/sstc-req-attr-ext.xsd
@@ -0,0 +1,42 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- 
+     SAML v2.0 Protocol Extension for Requesting Attributes per Request Version 1.0
+     Committee Specification 01
+     23 August 2017
+     Copyright (c) OASIS Open 2017. All Rights Reserved.
+     Source: http://docs.oasis-open.org/security/saml-protoc-req-attr-req/v1.0/cs01/schema/
+     Latest version of the specification: http://docs.oasis-open.org/security/saml-protoc-req-attr-req/v1.0/saml-protoc-req-attr-req-v1.0.html
+     TC IPR Statement: https://www.oasis-open.org/committees/security/ipr.php
+-->
+
+<schema xmlns:req-attr="urn:oasis:names:tc:SAML:protocol:ext:req-attr"
+         targetNamespace="urn:oasis:names:tc:SAML:protocol:ext:req-attr"
+         xmlns:md="urn:oasis:names:tc:SAML:2.0:metadata"
+         xmlns="http://www.w3.org/2001/XMLSchema"
+         elementFormDefault="unqualified"
+		 attributeFormDefault="unqualified"
+		 blockDefault="substitution"
+		 version="1.0">
+
+   <import namespace="urn:oasis:names:tc:SAML:2.0:metadata" schemaLocation="http://docs.oasis-open.org/security/saml/v2.0/saml-schema-metadata-2.0.xsd"/>
+
+   <annotation>
+       <documentation>
+           Document title: SAML V2.0 Protocol Extension For Requesting Attributes Per Request
+           Document identifier: sstc-req-attr-ext
+           Location: http://docs.oasis-open.org/security/saml-protoc-req-attr-req/v1.0/csprd01/schema/
+           Revision history: WD-03
+       </documentation>
+   </annotation>
+
+
+   <element name="RequestedAttributes" type="req-attr:RequestedAttributesType"/>
+
+   <complexType name="RequestedAttributesType">
+       <sequence>
+           <element ref="md:RequestedAttribute" minOccurs="1" maxOccurs="unbounded"/>
+       </sequence>
+   </complexType>
+
+   <attribute name="supportsRequestedAttributes" type="boolean"/>
+</schema>
diff --git a/opensaml-saml-impl/src/main/java/org/opensaml/saml/config/impl/XMLObjectProviderInitializer.java b/opensaml-saml-impl/src/main/java/org/opensaml/saml/config/impl/XMLObjectProviderInitializer.java
index f83810a..9b036e1 100644
--- a/opensaml-saml-impl/src/main/java/org/opensaml/saml/config/impl/XMLObjectProviderInitializer.java
+++ b/opensaml-saml-impl/src/main/java/org/opensaml/saml/config/impl/XMLObjectProviderInitializer.java
@@ -42,12 +42,14 @@ public class XMLObjectProviderInitializer extends AbstractXMLObjectProviderIniti
         "/saml2-metadata-rpi-config.xml",
         "/saml2-protocol-config.xml",
         "/saml2-protocol-thirdparty-config.xml",
+        "/saml2-req-attr-config.xml",
         "/saml2-protocol-aslo-config.xml",
         "/saml2-channel-binding-config.xml",
         "/saml-ec-gss-config.xml",
         };
 
     /** {@inheritDoc} */
+    @Override
     protected String[] getConfigResources() {
         return configs;
     }
diff --git a/opensaml-saml-impl/src/main/java/org/opensaml/saml/ext/reqattr/impl/RequestedAttributesBuilder.java b/opensaml-saml-impl/src/main/java/org/opensaml/saml/ext/reqattr/impl/RequestedAttributesBuilder.java
new file mode 100644
index 0000000..68beeed
--- /dev/null
+++ b/opensaml-saml-impl/src/main/java/org/opensaml/saml/ext/reqattr/impl/RequestedAttributesBuilder.java
@@ -0,0 +1,43 @@
+/*
+ * Licensed to the University Corporation for Advanced Internet Development,
+ * Inc. (UCAID) under one or more contributor license agreements.  See the
+ * NOTICE file distributed with this work for additional information regarding
+ * copyright ownership. The UCAID licenses this file to You 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 org.opensaml.saml.ext.reqattr.impl;
+
+import org.opensaml.saml.common.AbstractSAMLObjectBuilder;
+import org.opensaml.saml.common.xml.SAMLConstants;
+import org.opensaml.saml.ext.reqattr.RequestedAttributes;
+
+
+/**
+ * Summon up a new {@link RequestedAttributes}.
+ */
+public class RequestedAttributesBuilder extends AbstractSAMLObjectBuilder<RequestedAttributes> {
+
+    /** {@inheritDoc} */
+    @Override
+    public RequestedAttributes buildObject() {
+        return buildObject(SAMLConstants.SAML20PREQ_ATTR_NS, RequestedAttributes.DEFAULT_ELEMENT_LOCAL_NAME,
+                SAMLConstants.SAML20PREQ_ATTRR_PREFIX);
+    }
+
+    /** {@inheritDoc} */
+    @Override
+    public RequestedAttributes buildObject(final String namespaceURI, final String localName,
+            final String namespacePrefix) {
+        return new RequestedAttributesImpl(namespaceURI, localName, namespacePrefix);
+    }
+}
diff --git a/opensaml-saml-impl/src/main/java/org/opensaml/saml/ext/reqattr/impl/RequestedAttributesImpl.java b/opensaml-saml-impl/src/main/java/org/opensaml/saml/ext/reqattr/impl/RequestedAttributesImpl.java
new file mode 100644
index 0000000..0260a45
--- /dev/null
+++ b/opensaml-saml-impl/src/main/java/org/opensaml/saml/ext/reqattr/impl/RequestedAttributesImpl.java
@@ -0,0 +1,65 @@
+/*
+ * Licensed to the University Corporation for Advanced Internet Development,
+ * Inc. (UCAID) under one or more contributor license agreements.  See the
+ * NOTICE file distributed with this work for additional information regarding
+ * copyright ownership. The UCAID licenses this file to You 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 org.opensaml.saml.ext.reqattr.impl;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.opensaml.core.xml.XMLObject;
+import org.opensaml.core.xml.util.IndexedXMLObjectChildrenList;
+import org.opensaml.core.xml.util.XMLObjectChildrenList;
+import org.opensaml.saml.common.AbstractSAMLObject;
+import org.opensaml.saml.ext.reqattr.RequestedAttributes;
+import org.opensaml.saml.saml2.metadata.RequestedAttribute;
+
+
+/**
+ * A concrete {@link RequestedAttributes}.
+ */
+public class RequestedAttributesImpl extends AbstractSAMLObject implements RequestedAttributes {
+
+    /** The policies. */
+    private XMLObjectChildrenList<RequestedAttribute> requestedAttributes;
+
+    /**
+     * Constructor.
+     *
+     * @param namespaceURI the namespace the element is in
+     * @param elementLocalName the local name of the XML element this Object represents
+     * @param namespacePrefix the prefix for the given namespace
+     */
+    protected RequestedAttributesImpl(final String namespaceURI, final String elementLocalName,
+            final String namespacePrefix) {
+        super(namespaceURI, elementLocalName, namespacePrefix);
+        requestedAttributes = new IndexedXMLObjectChildrenList<>(this);
+    }
+
+    /** {@inheritDoc} */
+    @Override
+    public List<RequestedAttribute> getRequestedAttributes() {
+        return requestedAttributes;
+    }
+
+    /** {@inheritDoc} */
+    @Override
+    public List<XMLObject> getOrderedChildren() {
+        final ArrayList<XMLObject> children = new ArrayList<>();
+        children.addAll(requestedAttributes);
+        return children;
+    }
+}
diff --git a/opensaml-saml-impl/src/main/java/org/opensaml/saml/ext/reqattr/impl/RequestedAttributesMarshaller.java b/opensaml-saml-impl/src/main/java/org/opensaml/saml/ext/reqattr/impl/RequestedAttributesMarshaller.java
new file mode 100644
index 0000000..b785ee0
--- /dev/null
+++ b/opensaml-saml-impl/src/main/java/org/opensaml/saml/ext/reqattr/impl/RequestedAttributesMarshaller.java
@@ -0,0 +1,26 @@
+/*
+ * Licensed to the University Corporation for Advanced Internet Development,
+ * Inc. (UCAID) under one or more contributor license agreements.  See the
+ * NOTICE file distributed with this work for additional information regarding
+ * copyright ownership. The UCAID licenses this file to You 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 org.opensaml.saml.ext.reqattr.impl;
+
+import org.opensaml.saml.common.AbstractSAMLObjectMarshaller;
+
+/**
+ * A marshaller for {@link org.opensaml.saml.ext.reqattr.RequestedAttributes}.
+ */
+public class RequestedAttributesMarshaller extends AbstractSAMLObjectMarshaller {
+}
diff --git a/opensaml-saml-impl/src/main/java/org/opensaml/saml/ext/reqattr/impl/RequestedAttributesUnmarshaller.java b/opensaml-saml-impl/src/main/java/org/opensaml/saml/ext/reqattr/impl/RequestedAttributesUnmarshaller.java
new file mode 100644
index 0000000..bad6959
--- /dev/null
+++ b/opensaml-saml-impl/src/main/java/org/opensaml/saml/ext/reqattr/impl/RequestedAttributesUnmarshaller.java
@@ -0,0 +1,45 @@
+/*
+ * Licensed to the University Corporation for Advanced Internet Development,
+ * Inc. (UCAID) under one or more contributor license agreements.  See the
+ * NOTICE file distributed with this work for additional information regarding
+ * copyright ownership. The UCAID licenses this file to You 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 org.opensaml.saml.ext.reqattr.impl;
+
+import org.opensaml.core.xml.XMLObject;
+import org.opensaml.core.xml.io.UnmarshallingException;
+import org.opensaml.saml.common.AbstractSAMLObjectUnmarshaller;
+import org.opensaml.saml.ext.reqattr.RequestedAttributes;
+import org.opensaml.saml.saml2.metadata.RequestedAttribute;
+
+
+/**
+ * An unmarshaller for {@link RequestedAttributes}.
+ */
+public class RequestedAttributesUnmarshaller extends AbstractSAMLObjectUnmarshaller {
+
+    /** {@inheritDoc} */
+    @Override
+    protected void processChildElement(final XMLObject parentObject, final XMLObject childObject)
+            throws UnmarshallingException {
+        final RequestedAttributes pPath = (RequestedAttributes) parentObject;
+
+        if (childObject instanceof RequestedAttribute) {
+            pPath.getRequestedAttributes().add((RequestedAttribute)childObject);
+        } else {
+            super.processChildElement(parentObject, childObject);
+        }
+    }
+
+}
diff --git a/opensaml-saml-impl/src/main/java/org/opensaml/saml/ext/reqattr/impl/package-info.java b/opensaml-saml-impl/src/main/java/org/opensaml/saml/ext/reqattr/impl/package-info.java
new file mode 100644
index 0000000..70266c8
--- /dev/null
+++ b/opensaml-saml-impl/src/main/java/org/opensaml/saml/ext/reqattr/impl/package-info.java
@@ -0,0 +1,21 @@
+/*
+ * Licensed to the University Corporation for Advanced Internet Development,
+ * Inc. (UCAID) under one or more contributor license agreements.  See the
+ * NOTICE file distributed with this work for additional information regarding
+ * copyright ownership. The UCAID licenses this file to You 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.
+ */
+/**
+ * Implementations for SAML V2.0 Protocol Extension For Requesting Attributes Per Request.
+ */
+
+package org.opensaml.saml.ext.reqattr.impl;
\ No newline at end of file
diff --git a/opensaml-saml-impl/src/main/resources/saml2-req-attr-config.xml b/opensaml-saml-impl/src/main/resources/saml2-req-attr-config.xml
new file mode 100644
index 0000000..e77fcef
--- /dev/null
+++ b/opensaml-saml-impl/src/main/resources/saml2-req-attr-config.xml
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<XMLTooling xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+            xmlns:req-attr="urn:oasis:names:tc:SAML:protocol:ext:req-attr" xmlns="http://www.opensaml.org/xmltooling-config"
+            xsi:schemaLocation="http://www.opensaml.org/xmltooling-config ../../src/schema/xmltooling-config.xsd">
+
+  <!-- SAML 2.0 SAML V2.0 Protocol Extension For Requesting Attributes Per Request -->
+  <ObjectProviders>
+
+    <!-- Publication provider -->
+    <ObjectProvider qualifiedName="req-attr:RequestedAttributes">
+      <BuilderClass className="org.opensaml.saml.ext.reqattr.impl.RequestedAttributesBuilder" />
+      <MarshallingClass className="org.opensaml.saml.ext.reqattr.impl.RequestedAttributesMarshaller" />
+      <UnmarshallingClass className="org.opensaml.saml.ext.reqattr.impl.RequestedAttributesUnmarshaller" />
+    </ObjectProvider>
+ 
+  </ObjectProviders>
+</XMLTooling>
diff --git a/opensaml-saml-impl/src/test/java/org/opensaml/saml/ext/reqattr/impl/RequestedAttributesTest.java b/opensaml-saml-impl/src/test/java/org/opensaml/saml/ext/reqattr/impl/RequestedAttributesTest.java
new file mode 100644
index 0000000..105eeac
--- /dev/null
+++ b/opensaml-saml-impl/src/test/java/org/opensaml/saml/ext/reqattr/impl/RequestedAttributesTest.java
@@ -0,0 +1,97 @@
+/*
+ * Licensed to the University Corporation for Advanced Internet Development,
+ * Inc. (UCAID) under one or more contributor license agreements.  See the
+ * NOTICE file distributed with this work for additional information regarding
+ * copyright ownership. The UCAID licenses this file to You 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 org.opensaml.saml.ext.reqattr.impl;
+
+import javax.xml.namespace.QName;
+
+import org.opensaml.core.xml.XMLObjectProviderBaseTestCase;
+import org.opensaml.saml.common.xml.SAMLConstants;
+import org.opensaml.saml.ext.reqattr.RequestedAttributes;
+import org.opensaml.saml.saml2.metadata.RequestedAttribute;
+import org.opensaml.saml.saml2.metadata.impl.RequestedAttributeBuilder;
+import org.testng.Assert;
+import org.testng.annotations.Test;
+
+/**
+ * Test case for creating, marshalling, and unmarshalling
+ * {@link org.opensaml.saml.saml2.metadata.impl.RequestedAttributeImpl}.
+ */
+public class RequestedAttributesTest extends XMLObjectProviderBaseTestCase {
+
+    /** Expected Name attribute value */
+    protected final String expectedNames[] = {"attribName1", "attribName2", "attribName3"};
+
+    /**
+     * Constructor
+     */
+    public RequestedAttributesTest() {
+        singleElementFile = "/org/opensaml/saml/ext/reqattr/impl/RequestedAttributes.xml";
+        childElementsFile = "/org/opensaml/saml/ext/reqattr/impl/RequestedAttributesChildElements.xml";
+    }
+
+    /** {@inheritDoc} */
+    @Override
+    @Test
+    public void testSingleElementUnmarshall() {
+        final RequestedAttributes requestedAttributes = (RequestedAttributes) unmarshallElement(singleElementFile);
+
+        Assert.assertNotNull(requestedAttributes, "Requested Attribute Simple parse");
+
+    }
+
+    /** {@inheritDoc} */
+    @Override
+    @Test
+    public void testChildElementsUnmarshall() {
+        final RequestedAttributes requestedAttributes = (RequestedAttributes) unmarshallElement(childElementsFile);
+
+        Assert.assertEquals(requestedAttributes.getRequestedAttributes().size(), expectedNames.length);
+        
+        for (int i = 0; i < expectedNames.length; i++) {
+            Assert.assertEquals(requestedAttributes.getRequestedAttributes().get(i).getName(), expectedNames[i]);
+        }
+    }
+
+
+    /** {@inheritDoc} */
+    @Override
+    @Test
+    public void testSingleElementMarshall() {
+        final QName qname = new QName(SAMLConstants.SAML20PREQ_ATTR_NS, RequestedAttributes.DEFAULT_ELEMENT_LOCAL_NAME, SAMLConstants.SAML20PREQ_ATTRR_PREFIX);
+        final RequestedAttributes requestedAttributes = (RequestedAttributes) buildXMLObject(qname);
+
+        assertXMLEquals(expectedDOM, requestedAttributes);
+    }
+
+    /** {@inheritDoc} */
+    @Override
+    @Test
+    public void testChildElementsMarshall() {
+        final RequestedAttributes requestedAttributes = (new RequestedAttributesBuilder()).buildObject();
+        final RequestedAttributeBuilder childBuilder = new RequestedAttributeBuilder();
+        
+        for (int i = 0; i < expectedNames.length; i++) {
+            final RequestedAttribute ra = childBuilder.buildObject();
+            ra.setName(expectedNames[i]);
+            requestedAttributes.getRequestedAttributes().add(ra);
+        }
+
+        assertXMLEquals(expectedChildElementsDOM, requestedAttributes);
+    }
+    
+}
\ No newline at end of file
diff --git a/opensaml-saml-impl/src/test/resources/org/opensaml/saml/ext/reqattr/impl/RequestedAttributes.xml b/opensaml-saml-impl/src/test/resources/org/opensaml/saml/ext/reqattr/impl/RequestedAttributes.xml
new file mode 100644
index 0000000..204dc93
--- /dev/null
+++ b/opensaml-saml-impl/src/test/resources/org/opensaml/saml/ext/reqattr/impl/RequestedAttributes.xml
@@ -0,0 +1,2 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<req-attr:RequestedAttributes xmlns:req-attr="urn:oasis:names:tc:SAML:protocol:ext:req-attr"/>
diff --git a/opensaml-saml-impl/src/test/resources/org/opensaml/saml/ext/reqattr/impl/RequestedAttributesChildElements.xml b/opensaml-saml-impl/src/test/resources/org/opensaml/saml/ext/reqattr/impl/RequestedAttributesChildElements.xml
new file mode 100644
index 0000000..faead90
--- /dev/null
+++ b/opensaml-saml-impl/src/test/resources/org/opensaml/saml/ext/reqattr/impl/RequestedAttributesChildElements.xml
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<req-attr:RequestedAttributes xmlns:req-attr="urn:oasis:names:tc:SAML:protocol:ext:req-attr" xmlns:md="urn:oasis:names:tc:SAML:2.0:metadata">
+    <md:RequestedAttribute Name="attribName1"/>
+    <md:RequestedAttribute Name="attribName2"/>
+    <md:RequestedAttribute Name="attribName3"/>
+</req-attr:RequestedAttributes>

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the commits mailing list