[java-identity-provider] 09/27: SAML 1 scoped support, including some amount of decoding.
Scott Cantor
cantor.2 at osu.edu
Fri May 3 14:31:59 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=8d380fe3c724f946cd0748c5c350bf3a403b723b
commit 8d380fe3c724f946cd0748c5c350bf3a403b723b
Author: Scott Cantor <cantor.2 at osu.edu>
AuthorDate: Wed Apr 17 20:17:14 2019 -0400
SAML 1 scoped support, including some amount of decoding.
---
.../AbstractSAMLAttributeTranscoder.java | 5 +
.../impl/SAML1ScopedStringAttributeTranscoder.java | 138 +++++++++++++++++++
... SAML1ScopedStringAttributeTranscoderTest.java} | 151 +++++++++++++--------
.../impl/SAML1StringAttributeTranscoderTest.java | 7 +-
.../SAML2ScopedStringAttributeTranscoderTest.java | 6 +-
.../impl/SAML2StringAttributeTranscoderTest.java | 8 +-
6 files changed, 246 insertions(+), 69 deletions(-)
diff --git a/idp-saml-api/src/main/java/net/shibboleth/idp/saml/attribute/transcoding/AbstractSAMLAttributeTranscoder.java b/idp-saml-api/src/main/java/net/shibboleth/idp/saml/attribute/transcoding/AbstractSAMLAttributeTranscoder.java
index 7722794..624e0a8 100644
--- a/idp-saml-api/src/main/java/net/shibboleth/idp/saml/attribute/transcoding/AbstractSAMLAttributeTranscoder.java
+++ b/idp-saml-api/src/main/java/net/shibboleth/idp/saml/attribute/transcoding/AbstractSAMLAttributeTranscoder.java
@@ -30,6 +30,7 @@ import net.shibboleth.idp.attribute.AttributeEncodingException;
import net.shibboleth.idp.attribute.IdPAttribute;
import net.shibboleth.idp.attribute.IdPAttributeValue;
import net.shibboleth.idp.attribute.transcoding.AbstractAttributeTranscoder;
+import net.shibboleth.idp.saml.xmlobject.ScopedValue;
import net.shibboleth.utilities.java.support.annotation.constraint.NonnullElements;
import net.shibboleth.utilities.java.support.annotation.constraint.NotEmpty;
import net.shibboleth.utilities.java.support.component.ComponentSupport;
@@ -189,6 +190,10 @@ public abstract class AbstractSAMLAttributeTranscoder<AttributeType extends SAML
} else if (object instanceof XSBase64Binary) {
retVal = ((XSBase64Binary) object).getValue();
+
+ } else if (object instanceof ScopedValue) {
+
+ retVal = ((ScopedValue) object).getValue();
} else if (object instanceof XSAny) {
diff --git a/idp-saml-impl/src/main/java/net/shibboleth/idp/saml/attribute/transcoding/impl/SAML1ScopedStringAttributeTranscoder.java b/idp-saml-impl/src/main/java/net/shibboleth/idp/saml/attribute/transcoding/impl/SAML1ScopedStringAttributeTranscoder.java
new file mode 100644
index 0000000..f4b90a5
--- /dev/null
+++ b/idp-saml-impl/src/main/java/net/shibboleth/idp/saml/attribute/transcoding/impl/SAML1ScopedStringAttributeTranscoder.java
@@ -0,0 +1,138 @@
+/*
+ * 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.saml.attribute.transcoding.impl;
+
+import java.util.Properties;
+
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
+import javax.xml.namespace.QName;
+
+import net.shibboleth.idp.attribute.AttributeEncodingException;
+import net.shibboleth.idp.attribute.IdPAttribute;
+import net.shibboleth.idp.attribute.IdPAttributeValue;
+import net.shibboleth.idp.attribute.ScopedStringAttributeValue;
+import net.shibboleth.idp.saml.attribute.encoding.SAMLEncoderSupport;
+import net.shibboleth.idp.saml.attribute.transcoding.AbstractSAML1AttributeTranscoder;
+import net.shibboleth.utilities.java.support.annotation.constraint.NotEmpty;
+
+import org.opensaml.core.xml.AttributeExtensibleXMLObject;
+import org.opensaml.core.xml.XMLObject;
+import org.opensaml.profile.context.ProfileRequestContext;
+import org.opensaml.saml.saml1.core.AttributeDesignator;
+import org.opensaml.saml.saml1.core.AttributeValue;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * {@link net.shibboleth.idp.attribute.AttributeTranscoder} that supports {@link AttributeDesignator} and
+ * {@link ScopedStringAttributeValue} objects.
+ */
+public class SAML1ScopedStringAttributeTranscoder extends AbstractSAML1AttributeTranscoder<ScopedStringAttributeValue> {
+
+ /** One of "inline" or "attribute", controlling the style of XML encoding. */
+ @Nonnull @NotEmpty public static final String PROP_SCOPE_TYPE = "scopeType";
+
+ /** Name of XML attribute when scopeType property is "attribute". */
+ @Nonnull @NotEmpty public static final String PROP_SCOPE_ATTR_NAME = "scopeAttributeName";
+
+ /** Scope delimiter when scopeType property is "inline". */
+ @Nonnull @NotEmpty public static final String PROP_SCOPE_DELIMITER = "scopeDelimiter";
+
+ /** Class logger. */
+ @Nonnull private final Logger log = LoggerFactory.getLogger(SAML1ScopedStringAttributeTranscoder.class);
+
+ /** {@inheritDoc} */
+ @Override protected boolean canEncodeValue(@Nonnull final IdPAttribute attribute,
+ @Nonnull final IdPAttributeValue value) {
+ return value instanceof ScopedStringAttributeValue;
+ }
+
+ /** {@inheritDoc} */
+ @Override @Nullable protected XMLObject encodeValue(@Nullable final ProfileRequestContext profileRequestContext,
+ @Nonnull final IdPAttribute attribute, @Nonnull final Properties properties,
+ @Nonnull final ScopedStringAttributeValue value) throws AttributeEncodingException {
+
+ final Object encodeType = properties.getOrDefault(PROP_ENCODE_TYPE, Boolean.TRUE);
+
+ final String scopeType = properties.getProperty(PROP_SCOPE_TYPE, "attribute");
+
+ if ("attribute".equals(scopeType)) {
+ final String scopeAttributeName = properties.getProperty(PROP_SCOPE_ATTR_NAME, "Scope");
+ return SAMLEncoderSupport.encodeScopedStringValueAttribute(attribute,
+ AttributeValue.DEFAULT_ELEMENT_NAME, value, scopeAttributeName,
+ encodeType instanceof Boolean ? (Boolean) encodeType : true);
+ } else if ("inline".equals(scopeType)) {
+ final String scopeDelimiter = properties.getProperty(PROP_SCOPE_DELIMITER, "@");
+ return SAMLEncoderSupport.encodeScopedStringValueInline(
+ attribute, AttributeValue.DEFAULT_ELEMENT_NAME, value, scopeDelimiter,
+ encodeType instanceof Boolean ? (Boolean) encodeType : true);
+ } else {
+ throw new AttributeEncodingException("Invalid scopeType property (must be inline or attribute)");
+ }
+ }
+
+ /** {@inheritDoc} */
+ @Override @Nullable protected IdPAttributeValue<?> decodeValue(
+ @Nullable final ProfileRequestContext profileRequestContext, @Nonnull final AttributeDesignator attribute,
+ @Nonnull final Properties properties, @Nullable final XMLObject value) {
+
+ if (value == null) {
+ return null;
+ }
+
+ final String stringValue = getStringValue(value);
+ if (null == stringValue) {
+ return null;
+ }
+
+ final String scopeType = properties.getProperty(PROP_SCOPE_TYPE, "attribute");
+ if ("attribute".equals(scopeType)) {
+
+ if (value instanceof AttributeExtensibleXMLObject) {
+ final String scopeValue = ((AttributeExtensibleXMLObject) value).getUnknownAttributes().get(
+ new QName(properties.getProperty(PROP_SCOPE_ATTR_NAME, "Scope")));
+
+ if (scopeValue == null) {
+ log.warn("Scope not found in designated XML attribute");
+ return null;
+ }
+
+ return ScopedStringAttributeValue.valueOf(stringValue, scopeValue);
+ } else {
+ log.warn("Object does not support required interface to access the scope via XML attribute");
+ return null;
+ }
+ } else if ("inline".equals(scopeType)) {
+ final String scopeDelimiter = properties.getProperty(PROP_SCOPE_DELIMITER, "@");
+ final int offset = stringValue.indexOf(scopeDelimiter);
+ if (offset < 0) {
+ log.warn("Ignoring value with no scope delimiter ({})", scopeDelimiter);
+ return null;
+ }
+
+ return ScopedStringAttributeValue.valueOf(stringValue.substring(0, offset), stringValue.substring(offset
+ + scopeDelimiter.length()));
+
+ } else {
+ log.error("Invalid scopeType property (must be inline or attribute)");
+ return null;
+ }
+ }
+
+}
\ No newline at end of file
diff --git a/idp-saml-impl/src/test/java/net/shibboleth/idp/saml/attribute/transcoding/impl/SAML1StringAttributeTranscoderTest.java b/idp-saml-impl/src/test/java/net/shibboleth/idp/saml/attribute/transcoding/impl/SAML1ScopedStringAttributeTranscoderTest.java
similarity index 69%
copy from idp-saml-impl/src/test/java/net/shibboleth/idp/saml/attribute/transcoding/impl/SAML1StringAttributeTranscoderTest.java
copy to idp-saml-impl/src/test/java/net/shibboleth/idp/saml/attribute/transcoding/impl/SAML1ScopedStringAttributeTranscoderTest.java
index d51cb90..d74d925 100644
--- a/idp-saml-impl/src/test/java/net/shibboleth/idp/saml/attribute/transcoding/impl/SAML1StringAttributeTranscoderTest.java
+++ b/idp-saml-impl/src/test/java/net/shibboleth/idp/saml/attribute/transcoding/impl/SAML1ScopedStringAttributeTranscoderTest.java
@@ -37,6 +37,7 @@ import net.shibboleth.idp.attribute.transcoding.TranscoderSupport;
import net.shibboleth.idp.attribute.transcoding.impl.AttributeTranscoderRegistryImpl;
import net.shibboleth.idp.saml.attribute.transcoding.AbstractSAML1AttributeTranscoder;
import net.shibboleth.idp.saml.attribute.transcoding.AbstractSAMLAttributeTranscoder;
+import net.shibboleth.idp.saml.xmlobject.ScopedValue;
import net.shibboleth.utilities.java.support.component.ComponentInitializationException;
import org.opensaml.core.OpenSAMLInitBaseTestCase;
@@ -46,20 +47,22 @@ import org.opensaml.core.xml.config.XMLObjectProviderRegistrySupport;
import org.opensaml.core.xml.schema.XSString;
import org.opensaml.saml.common.SAMLObjectBuilder;
import org.opensaml.saml.saml1.core.Attribute;
-import org.opensaml.saml.saml1.core.AttributeValue;
import org.opensaml.saml.saml1.core.AttributeDesignator;
+import org.opensaml.saml.saml1.core.AttributeValue;
import org.testng.Assert;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
-/** {@link SAML1StringAttributeTranscoder} unit test. */
-public class SAML1StringAttributeTranscoderTest extends OpenSAMLInitBaseTestCase {
+/** {@link SAML1ScopedStringAttributeTranscoder} unit test. */
+public class SAML1ScopedStringAttributeTranscoderTest extends OpenSAMLInitBaseTestCase {
private AttributeTranscoderRegistryImpl registry;
-
+
private XMLObjectBuilder<XSString> stringBuilder;
+ private XMLObjectBuilder<ScopedValue> scopedBuilder;
+
private SAMLObjectBuilder<Attribute> attributeBuilder;
private SAMLObjectBuilder<AttributeDesignator> designatorBuilder;
@@ -68,10 +71,17 @@ public class SAML1StringAttributeTranscoderTest extends OpenSAMLInitBaseTestCase
private final static String ATTR_NAMESPACE = "Namespace";
private final static String STRING_1 = "Value The First";
private final static String STRING_2 = "Second string the value is";
+ private final static String SCOPE_1 = "scope1.example.org";
+ private final static String SCOPE_2 = "scope2";
+ private final static String DELIMITER = "#";
@BeforeClass public void setUp() throws ComponentInitializationException {
- stringBuilder = XMLObjectProviderRegistrySupport.getBuilderFactory().<XSString>getBuilderOrThrow(XSString.TYPE_NAME);
+ stringBuilder = XMLObjectProviderRegistrySupport.getBuilderFactory().<XSString>getBuilderOrThrow(
+ XSString.TYPE_NAME);
+
+ scopedBuilder = XMLObjectProviderRegistrySupport.getBuilderFactory().<ScopedValue>getBuilderOrThrow(
+ ScopedValue.TYPE_NAME);
attributeBuilder = (SAMLObjectBuilder<Attribute>)
XMLObjectProviderRegistrySupport.getBuilderFactory().<Attribute>getBuilderOrThrow(
@@ -82,20 +92,23 @@ public class SAML1StringAttributeTranscoderTest extends OpenSAMLInitBaseTestCase
registry = new AttributeTranscoderRegistryImpl();
registry.setId("test");
-
- final SAML1StringAttributeTranscoder transcoder = new SAML1StringAttributeTranscoder();
+
+ final SAML1ScopedStringAttributeTranscoder transcoder = new SAML1ScopedStringAttributeTranscoder();
transcoder.initialize();
registry.setNamingRegistry(Collections.singletonMap(
transcoder.getEncodedType(), new AbstractSAML1AttributeTranscoder.NamingFunction()));
-
+
final Map<String,Collection<Properties>> mappings = new HashMap<>();
final Properties ruleset1 = new Properties();
ruleset1.put(AttributeTranscoderRegistry.PROP_TRANSCODER, transcoder);
ruleset1.put(AbstractSAMLAttributeTranscoder.PROP_ENCODE_TYPE, true);
ruleset1.setProperty(AbstractSAMLAttributeTranscoder.PROP_NAME, ATTR_NAME);
+ ruleset1.setProperty(AbstractSAMLAttributeTranscoder.PROP_NAME, ATTR_NAME);
ruleset1.setProperty(AbstractSAML1AttributeTranscoder.PROP_NAMESPACE, ATTR_NAMESPACE);
+ ruleset1.setProperty(SAML1ScopedStringAttributeTranscoder.PROP_SCOPE_DELIMITER, DELIMITER);
+ ruleset1.setProperty(SAML1ScopedStringAttributeTranscoder.PROP_SCOPE_TYPE, "attribute");
mappings.put(ATTR_NAME, Collections.singletonList(ruleset1));
@@ -116,28 +129,7 @@ public class SAML1StringAttributeTranscoderTest extends OpenSAMLInitBaseTestCase
Assert.assertEquals(rulesets.size(), 1);
final Properties ruleset = rulesets.iterator().next();
- final Attribute attr = TranscoderSupport.<Attribute>getTranscoder(ruleset).encode(
- null, inputAttribute, Attribute.class, ruleset);
-
- Assert.assertNotNull(attr);
- Assert.assertEquals(attr.getAttributeName(), ATTR_NAME);
- Assert.assertEquals(attr.getAttributeNamespace(), ATTR_NAMESPACE);
- Assert.assertTrue(attr.getAttributeValues().isEmpty());
- }
-
- @Test public void emptyRequestedEncode() throws Exception {
- final IdPAttribute inputAttribute = new IdPAttribute(ATTR_NAME);
-
- final Collection<Properties> rulesets = registry.getTranscodingProperties(inputAttribute, AttributeDesignator.class);
- Assert.assertEquals(rulesets.size(), 1);
- final Properties ruleset = rulesets.iterator().next();
-
- final AttributeDesignator attr = TranscoderSupport.<AttributeDesignator>getTranscoder(ruleset).encode(
- null, inputAttribute, AttributeDesignator.class, ruleset);
-
- Assert.assertNotNull(attr);
- Assert.assertEquals(attr.getAttributeName(), ATTR_NAME);
- Assert.assertEquals(attr.getAttributeNamespace(), ATTR_NAMESPACE);
+ TranscoderSupport.<Attribute>getTranscoder(ruleset).encode(null, inputAttribute, Attribute.class, ruleset);
}
@Test public void emptyDecode() throws Exception {
@@ -202,7 +194,10 @@ public class SAML1StringAttributeTranscoderTest extends OpenSAMLInitBaseTestCase
@Test public void single() throws Exception {
final Collection<? extends IdPAttributeValue<?>> values =
- Arrays.asList(new ByteAttributeValue(new byte[] {1, 2, 3,}), new StringAttributeValue(STRING_1));
+ Arrays.asList(new ByteAttributeValue(new byte[] {1, 2, 3,}),
+ new ScopedStringAttributeValue(STRING_1, SCOPE_1),
+ new StringAttributeValue(STRING_1),
+ new StringAttributeValue(STRING_1 + "@" + SCOPE_1));
final IdPAttribute inputAttribute = new IdPAttribute(ATTR_NAME);
inputAttribute.setValues(values);
@@ -227,16 +222,18 @@ public class SAML1StringAttributeTranscoderTest extends OpenSAMLInitBaseTestCase
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");
+ Assert.assertTrue(child instanceof ScopedValue, "Child of result attribute should be a string");
- final XSString childAsString = (XSString) child;
+ final ScopedValue childAsScopedValue = (ScopedValue) child;
- Assert.assertEquals(childAsString.getValue(), STRING_1);
+ Assert.assertEquals(childAsScopedValue.getValue(), STRING_1, "Input equals output");
+ Assert.assertEquals(childAsScopedValue.getScope(), SCOPE_1, "Input equals output");
}
@Test public void singleRequested() throws Exception {
final Collection<? extends IdPAttributeValue<?>> values =
- Arrays.asList(new ByteAttributeValue(new byte[] {1, 2, 3,}), new StringAttributeValue(STRING_1));
+ Arrays.asList(new ByteAttributeValue(new byte[] {1, 2, 3,}),
+ new ScopedStringAttributeValue(STRING_1, SCOPE_1));
final IdPRequestedAttribute inputAttribute = new IdPRequestedAttribute(ATTR_NAME);
inputAttribute.setValues(values);
@@ -255,13 +252,15 @@ public class SAML1StringAttributeTranscoderTest extends OpenSAMLInitBaseTestCase
@Test public void singleDecode() throws Exception {
- final XSString stringValue = stringBuilder.buildObject(AttributeValue.DEFAULT_ELEMENT_NAME);
- stringValue.setValue(STRING_1);
+ final ScopedValue scopedValue = scopedBuilder.buildObject(AttributeValue.DEFAULT_ELEMENT_NAME);
+ scopedValue.setScopeAttributeName("Scope");
+ scopedValue.setValue(STRING_1);
+ scopedValue.setScope(SCOPE_1);
final Attribute samlAttribute = attributeBuilder.buildObject();
samlAttribute.setAttributeName(ATTR_NAME);
samlAttribute.setAttributeNamespace(ATTR_NAMESPACE);
- samlAttribute.getAttributeValues().add(stringValue);
+ samlAttribute.getAttributeValues().add(scopedValue);
final Collection<Properties> rulesets = registry.getTranscodingProperties(samlAttribute);
Assert.assertEquals(rulesets.size(), 1);
@@ -272,15 +271,17 @@ public class SAML1StringAttributeTranscoderTest extends OpenSAMLInitBaseTestCase
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);
+
+ final ScopedStringAttributeValue value = (ScopedStringAttributeValue) attr.getValues().get(0);
+ Assert.assertEquals(value.getValue(), STRING_1);
+ Assert.assertEquals(value.getScope(), SCOPE_1);
}
@Test public void multi() throws Exception {
final Collection<? extends IdPAttributeValue<?>> values =
Arrays.asList(new ByteAttributeValue(new byte[] {1, 2, 3,}),
- new StringAttributeValue(STRING_1),
- new StringAttributeValue(STRING_2),
- new ScopedStringAttributeValue(STRING_1, STRING_2));
+ new ScopedStringAttributeValue(STRING_1, SCOPE_1),
+ new ScopedStringAttributeValue(STRING_2, SCOPE_2));
final IdPAttribute inputAttribute = new IdPAttribute(ATTR_NAME);
inputAttribute.setValues(values);
@@ -295,28 +296,61 @@ public class SAML1StringAttributeTranscoderTest extends OpenSAMLInitBaseTestCase
Assert.assertNotNull(attr);
final List<XMLObject> children = attr.getOrderedChildren();
- Assert.assertEquals(children.size(), 3, "Encoding three entries");
+ Assert.assertEquals(children.size(), 2, "Encoding 2 entries");
+
+ Assert.assertTrue(children.get(0) instanceof ScopedValue && children.get(1) instanceof ScopedValue,
+ "Child of result attribute should be a string");
- for (final XMLObject child: children) {
- Assert.assertTrue(child instanceof XSString, "Child of result attribute should be a string");
- final String childAsString = ((XSString) children.get(0)).getValue();
- Assert.assertTrue(STRING_1.equals(childAsString)||STRING_2.equals(childAsString));
+ final ScopedValue child1 = (ScopedValue) children.get(0);
+ Assert.assertEquals(child1.getElementQName(), AttributeValue.DEFAULT_ELEMENT_NAME,
+ "Attribute Value not inside <AttributeValue/>");
+
+ final ScopedValue child2 = (ScopedValue) children.get(1);
+ Assert.assertEquals(child2.getElementQName(), AttributeValue.DEFAULT_ELEMENT_NAME,
+ "Attribute Value not inside <AttributeValue/>");
+ //
+ // order of results is not guaranteed so sense the result from the length
+ //
+ if (child1.getValue().length() == STRING_1.length()) {
+ Assert.assertEquals(child1.getValue(), STRING_1, "Input matches output");
+ Assert.assertEquals(child2.getValue(), STRING_2, "Input matches output");
+ Assert.assertEquals(child1.getScope(), SCOPE_1, "Input matches output");
+ Assert.assertEquals(child2.getScope(), SCOPE_2, "Input matches output");
+ } else if (child1.getValue().length() == STRING_2.length()) {
+ Assert.assertEquals(child2.getValue(), STRING_1, "Input matches output");
+ Assert.assertEquals(child1.getValue(), STRING_2, "Input matches output");
+ Assert.assertEquals(child2.getScope(), SCOPE_1, "Input matches output");
+ Assert.assertEquals(child1.getScope(), SCOPE_2, "Input matches output");
+ } else {
+ Assert.fail("Value mismatch");
}
}
@Test public void multiDecode() throws Exception {
- final XSString stringValue = stringBuilder.buildObject(AttributeValue.DEFAULT_ELEMENT_NAME);
- stringValue.setValue(STRING_1);
+ final ScopedValue scopedValue = scopedBuilder.buildObject(AttributeValue.DEFAULT_ELEMENT_NAME);
+ scopedValue.setScopeAttributeName("Scope");
+ scopedValue.setValue(STRING_1);
+ scopedValue.setScope(SCOPE_1);
+
+ final ScopedValue scopedValue2 = scopedBuilder.buildObject(AttributeValue.DEFAULT_ELEMENT_NAME);
+ scopedValue2.setScopeAttributeName("Scope");
+ scopedValue2.setValue(STRING_2);
+ scopedValue2.setScope(SCOPE_2);
+
+ final XSString stringValue3 = stringBuilder.buildObject(AttributeValue.DEFAULT_ELEMENT_NAME);
+ stringValue3.setValue(STRING_2 + "@" + SCOPE_2);
+
+ final XSString stringValue4 = stringBuilder.buildObject(AttributeValue.DEFAULT_ELEMENT_NAME);
+ stringValue4.setValue(STRING_2);
- final XSString stringValue2 = stringBuilder.buildObject(AttributeValue.DEFAULT_ELEMENT_NAME);
- stringValue2.setValue(STRING_2);
-
final Attribute samlAttribute = attributeBuilder.buildObject();
samlAttribute.setAttributeName(ATTR_NAME);
samlAttribute.setAttributeNamespace(ATTR_NAMESPACE);
- samlAttribute.getAttributeValues().add(stringValue);
- samlAttribute.getAttributeValues().add(stringValue2);
+ samlAttribute.getAttributeValues().add(scopedValue);
+ samlAttribute.getAttributeValues().add(scopedValue2);
+ samlAttribute.getAttributeValues().add(stringValue3);
+ samlAttribute.getAttributeValues().add(stringValue4);
final Collection<Properties> rulesets = registry.getTranscodingProperties(samlAttribute);
Assert.assertEquals(rulesets.size(), 1);
@@ -327,8 +361,13 @@ public class SAML1StringAttributeTranscoderTest extends OpenSAMLInitBaseTestCase
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);
+
+ final ScopedStringAttributeValue value1 = (ScopedStringAttributeValue) attr.getValues().get(0);
+ final ScopedStringAttributeValue value2 = (ScopedStringAttributeValue) attr.getValues().get(1);
+ Assert.assertTrue(STRING_1.equals(value1.getValue()) || STRING_1.equals(value2.getValue()));
+ Assert.assertTrue(STRING_2.equals(value1.getValue()) || STRING_2.equals(value2.getValue()));
+ Assert.assertTrue(SCOPE_1.equals(value1.getScope()) || SCOPE_1.equals(value2.getScope()));
+ Assert.assertTrue(SCOPE_2.equals(value1.getScope()) || SCOPE_2.equals(value2.getScope()));
}
}
\ No newline at end of file
diff --git a/idp-saml-impl/src/test/java/net/shibboleth/idp/saml/attribute/transcoding/impl/SAML1StringAttributeTranscoderTest.java b/idp-saml-impl/src/test/java/net/shibboleth/idp/saml/attribute/transcoding/impl/SAML1StringAttributeTranscoderTest.java
index d51cb90..c737c37 100644
--- a/idp-saml-impl/src/test/java/net/shibboleth/idp/saml/attribute/transcoding/impl/SAML1StringAttributeTranscoderTest.java
+++ b/idp-saml-impl/src/test/java/net/shibboleth/idp/saml/attribute/transcoding/impl/SAML1StringAttributeTranscoderTest.java
@@ -116,13 +116,8 @@ public class SAML1StringAttributeTranscoderTest extends OpenSAMLInitBaseTestCase
Assert.assertEquals(rulesets.size(), 1);
final Properties ruleset = rulesets.iterator().next();
- final Attribute attr = TranscoderSupport.<Attribute>getTranscoder(ruleset).encode(
+ TranscoderSupport.<Attribute>getTranscoder(ruleset).encode(
null, inputAttribute, Attribute.class, ruleset);
-
- Assert.assertNotNull(attr);
- Assert.assertEquals(attr.getAttributeName(), ATTR_NAME);
- Assert.assertEquals(attr.getAttributeNamespace(), ATTR_NAMESPACE);
- Assert.assertTrue(attr.getAttributeValues().isEmpty());
}
@Test public void emptyRequestedEncode() throws Exception {
diff --git a/idp-saml-impl/src/test/java/net/shibboleth/idp/saml/attribute/transcoding/impl/SAML2ScopedStringAttributeTranscoderTest.java b/idp-saml-impl/src/test/java/net/shibboleth/idp/saml/attribute/transcoding/impl/SAML2ScopedStringAttributeTranscoderTest.java
index 0ceeb29..c2d5e58 100644
--- a/idp-saml-impl/src/test/java/net/shibboleth/idp/saml/attribute/transcoding/impl/SAML2ScopedStringAttributeTranscoderTest.java
+++ b/idp-saml-impl/src/test/java/net/shibboleth/idp/saml/attribute/transcoding/impl/SAML2ScopedStringAttributeTranscoderTest.java
@@ -87,12 +87,12 @@ public class SAML2ScopedStringAttributeTranscoderTest extends OpenSAMLInitBaseTe
registry = new AttributeTranscoderRegistryImpl();
registry.setId("test");
- registry.setNamingRegistry(Collections.singletonMap(
- Attribute.class, new AbstractSAML2AttributeTranscoder.NamingFunction()));
-
final SAML2ScopedStringAttributeTranscoder transcoder = new SAML2ScopedStringAttributeTranscoder();
transcoder.initialize();
+ registry.setNamingRegistry(Collections.singletonMap(
+ transcoder.getEncodedType(), new AbstractSAML2AttributeTranscoder.NamingFunction()));
+
final Map<String,Collection<Properties>> mappings = new HashMap<>();
final Properties ruleset1 = new Properties();
diff --git a/idp-saml-impl/src/test/java/net/shibboleth/idp/saml/attribute/transcoding/impl/SAML2StringAttributeTranscoderTest.java b/idp-saml-impl/src/test/java/net/shibboleth/idp/saml/attribute/transcoding/impl/SAML2StringAttributeTranscoderTest.java
index 3daa775..224f879 100644
--- a/idp-saml-impl/src/test/java/net/shibboleth/idp/saml/attribute/transcoding/impl/SAML2StringAttributeTranscoderTest.java
+++ b/idp-saml-impl/src/test/java/net/shibboleth/idp/saml/attribute/transcoding/impl/SAML2StringAttributeTranscoderTest.java
@@ -83,13 +83,13 @@ public class SAML2StringAttributeTranscoderTest extends OpenSAMLInitBaseTestCase
registry = new AttributeTranscoderRegistryImpl();
registry.setId("test");
-
- registry.setNamingRegistry(Collections.singletonMap(
- Attribute.class, new AbstractSAML2AttributeTranscoder.NamingFunction()));
-
+
final SAML2StringAttributeTranscoder transcoder = new SAML2StringAttributeTranscoder();
transcoder.initialize();
+ registry.setNamingRegistry(Collections.singletonMap(
+ transcoder.getEncodedType(), new AbstractSAML2AttributeTranscoder.NamingFunction()));
+
final Map<String,Collection<Properties>> mappings = new HashMap<>();
final Properties ruleset1 = new Properties();
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the commits
mailing list