[java-identity-provider] 07/16: IDP-1165 Warn on Lossy encoding of scoped attributes as strings.
Scott Cantor
cantor.2 at osu.edu
Tue Sep 26 12:41:17 EDT 2017
This is an automated email from the git hooks/post-receive script.
scantor pushed a commit to branch maint-3.3
in repository java-identity-provider.
View the commit online:
http://git.shibboleth.net/view/?p=java-identity-provider.git;a=commit;h=d87df963c5348286d81faddf15eaf638247e6b9f
commit d87df963c5348286d81faddf15eaf638247e6b9f
Author: Rod Widdowson <rdw at steadingsoftware.com>
AuthorDate: Fri Apr 28 16:03:42 2017 +0100
IDP-1165 Warn on Lossy encoding of scoped attributes as strings.
https://issues.shibboleth.net/jira/browse/IDP-1165
see also http://shibboleth.net/pipermail/users/2017-April/035589.html
---
.../encoding/impl/SAML1StringAttributeEncoder.java | 13 +++++++-
.../encoding/impl/SAML2StringAttributeEncoder.java | 11 +++++++
.../impl/SAML1StringAttributeEncoderTest.java | 38 +++++++---------------
.../impl/SAML2StringAttributeEncoderTest.java | 38 +++++++---------------
4 files changed, 47 insertions(+), 53 deletions(-)
diff --git a/idp-saml-impl/src/main/java/net/shibboleth/idp/saml/attribute/encoding/impl/SAML1StringAttributeEncoder.java b/idp-saml-impl/src/main/java/net/shibboleth/idp/saml/attribute/encoding/impl/SAML1StringAttributeEncoder.java
index 3e62a4f..7b80268 100644
--- a/idp-saml-impl/src/main/java/net/shibboleth/idp/saml/attribute/encoding/impl/SAML1StringAttributeEncoder.java
+++ b/idp-saml-impl/src/main/java/net/shibboleth/idp/saml/attribute/encoding/impl/SAML1StringAttributeEncoder.java
@@ -20,15 +20,19 @@ package net.shibboleth.idp.saml.attribute.encoding.impl;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
-import net.shibboleth.idp.attribute.IdPAttribute;
import net.shibboleth.idp.attribute.AttributeEncodingException;
+import net.shibboleth.idp.attribute.IdPAttribute;
import net.shibboleth.idp.attribute.IdPAttributeValue;
+import net.shibboleth.idp.attribute.LocalizedStringAttributeValue;
+import net.shibboleth.idp.attribute.ScopedStringAttributeValue;
import net.shibboleth.idp.attribute.StringAttributeValue;
import net.shibboleth.idp.saml.attribute.encoding.AbstractSAML1AttributeEncoder;
import net.shibboleth.idp.saml.attribute.encoding.SAMLEncoderSupport;
import org.opensaml.core.xml.XMLObject;
import org.opensaml.saml.saml1.core.AttributeValue;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
/**
* {@link net.shibboleth.idp.attribute.AttributeEncoder} that produces SAML 1 attributes from an
@@ -36,6 +40,9 @@ import org.opensaml.saml.saml1.core.AttributeValue;
*/
public class SAML1StringAttributeEncoder extends AbstractSAML1AttributeEncoder<StringAttributeValue> {
+ /** Class logger. */
+ @Nonnull private final Logger log = LoggerFactory.getLogger(SAML1StringAttributeEncoder.class);
+
/** {@inheritDoc} */
@Override
protected boolean canEncodeValue(@Nonnull final IdPAttribute attribute, @Nonnull final IdPAttributeValue value) {
@@ -46,6 +53,10 @@ public class SAML1StringAttributeEncoder extends AbstractSAML1AttributeEncoder<S
@Override
@Nullable protected XMLObject encodeValue(@Nonnull final IdPAttribute attribute,
@Nonnull final StringAttributeValue value) throws AttributeEncodingException {
+ if (value instanceof LocalizedStringAttributeValue || value instanceof ScopedStringAttributeValue) {
+ log.warn("Attribute '{}': Lossy encoding of attribute value of type {} to SAML1 String Attribute",
+ attribute.getId(), value.getClass().getName());
+ }
return SAMLEncoderSupport.encodeStringValue(attribute,
AttributeValue.DEFAULT_ELEMENT_NAME, value.getValue(), encodeType());
}
diff --git a/idp-saml-impl/src/main/java/net/shibboleth/idp/saml/attribute/encoding/impl/SAML2StringAttributeEncoder.java b/idp-saml-impl/src/main/java/net/shibboleth/idp/saml/attribute/encoding/impl/SAML2StringAttributeEncoder.java
index 97976ff..d317a93 100644
--- a/idp-saml-impl/src/main/java/net/shibboleth/idp/saml/attribute/encoding/impl/SAML2StringAttributeEncoder.java
+++ b/idp-saml-impl/src/main/java/net/shibboleth/idp/saml/attribute/encoding/impl/SAML2StringAttributeEncoder.java
@@ -24,6 +24,8 @@ import net.shibboleth.idp.attribute.AttributeEncodingException;
import net.shibboleth.idp.attribute.IdPAttribute;
import net.shibboleth.idp.attribute.IdPAttributeValue;
import net.shibboleth.idp.attribute.IdPRequestedAttribute;
+import net.shibboleth.idp.attribute.LocalizedStringAttributeValue;
+import net.shibboleth.idp.attribute.ScopedStringAttributeValue;
import net.shibboleth.idp.attribute.StringAttributeValue;
import net.shibboleth.idp.saml.attribute.encoding.AbstractSAML2AttributeEncoder;
import net.shibboleth.idp.saml.attribute.encoding.AttributeMapperProcessor;
@@ -34,6 +36,8 @@ import net.shibboleth.idp.saml.attribute.mapping.impl.StringAttributeValueMapper
import org.opensaml.core.xml.XMLObject;
import org.opensaml.saml.saml2.core.AttributeValue;
import org.opensaml.saml.saml2.metadata.RequestedAttribute;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
/**
* {@link net.shibboleth.idp.attribute.AttributeEncoder} that produces a SAML 2 Attribute from an {@link IdPAttribute}
@@ -42,6 +46,9 @@ import org.opensaml.saml.saml2.metadata.RequestedAttribute;
public class SAML2StringAttributeEncoder extends AbstractSAML2AttributeEncoder<StringAttributeValue> implements
AttributeMapperProcessor<RequestedAttribute, IdPRequestedAttribute> {
+ /** Class logger. */
+ @Nonnull private final Logger log = LoggerFactory.getLogger(SAML2StringAttributeEncoder.class);
+
/** {@inheritDoc} */
@Override protected boolean canEncodeValue(@Nonnull final IdPAttribute attribute,
@Nonnull final IdPAttributeValue value) {
@@ -51,6 +58,10 @@ public class SAML2StringAttributeEncoder extends AbstractSAML2AttributeEncoder<S
/** {@inheritDoc} */
@Override @Nullable protected XMLObject encodeValue(@Nonnull final IdPAttribute attribute,
@Nonnull final StringAttributeValue value) throws AttributeEncodingException {
+ if (value instanceof LocalizedStringAttributeValue || value instanceof ScopedStringAttributeValue) {
+ log.warn("Attribute '{}': Lossy encoding of attribute value of type {} to SAML2 String Attribute",
+ attribute.getId(), value.getClass().getName());
+ }
return SAMLEncoderSupport.encodeStringValue(attribute,
AttributeValue.DEFAULT_ELEMENT_NAME, value.getValue(), encodeType());
}
diff --git a/idp-saml-impl/src/test/java/net/shibboleth/idp/saml/attribute/encoding/impl/SAML1StringAttributeEncoderTest.java b/idp-saml-impl/src/test/java/net/shibboleth/idp/saml/attribute/encoding/impl/SAML1StringAttributeEncoderTest.java
index a0d92a4..35169ae 100644
--- a/idp-saml-impl/src/test/java/net/shibboleth/idp/saml/attribute/encoding/impl/SAML1StringAttributeEncoderTest.java
+++ b/idp-saml-impl/src/test/java/net/shibboleth/idp/saml/attribute/encoding/impl/SAML1StringAttributeEncoderTest.java
@@ -22,9 +22,10 @@ import java.util.Collection;
import java.util.List;
import net.shibboleth.idp.attribute.AttributeEncodingException;
-import net.shibboleth.idp.attribute.IdPAttributeValue;
import net.shibboleth.idp.attribute.ByteAttributeValue;
import net.shibboleth.idp.attribute.IdPAttribute;
+import net.shibboleth.idp.attribute.IdPAttributeValue;
+import net.shibboleth.idp.attribute.ScopedStringAttributeValue;
import net.shibboleth.idp.attribute.StringAttributeValue;
import net.shibboleth.utilities.java.support.component.ComponentInitializationException;
@@ -73,9 +74,11 @@ public class SAML1StringAttributeEncoderTest extends OpenSAMLInitBaseTestCase {
final Collection<IdPAttributeValue<?>> values =
Arrays.asList(new ByteAttributeValue(new byte[] {1, 2, 3,}),
new IdPAttributeValue<Object>() {
+ @Override
public Object getValue() {
return intArray;
}
+ @Override
public String getDisplayValue() {
return intArray.toString();
}
@@ -119,7 +122,9 @@ public class SAML1StringAttributeEncoderTest extends OpenSAMLInitBaseTestCase {
@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 StringAttributeValue(STRING_1),
+ new StringAttributeValue(STRING_2),
+ new ScopedStringAttributeValue(STRING_2, STRING_1));
final IdPAttribute inputAttribute = new IdPAttribute(ATTR_NAME);
inputAttribute.setValues(values);
@@ -129,31 +134,12 @@ public class SAML1StringAttributeEncoderTest extends OpenSAMLInitBaseTestCase {
Assert.assertNotNull(outputAttribute);
final List<XMLObject> children = outputAttribute.getOrderedChildren();
- Assert.assertEquals(children.size(), 2, "Encoding two entries");
-
- Assert.assertTrue(children.get(0) instanceof XSString && children.get(1) instanceof XSString,
- "Child of result attribute should be a string");
+ Assert.assertEquals(children.size(), 3, "Encoding three entries");
- final XSString child1 = (XSString) children.get(0);
- Assert.assertEquals(child1.getElementQName(), AttributeValue.DEFAULT_ELEMENT_NAME,
- "Attribute Value not inside <AttributeValue/>");
-
- final XSString child2 = (XSString) 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");
- } 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");
- } else {
- Assert.assertTrue(
- child1.getValue().length() == STRING_1.length() || child1.getValue().length() == STRING_2.length(),
- "One of the output's size should match an input size");
+ 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));
}
}
diff --git a/idp-saml-impl/src/test/java/net/shibboleth/idp/saml/attribute/encoding/impl/SAML2StringAttributeEncoderTest.java b/idp-saml-impl/src/test/java/net/shibboleth/idp/saml/attribute/encoding/impl/SAML2StringAttributeEncoderTest.java
index 672e590..390ef59 100644
--- a/idp-saml-impl/src/test/java/net/shibboleth/idp/saml/attribute/encoding/impl/SAML2StringAttributeEncoderTest.java
+++ b/idp-saml-impl/src/test/java/net/shibboleth/idp/saml/attribute/encoding/impl/SAML2StringAttributeEncoderTest.java
@@ -22,9 +22,10 @@ import java.util.Collection;
import java.util.List;
import net.shibboleth.idp.attribute.AttributeEncodingException;
-import net.shibboleth.idp.attribute.IdPAttributeValue;
import net.shibboleth.idp.attribute.ByteAttributeValue;
import net.shibboleth.idp.attribute.IdPAttribute;
+import net.shibboleth.idp.attribute.IdPAttributeValue;
+import net.shibboleth.idp.attribute.ScopedStringAttributeValue;
import net.shibboleth.idp.attribute.StringAttributeValue;
import net.shibboleth.utilities.java.support.component.ComponentInitializationException;
@@ -74,9 +75,11 @@ public class SAML2StringAttributeEncoderTest extends OpenSAMLInitBaseTestCase {
final int[] intArray = {1, 2, 3, 4};
final Collection<? extends IdPAttributeValue<?>> values =
Arrays.asList(new ByteAttributeValue(new byte[] {1, 2, 3,}), new IdPAttributeValue<Object>() {
+ @Override
public Object getValue() {
return intArray;
}
+ @Override
public String getDisplayValue() {
return intArray.toString();
}
@@ -118,7 +121,9 @@ public class SAML2StringAttributeEncoderTest extends OpenSAMLInitBaseTestCase {
@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 StringAttributeValue(STRING_1),
+ new StringAttributeValue(STRING_2),
+ new ScopedStringAttributeValue(STRING_1, STRING_2));
final IdPAttribute inputAttribute = new IdPAttribute(ATTR_NAME);
inputAttribute.setValues(values);
@@ -128,31 +133,12 @@ public class SAML2StringAttributeEncoderTest extends OpenSAMLInitBaseTestCase {
Assert.assertNotNull(outputAttribute);
final List<XMLObject> children = outputAttribute.getOrderedChildren();
- Assert.assertEquals(children.size(), 2, "Encoding two entries");
-
- Assert.assertTrue(children.get(0) instanceof XSString && children.get(1) instanceof XSString,
- "Child of result attribute should be a string");
+ Assert.assertEquals(children.size(), 3, "Encoding three entries");
- final XSString child1 = (XSString) children.get(0);
- Assert.assertEquals(child1.getElementQName(), AttributeValue.DEFAULT_ELEMENT_NAME,
- "Attribute Value not inside <AttributeValue/>");
-
- final XSString child2 = (XSString) 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");
- } 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");
- } else {
- Assert.assertTrue(
- child1.getValue().length() == STRING_1.length() || child1.getValue().length() == STRING_2.length(),
- "One of the output's size should match an input size");
+ 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));
}
}
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the commits
mailing list