[java-identity-provider] 06/27: More tests and some helpers.
Scott Cantor
cantor.2 at osu.edu
Fri May 3 14:31:56 EDT 2019
This is an automated email from the git hooks/post-receive script.
scantor pushed a commit to branch feature/IDP-1434
in repository java-identity-provider.
View the commit online:
http://git.shibboleth.net/view/?p=java-identity-provider.git;a=commit;h=7ed8764ac302c0853619fe9c699318b73483047a
commit 7ed8764ac302c0853619fe9c699318b73483047a
Author: Scott Cantor <cantor.2 at osu.edu>
AuthorDate: Thu Apr 11 16:05:16 2019 -0400
More tests and some helpers.
---
.../attribute/transcoding/TranscoderSupport.java | 56 +++++++
.../impl/AttributeTranscoderRegistryImpl.java | 20 +--
.../impl/AttributeTranscoderRegistryTest.java | 31 ++--
.../impl/SAML2StringAttributeEncoderTest.java | 168 ++++++++++++++++++---
4 files changed, 223 insertions(+), 52 deletions(-)
diff --git a/idp-attribute-api/src/main/java/net/shibboleth/idp/attribute/transcoding/TranscoderSupport.java b/idp-attribute-api/src/main/java/net/shibboleth/idp/attribute/transcoding/TranscoderSupport.java
new file mode 100644
index 0000000..10df4a2
--- /dev/null
+++ b/idp-attribute-api/src/main/java/net/shibboleth/idp/attribute/transcoding/TranscoderSupport.java
@@ -0,0 +1,56 @@
+/*
+ * 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 net.shibboleth.idp.attribute.transcoding;
+
+import java.util.Properties;
+
+import javax.annotation.Nonnull;
+
+import net.shibboleth.utilities.java.support.logic.Constraint;
+import net.shibboleth.utilities.java.support.logic.ConstraintViolationException;
+
+/**
+ * Support functions for working with {@link AttributeTranscoder} framework.
+ */
+public final class TranscoderSupport {
+
+ /** Constructor. */
+ private TranscoderSupport() {
+
+ }
+
+ /**
+ * Pull an {@link AttributeTranscoder} object out of the properties provided.
+ *
+ * @param <T> type of supported target object
+ * @param ruleset transcoding rules in the form of a {@link Properties} collection
+ *
+ * @return an {@link AttributeTranscoder}
+ *
+ * @throws ConstraintViolationException if a transcoder cannot be obtained
+ */
+ @Nonnull public static <T> AttributeTranscoder<T> getTranscoder(@Nonnull final Properties ruleset)
+ throws ConstraintViolationException {
+ Constraint.isNotNull(ruleset, "Transcoding properties cannot be null");
+
+ final Object transcoder = ruleset.get(AttributeTranscoderRegistry.PROP_TRANSCODER);
+ Constraint.isTrue(transcoder instanceof AttributeTranscoder<?>, "AttributeTranscoder not found in properties");
+ return (AttributeTranscoder<T>) transcoder;
+ }
+
+}
\ No newline at end of file
diff --git a/idp-attribute-impl/src/main/java/net/shibboleth/idp/attribute/transcoding/impl/AttributeTranscoderRegistryImpl.java b/idp-attribute-impl/src/main/java/net/shibboleth/idp/attribute/transcoding/impl/AttributeTranscoderRegistryImpl.java
index 0fa1ab3..dc56e6a 100644
--- a/idp-attribute-impl/src/main/java/net/shibboleth/idp/attribute/transcoding/impl/AttributeTranscoderRegistryImpl.java
+++ b/idp-attribute-impl/src/main/java/net/shibboleth/idp/attribute/transcoding/impl/AttributeTranscoderRegistryImpl.java
@@ -244,20 +244,16 @@ public class AttributeTranscoderRegistryImpl extends AbstractServiceableComponen
*/
@Nullable private Class<?> getEffectiveType(@Nonnull final Class<?> inputType) {
- // Walk the superclass tree.
- Class<?> returnType = inputType;
- while (returnType != null && !namingFunctionRegistry.containsKey(returnType)) {
- returnType = returnType.getSuperclass();
+ // Check for explicit support.
+ if (namingFunctionRegistry.containsKey(inputType)) {
+ return inputType;
}
- if (returnType != null) {
- return returnType;
- }
-
- for (final Class<?> iface : inputType.getInterfaces()) {
- returnType = getEffectiveType(iface);
- if (returnType != null) {
- return returnType;
+ // Try each map entry for a match. Optimized around the assumption the
+ // map will be fairly small.
+ for (final Class<?> candidate : namingFunctionRegistry.keySet()) {
+ if (candidate.isAssignableFrom(inputType)) {
+ return candidate;
}
}
diff --git a/idp-attribute-impl/src/test/java/net/shibboleth/idp/attribute/transcoding/impl/AttributeTranscoderRegistryTest.java b/idp-attribute-impl/src/test/java/net/shibboleth/idp/attribute/transcoding/impl/AttributeTranscoderRegistryTest.java
index edea506..c12b30b 100644
--- a/idp-attribute-impl/src/test/java/net/shibboleth/idp/attribute/transcoding/impl/AttributeTranscoderRegistryTest.java
+++ b/idp-attribute-impl/src/test/java/net/shibboleth/idp/attribute/transcoding/impl/AttributeTranscoderRegistryTest.java
@@ -38,6 +38,7 @@ import net.shibboleth.idp.attribute.IdPAttribute;
import net.shibboleth.idp.attribute.StringAttributeValue;
import net.shibboleth.idp.attribute.transcoding.AttributeTranscoder;
import net.shibboleth.idp.attribute.transcoding.AttributeTranscoderRegistry;
+import net.shibboleth.idp.attribute.transcoding.TranscoderSupport;
import net.shibboleth.idp.attribute.transcoding.impl.AttributeTranscoderRegistryImpl;
import net.shibboleth.utilities.java.support.collection.Pair;
import net.shibboleth.utilities.java.support.component.ComponentInitializationException;
@@ -104,8 +105,7 @@ public class AttributeTranscoderRegistryTest {
final List<Pair> pairs = new ArrayList<>();
for (final Properties ruleset : registry.getTranscodingProperties(foo, Pair.class)) {
- final AttributeTranscoder<Pair> t =
- (AttributeTranscoder) ruleset.get(AttributeTranscoderRegistry.PROP_TRANSCODER);
+ final AttributeTranscoder<Pair> t = TranscoderSupport.getTranscoder(ruleset);
pairs.add(t.encode(null, foo, Pair.class, ruleset));
}
@@ -125,8 +125,7 @@ public class AttributeTranscoderRegistryTest {
final List<IdPAttribute> attributes = new ArrayList<>();
for (final Properties ruleset : registry.getTranscodingProperties(bar)) {
- final AttributeTranscoder<Pair> t =
- (AttributeTranscoder) ruleset.get(AttributeTranscoderRegistry.PROP_TRANSCODER);
+ final AttributeTranscoder<Pair> t = TranscoderSupport.getTranscoder(ruleset);
attributes.add(t.decode(null, bar, ruleset));
}
@@ -143,8 +142,7 @@ public class AttributeTranscoderRegistryTest {
final List<IdPAttribute> attributes = new ArrayList<>();
for (final Properties ruleset : registry.getTranscodingProperties(baz)) {
- final AttributeTranscoder<Pair> t =
- (AttributeTranscoder) ruleset.get(AttributeTranscoderRegistry.PROP_TRANSCODER);
+ final AttributeTranscoder<Pair> t = TranscoderSupport.getTranscoder(ruleset);
attributes.add(t.decode(null, baz, ruleset));
}
@@ -164,8 +162,7 @@ public class AttributeTranscoderRegistryTest {
final List<Pair> pairs = new ArrayList<>();
for (final Properties ruleset : registry.getTranscodingProperties(foo, Pair.class)) {
- final AttributeTranscoder<Pair> t =
- (AttributeTranscoder) ruleset.get(AttributeTranscoderRegistry.PROP_TRANSCODER);
+ final AttributeTranscoder<Pair> t = TranscoderSupport.getTranscoder(ruleset);
pairs.add(t.encode(null, foo, Pair.class, ruleset));
}
@@ -185,8 +182,7 @@ public class AttributeTranscoderRegistryTest {
final List<MyPair> pairs = new ArrayList<>();
for (final Properties ruleset : registry.getTranscodingProperties(foo, MyPair.class)) {
- final AttributeTranscoder<MyPair> t =
- (AttributeTranscoder) ruleset.get(AttributeTranscoderRegistry.PROP_TRANSCODER);
+ final AttributeTranscoder<MyPair> t = TranscoderSupport.getTranscoder(ruleset);
pairs.add(t.encode(null, foo, MyPair.class, ruleset));
}
@@ -206,8 +202,7 @@ public class AttributeTranscoderRegistryTest {
final List<IdPAttribute> attributes = new ArrayList<>();
for (final Properties ruleset : registry.getTranscodingProperties(bar)) {
- final AttributeTranscoder<Pair> t =
- (AttributeTranscoder) ruleset.get(AttributeTranscoderRegistry.PROP_TRANSCODER);
+ final AttributeTranscoder<Pair> t = TranscoderSupport.getTranscoder(ruleset);
attributes.add(t.decode(null, bar, ruleset));
}
@@ -224,8 +219,7 @@ public class AttributeTranscoderRegistryTest {
final List<IdPAttribute> attributes = new ArrayList<>();
for (final Properties ruleset : registry.getTranscodingProperties(baz)) {
- final AttributeTranscoder<Pair> t =
- (AttributeTranscoder) ruleset.get(AttributeTranscoderRegistry.PROP_TRANSCODER);
+ final AttributeTranscoder<Pair> t = TranscoderSupport.getTranscoder(ruleset);
attributes.add(t.decode(null, baz, ruleset));
}
@@ -245,8 +239,7 @@ public class AttributeTranscoderRegistryTest {
final List<Pair> pairs = new ArrayList<>();
for (final Properties ruleset : registry.getTranscodingProperties(foo, Pair.class)) {
- final AttributeTranscoder<Pair> t =
- (AttributeTranscoder) ruleset.get(AttributeTranscoderRegistry.PROP_TRANSCODER);
+ final AttributeTranscoder<Pair> t = TranscoderSupport.getTranscoder(ruleset);
pairs.add(t.encode(null, foo, Pair.class, ruleset));
}
@@ -266,8 +259,7 @@ public class AttributeTranscoderRegistryTest {
final List<IdPAttribute> attributes = new ArrayList<>();
for (final Properties ruleset : registry.getTranscodingProperties(bar)) {
- final AttributeTranscoder<Pair> t =
- (AttributeTranscoder) ruleset.get(AttributeTranscoderRegistry.PROP_TRANSCODER);
+ final AttributeTranscoder<Pair> t = TranscoderSupport.getTranscoder(ruleset);
attributes.add(t.decode(null, bar, ruleset));
}
@@ -284,8 +276,7 @@ public class AttributeTranscoderRegistryTest {
final List<IdPAttribute> attributes = new ArrayList<>();
for (final Properties ruleset : registry.getTranscodingProperties(baz)) {
- final AttributeTranscoder<Pair> t =
- (AttributeTranscoder) ruleset.get(AttributeTranscoderRegistry.PROP_TRANSCODER);
+ final AttributeTranscoder<Pair> t = TranscoderSupport.getTranscoder(ruleset);
attributes.add(t.decode(null, baz, ruleset));
}
diff --git a/idp-saml-impl/src/test/java/net/shibboleth/idp/saml/attribute/transcoding/impl/SAML2StringAttributeEncoderTest.java b/idp-saml-impl/src/test/java/net/shibboleth/idp/saml/attribute/transcoding/impl/SAML2StringAttributeEncoderTest.java
index b41146a..8a6eb2a 100644
--- a/idp-saml-impl/src/test/java/net/shibboleth/idp/saml/attribute/transcoding/impl/SAML2StringAttributeEncoderTest.java
+++ b/idp-saml-impl/src/test/java/net/shibboleth/idp/saml/attribute/transcoding/impl/SAML2StringAttributeEncoderTest.java
@@ -25,16 +25,15 @@ import java.util.List;
import java.util.Map;
import java.util.Properties;
-import javax.annotation.Nonnull;
-
import net.shibboleth.idp.attribute.AttributeEncodingException;
import net.shibboleth.idp.attribute.ByteAttributeValue;
import net.shibboleth.idp.attribute.IdPAttribute;
import net.shibboleth.idp.attribute.IdPAttributeValue;
+import net.shibboleth.idp.attribute.IdPRequestedAttribute;
import net.shibboleth.idp.attribute.ScopedStringAttributeValue;
import net.shibboleth.idp.attribute.StringAttributeValue;
-import net.shibboleth.idp.attribute.transcoding.AttributeTranscoder;
import net.shibboleth.idp.attribute.transcoding.AttributeTranscoderRegistry;
+import net.shibboleth.idp.attribute.transcoding.TranscoderSupport;
import net.shibboleth.idp.attribute.transcoding.impl.AttributeTranscoderRegistryImpl;
import net.shibboleth.idp.saml.attribute.transcoding.AbstractSAML2AttributeTranscoder;
import net.shibboleth.idp.saml.attribute.transcoding.AbstractSAMLAttributeTranscoder;
@@ -42,6 +41,7 @@ import net.shibboleth.utilities.java.support.component.ComponentInitializationEx
import org.opensaml.core.OpenSAMLInitBaseTestCase;
import org.opensaml.core.xml.XMLObject;
+import org.opensaml.core.xml.XMLObjectBuilder;
import org.opensaml.core.xml.config.XMLObjectProviderRegistrySupport;
import org.opensaml.core.xml.schema.XSString;
import org.opensaml.saml.common.SAMLObjectBuilder;
@@ -57,10 +57,12 @@ import org.testng.annotations.Test;
public class SAML2StringAttributeEncoderTest extends OpenSAMLInitBaseTestCase {
private AttributeTranscoderRegistryImpl registry;
+
+ private XMLObjectBuilder<XSString> stringBuilder;
- @Nonnull private SAMLObjectBuilder<Attribute> attributeBuilder;
+ private SAMLObjectBuilder<Attribute> attributeBuilder;
- @Nonnull private SAMLObjectBuilder<RequestedAttribute> reqAttributeBuilder;
+ private SAMLObjectBuilder<RequestedAttribute> reqAttributeBuilder;
private final static String ATTR_NAME = "foo";
private final static String ATTR_NAMEFORMAT = "Namespace";
@@ -70,6 +72,8 @@ public class SAML2StringAttributeEncoderTest extends OpenSAMLInitBaseTestCase {
@BeforeClass public void setUp() throws ComponentInitializationException {
+ stringBuilder = XMLObjectProviderRegistrySupport.getBuilderFactory().<XSString>getBuilderOrThrow(XSString.TYPE_NAME);
+
attributeBuilder = (SAMLObjectBuilder<Attribute>)
XMLObjectProviderRegistrySupport.getBuilderFactory().<Attribute>getBuilderOrThrow(
Attribute.TYPE_NAME);
@@ -114,9 +118,8 @@ public class SAML2StringAttributeEncoderTest extends OpenSAMLInitBaseTestCase {
Assert.assertEquals(rulesets.size(), 1);
final Properties ruleset = rulesets.iterator().next();
- final Attribute attr =
- ((AttributeTranscoder<Attribute>) ruleset.get(AttributeTranscoderRegistry.PROP_TRANSCODER)).encode(
- null, inputAttribute, Attribute.class, ruleset);
+ final Attribute attr = TranscoderSupport.<Attribute>getTranscoder(ruleset).encode(
+ null, inputAttribute, Attribute.class, ruleset);
Assert.assertNotNull(attr);
Assert.assertEquals(attr.getName(), ATTR_NAME);
@@ -135,15 +138,32 @@ public class SAML2StringAttributeEncoderTest extends OpenSAMLInitBaseTestCase {
Assert.assertEquals(rulesets.size(), 1);
final Properties ruleset = rulesets.iterator().next();
- final IdPAttribute attr =
- ((AttributeTranscoder<Attribute>) ruleset.get(AttributeTranscoderRegistry.PROP_TRANSCODER)).decode(
- null, samlAttribute, ruleset);
+ final IdPAttribute attr = TranscoderSupport.<Attribute>getTranscoder(ruleset).decode(null, samlAttribute, ruleset);
Assert.assertNotNull(attr);
Assert.assertEquals(attr.getId(), ATTR_NAME);
Assert.assertTrue(attr.getValues().isEmpty());
}
+ @Test public void emptyRequestedDecode() throws Exception {
+
+ final RequestedAttribute samlAttribute = reqAttributeBuilder.buildObject();
+ samlAttribute.setName(ATTR_NAME);
+ samlAttribute.setNameFormat(ATTR_NAMEFORMAT);
+ samlAttribute.setIsRequired(true);
+
+ final Collection<Properties> rulesets = registry.getTranscodingProperties(samlAttribute);
+ Assert.assertEquals(rulesets.size(), 1);
+ final Properties ruleset = rulesets.iterator().next();
+
+ final IdPAttribute attr = TranscoderSupport.<Attribute>getTranscoder(ruleset).decode(null, samlAttribute, ruleset);
+
+ Assert.assertTrue(attr instanceof IdPRequestedAttribute);
+ Assert.assertEquals(attr.getId(), ATTR_NAME);
+ Assert.assertTrue(((IdPRequestedAttribute) attr).getIsRequired());
+ Assert.assertTrue(attr.getValues().isEmpty());
+ }
+
@Test(expectedExceptions = {AttributeEncodingException.class,}) public void inappropriate() throws Exception {
final int[] intArray = {1, 2, 3, 4};
final Collection<? extends IdPAttributeValue<?>> values =
@@ -165,10 +185,9 @@ public class SAML2StringAttributeEncoderTest extends OpenSAMLInitBaseTestCase {
Assert.assertEquals(rulesets.size(), 1);
final Properties ruleset = rulesets.iterator().next();
- ((AttributeTranscoder<Attribute>) ruleset.get(AttributeTranscoderRegistry.PROP_TRANSCODER)).encode(
- null, inputAttribute, Attribute.class, ruleset);
+ TranscoderSupport.<Attribute>getTranscoder(ruleset).encode(null, inputAttribute, Attribute.class, ruleset);
}
-
+
@Test public void single() throws Exception {
final Collection<? extends IdPAttributeValue<?>> values =
Arrays.asList(new ByteAttributeValue(new byte[] {1, 2, 3,}), new StringAttributeValue(STRING_1));
@@ -180,9 +199,8 @@ public class SAML2StringAttributeEncoderTest extends OpenSAMLInitBaseTestCase {
Assert.assertEquals(rulesets.size(), 1);
final Properties ruleset = rulesets.iterator().next();
- final Attribute attr =
- ((AttributeTranscoder<Attribute>) ruleset.get(AttributeTranscoderRegistry.PROP_TRANSCODER)).encode(
- null, inputAttribute, Attribute.class, ruleset);
+ final Attribute attr = TranscoderSupport.<Attribute>getTranscoder(ruleset).encode(
+ null, inputAttribute, Attribute.class, ruleset);
Assert.assertNotNull(attr);
Assert.assertEquals(attr.getName(), ATTR_NAME);
@@ -205,6 +223,90 @@ public class SAML2StringAttributeEncoderTest extends OpenSAMLInitBaseTestCase {
Assert.assertEquals(childAsString.getValue(), STRING_1);
}
+ @Test public void singleRequested() throws Exception {
+ final Collection<? extends IdPAttributeValue<?>> values =
+ Arrays.asList(new ByteAttributeValue(new byte[] {1, 2, 3,}), new StringAttributeValue(STRING_1));
+
+ final IdPRequestedAttribute inputAttribute = new IdPRequestedAttribute(ATTR_NAME);
+ inputAttribute.setRequired(true);
+ inputAttribute.setValues(values);
+
+ final Collection<Properties> rulesets = registry.getTranscodingProperties(inputAttribute, Attribute.class);
+ Assert.assertEquals(rulesets.size(), 1);
+ final Properties ruleset = rulesets.iterator().next();
+
+ final RequestedAttribute attr = TranscoderSupport.<RequestedAttribute>getTranscoder(ruleset).encode(
+ null, inputAttribute, RequestedAttribute.class, ruleset);
+
+ Assert.assertNotNull(attr);
+ Assert.assertEquals(attr.getName(), ATTR_NAME);
+ Assert.assertEquals(attr.getNameFormat(), ATTR_NAMEFORMAT);
+ Assert.assertEquals(attr.getFriendlyName(), ATTR_FRIENDLYNAME);
+ Assert.assertTrue(attr.isRequired());
+
+ final List<XMLObject> children = attr.getOrderedChildren();
+
+ Assert.assertEquals(children.size(), 1, "Encoding one entry");
+
+ final XMLObject child = children.get(0);
+
+ Assert.assertEquals(child.getElementQName(), AttributeValue.DEFAULT_ELEMENT_NAME,
+ "Attribute Value not inside <AttributeValue/>");
+
+ Assert.assertTrue(child instanceof XSString, "Child of result attribute should be a string");
+
+ final XSString childAsString = (XSString) child;
+
+ Assert.assertEquals(childAsString.getValue(), STRING_1);
+ }
+
+ @Test public void singleDecode() throws Exception {
+
+ final XSString stringValue = stringBuilder.buildObject(AttributeValue.DEFAULT_ELEMENT_NAME);
+ stringValue.setValue(STRING_1);
+
+ final Attribute samlAttribute = attributeBuilder.buildObject();
+ samlAttribute.setName(ATTR_NAME);
+ samlAttribute.setNameFormat(ATTR_NAMEFORMAT);
+ samlAttribute.getAttributeValues().add(stringValue);
+
+ final Collection<Properties> rulesets = registry.getTranscodingProperties(samlAttribute);
+ Assert.assertEquals(rulesets.size(), 1);
+ final Properties ruleset = rulesets.iterator().next();
+
+ final IdPAttribute attr = TranscoderSupport.<Attribute>getTranscoder(ruleset).decode(null, samlAttribute, ruleset);
+
+ Assert.assertNotNull(attr);
+ Assert.assertEquals(attr.getId(), ATTR_NAME);
+ Assert.assertEquals(attr.getValues().size(), 1);
+ Assert.assertEquals(attr.getValues().get(0).getValue().toString(), STRING_1);
+ }
+
+
+ @Test public void singleRequestedDecode() throws Exception {
+
+ final XSString stringValue = stringBuilder.buildObject(AttributeValue.DEFAULT_ELEMENT_NAME);
+ stringValue.setValue(STRING_1);
+
+ final RequestedAttribute samlAttribute = reqAttributeBuilder.buildObject();
+ samlAttribute.setName(ATTR_NAME);
+ samlAttribute.setNameFormat(ATTR_NAMEFORMAT);
+ samlAttribute.setIsRequired(true);
+ samlAttribute.getAttributeValues().add(stringValue);
+
+ final Collection<Properties> rulesets = registry.getTranscodingProperties(samlAttribute);
+ Assert.assertEquals(rulesets.size(), 1);
+ final Properties ruleset = rulesets.iterator().next();
+
+ final IdPAttribute attr = TranscoderSupport.<Attribute>getTranscoder(ruleset).decode(null, samlAttribute, ruleset);
+
+ Assert.assertTrue(attr instanceof IdPRequestedAttribute);
+ Assert.assertEquals(attr.getId(), ATTR_NAME);
+ Assert.assertTrue(((IdPRequestedAttribute) attr).getIsRequired());
+ Assert.assertEquals(attr.getValues().size(), 1);
+ Assert.assertEquals(attr.getValues().get(0).getValue().toString(), STRING_1);
+ }
+
@Test public void multi() throws Exception {
final Collection<? extends IdPAttributeValue<?>> values =
Arrays.asList(new ByteAttributeValue(new byte[] {1, 2, 3,}),
@@ -219,9 +321,8 @@ public class SAML2StringAttributeEncoderTest extends OpenSAMLInitBaseTestCase {
Assert.assertEquals(rulesets.size(), 1);
final Properties ruleset = rulesets.iterator().next();
- final Attribute attr =
- ((AttributeTranscoder<Attribute>) ruleset.get(AttributeTranscoderRegistry.PROP_TRANSCODER)).encode(
- null, inputAttribute, Attribute.class, ruleset);
+ final Attribute attr = TranscoderSupport.<Attribute>getTranscoder(ruleset).encode(
+ null, inputAttribute, Attribute.class, ruleset);
Assert.assertNotNull(attr);
@@ -235,4 +336,31 @@ public class SAML2StringAttributeEncoderTest extends OpenSAMLInitBaseTestCase {
}
}
+ @Test public void multiDecode() throws Exception {
+
+ final XSString stringValue = stringBuilder.buildObject(AttributeValue.DEFAULT_ELEMENT_NAME);
+ stringValue.setValue(STRING_1);
+
+ final XSString stringValue2 = stringBuilder.buildObject(AttributeValue.DEFAULT_ELEMENT_NAME);
+ stringValue2.setValue(STRING_2);
+
+ final Attribute samlAttribute = attributeBuilder.buildObject();
+ samlAttribute.setName(ATTR_NAME);
+ samlAttribute.setNameFormat(ATTR_NAMEFORMAT);
+ samlAttribute.getAttributeValues().add(stringValue);
+ samlAttribute.getAttributeValues().add(stringValue2);
+
+ final Collection<Properties> rulesets = registry.getTranscodingProperties(samlAttribute);
+ Assert.assertEquals(rulesets.size(), 1);
+ final Properties ruleset = rulesets.iterator().next();
+
+ final IdPAttribute attr = TranscoderSupport.<Attribute>getTranscoder(ruleset).decode(null, samlAttribute, ruleset);
+
+ Assert.assertNotNull(attr);
+ Assert.assertEquals(attr.getId(), ATTR_NAME);
+ Assert.assertEquals(attr.getValues().size(), 2);
+ Assert.assertEquals(attr.getValues().get(0).getValue().toString(), STRING_1);
+ Assert.assertEquals(attr.getValues().get(1).getValue().toString(), STRING_2);
+ }
+
}
\ No newline at end of file
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the commits
mailing list