[java-identity-provider] 10/27: Some refactoring, add activation condition support.
Scott Cantor
cantor.2 at osu.edu
Fri May 3 14:32:00 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=13d32516b1a2da7630135e1225597b6b5ed79fbc
commit 13d32516b1a2da7630135e1225597b6b5ed79fbc
Author: Scott Cantor <cantor.2 at osu.edu>
AuthorDate: Thu Apr 18 13:18:04 2019 -0400
Some refactoring, add activation condition support.
---
.../transcoding/AbstractAttributeTranscoder.java | 112 ++++++++++++-
.../attribute/transcoding/AttributeTranscoder.java | 3 +-
.../transcoding/AttributeTranscoderRegistry.java | 6 +
idp-attribute-impl/pom.xml | 6 +
.../impl/AttributeTranscoderRegistryImpl.java | 63 +++++++-
...va => AttributeTranscoderRegistryImplTest.java} | 176 ++++++++++++---------
.../attribute/transcoding/impl/PairTranscoder.java | 6 +-
.../AbstractSAMLAttributeTranscoder.java | 22 +--
.../SAML1ScopedStringAttributeTranscoderTest.java | 4 +-
.../impl/SAML1StringAttributeTranscoderTest.java | 4 +-
.../SAML2ScopedStringAttributeTranscoderTest.java | 4 +-
.../impl/SAML2StringAttributeTranscoderTest.java | 4 +-
12 files changed, 296 insertions(+), 114 deletions(-)
diff --git a/idp-attribute-api/src/main/java/net/shibboleth/idp/attribute/transcoding/AbstractAttributeTranscoder.java b/idp-attribute-api/src/main/java/net/shibboleth/idp/attribute/transcoding/AbstractAttributeTranscoder.java
index 4ac568f..92ce1ac 100644
--- a/idp-attribute-api/src/main/java/net/shibboleth/idp/attribute/transcoding/AbstractAttributeTranscoder.java
+++ b/idp-attribute-api/src/main/java/net/shibboleth/idp/attribute/transcoding/AbstractAttributeTranscoder.java
@@ -17,10 +17,15 @@
package net.shibboleth.idp.attribute.transcoding;
+import java.util.Properties;
import java.util.function.Predicate;
import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
+import net.shibboleth.idp.attribute.AttributeDecodingException;
+import net.shibboleth.idp.attribute.AttributeEncodingException;
+import net.shibboleth.idp.attribute.IdPAttribute;
import net.shibboleth.utilities.java.support.component.AbstractInitializableComponent;
import net.shibboleth.utilities.java.support.component.ComponentSupport;
import net.shibboleth.utilities.java.support.logic.Constraint;
@@ -42,7 +47,7 @@ public abstract class AbstractAttributeTranscoder<T> extends AbstractInitializab
/** Class logger. */
@Nonnull private final Logger log = LoggerFactory.getLogger(AbstractAttributeTranscoder.class);
- /** Condition for use of this encoder. */
+ /** Condition for use of this transcoder. */
@Nonnull private Predicate<ProfileRequestContext> activationCondition;
/** Constructor. */
@@ -50,13 +55,8 @@ public abstract class AbstractAttributeTranscoder<T> extends AbstractInitializab
activationCondition = Predicates.alwaysTrue();
}
- /** {@inheritDoc} */
- @Nonnull public Predicate<ProfileRequestContext> getActivationCondition() {
- return activationCondition;
- }
-
/**
- * Set the activation condition for this encoder.
+ * Set an activation condition for this transcoder.
*
* @param condition condition to set
*/
@@ -65,5 +65,103 @@ public abstract class AbstractAttributeTranscoder<T> extends AbstractInitializab
activationCondition = Constraint.isNotNull(condition, "Activation condition cannot be null");
}
+
+ /** {@inheritDoc} */
+ @Nullable public T encode(@Nullable final ProfileRequestContext profileRequestContext,
+ @Nonnull final IdPAttribute attribute, @Nonnull final Class<? extends T> to,
+ @Nonnull final Properties properties) throws AttributeEncodingException {
+ ComponentSupport.ifNotInitializedThrowUninitializedComponentException(this);
+ Constraint.isNotNull(attribute, "Attribute to encode cannot be null");
+
+ if (!checkActivation(profileRequestContext, properties)) {
+ return null;
+ }
+
+ return doEncode(profileRequestContext, attribute, to, properties);
+ }
+
+ /**
+ * Decode the supplied object into a protocol-neutral representation.
+ *
+ * @param profileRequestContext current profile request context
+ * @param input the object to decode
+ * @param properties properties governing the decoding process, principally the resulting attribute's naming
+ *
+ * @return the attribute the object was decoded into
+ *
+ * @throws AttributeDecodingException if unable to successfully decode object
+ */
+ @Nullable public IdPAttribute decode(@Nullable final ProfileRequestContext profileRequestContext,
+ @Nonnull final T input, @Nonnull final Properties properties) throws AttributeDecodingException {
+ ComponentSupport.ifNotInitializedThrowUninitializedComponentException(this);
+ Constraint.isNotNull(input, "Attribute to decode cannot be null");
+
+ if (!checkActivation(profileRequestContext, properties)) {
+ return null;
+ }
+
+ return doDecode(profileRequestContext, input, properties);
+ }
+
+
+ /**
+ * Encode the supplied attribute into a protocol specific representation.
+ *
+ * @param profileRequestContext current profile request context
+ * @param attribute the attribute to encode
+ * @param to specific type of object to encode
+ * @param properties properties governing the encoding process, principally the resulting object's naming
+ *
+ * @return the Object the attribute was encoded into
+ *
+ * @throws AttributeEncodingException if unable to successfully encode attribute
+ */
+ @Nullable protected abstract T doEncode(@Nullable final ProfileRequestContext profileRequestContext,
+ @Nonnull final IdPAttribute attribute, @Nonnull final Class<? extends T> to,
+ @Nonnull final Properties properties) throws AttributeEncodingException;
+
+ /**
+ * Decode the supplied object into a protocol-neutral representation.
+ *
+ * @param profileRequestContext current profile request context
+ * @param input the object to decode
+ * @param properties properties governing the decoding process, principally the resulting attribute's naming
+ *
+ * @return the attribute the object was decoded into
+ *
+ * @throws AttributeDecodingException if unable to successfully decode object
+ */
+ @Nullable protected abstract IdPAttribute doDecode(@Nullable final ProfileRequestContext profileRequestContext,
+ @Nonnull final T input, @Nonnull final Properties properties) throws AttributeDecodingException;
+
+
+ /**
+ *
+ * Apply any activation rules to the request.
+ *
+ * @param profileRequestContext current profile request context
+ * @param properties properties governing the transoding process
+ *
+ * @return true iff the process should continue
+ */
+ private boolean checkActivation(@Nullable final ProfileRequestContext profileRequestContext,
+ @Nonnull final Properties properties) {
+
+ if (!activationCondition.test(profileRequestContext)) {
+ log.debug("Transcoder inactive");
+ return false;
+ }
+
+ final Object condition = properties.get(AttributeTranscoderRegistry.PROP_CONDITION);
+ if (condition instanceof Predicate) {
+ if (!((Predicate) condition).test(profileRequestContext)) {
+ log.debug("Transcoder inactive");
+ return false;
+ }
+ }
+
+ return true;
+ }
+
}
\ No newline at end of file
diff --git a/idp-attribute-api/src/main/java/net/shibboleth/idp/attribute/transcoding/AttributeTranscoder.java b/idp-attribute-api/src/main/java/net/shibboleth/idp/attribute/transcoding/AttributeTranscoder.java
index 8ced8a8..5b83414 100644
--- a/idp-attribute-api/src/main/java/net/shibboleth/idp/attribute/transcoding/AttributeTranscoder.java
+++ b/idp-attribute-api/src/main/java/net/shibboleth/idp/attribute/transcoding/AttributeTranscoder.java
@@ -30,6 +30,7 @@ import net.shibboleth.idp.attribute.AttributeDecodingException;
import net.shibboleth.idp.attribute.AttributeEncodingException;
import net.shibboleth.idp.attribute.IdPAttribute;
import net.shibboleth.utilities.java.support.annotation.constraint.NotEmpty;
+import net.shibboleth.utilities.java.support.component.InitializableComponent;
/**
* Transcoders are objects that support both attribute encoding and decoding for bidirectional
@@ -45,7 +46,7 @@ import net.shibboleth.utilities.java.support.annotation.constraint.NotEmpty;
* @param <T> the type of object supported
*/
@ThreadSafe
-public interface AttributeTranscoder<T> {
+public interface AttributeTranscoder<T> extends InitializableComponent {
/**
* Get the class representing the type of object supported by this transcoder.
diff --git a/idp-attribute-api/src/main/java/net/shibboleth/idp/attribute/transcoding/AttributeTranscoderRegistry.java b/idp-attribute-api/src/main/java/net/shibboleth/idp/attribute/transcoding/AttributeTranscoderRegistry.java
index 07dce7b..861797a 100644
--- a/idp-attribute-api/src/main/java/net/shibboleth/idp/attribute/transcoding/AttributeTranscoderRegistry.java
+++ b/idp-attribute-api/src/main/java/net/shibboleth/idp/attribute/transcoding/AttributeTranscoderRegistry.java
@@ -44,6 +44,12 @@ public interface AttributeTranscoderRegistry extends IdentifiedComponent {
/** Property name for accessing {@link AttributeTranscoder} object to use. */
@Nonnull @NotEmpty static final String PROP_TRANSCODER = "transcoder";
+ /** Property name for accessing an activation condition object to apply. */
+ @Nonnull @NotEmpty static final String PROP_CONDITION = "activationCondition";
+
+ /** Property name for accessing relying parties to wrap an activation condition around. */
+ @Nonnull @NotEmpty static final String PROP_RELYINGPARTIES = "relyingParties";
+
/**
* Obtains a set of instructions for encoding an input {@link IdPAttribute} into a target type.
*
diff --git a/idp-attribute-impl/pom.xml b/idp-attribute-impl/pom.xml
index 7a9d95a..77f3e9f 100644
--- a/idp-attribute-impl/pom.xml
+++ b/idp-attribute-impl/pom.xml
@@ -25,6 +25,12 @@
</dependency>
<dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>idp-profile-api</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+
+ <dependency>
<groupId>net.shibboleth.ext</groupId>
<artifactId>spring-extensions</artifactId>
</dependency>
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 dc56e6a..9d7a133 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
@@ -24,6 +24,7 @@ import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
import java.util.function.Function;
+import java.util.function.Predicate;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
@@ -33,13 +34,16 @@ import net.shibboleth.ext.spring.service.AbstractServiceableComponent;
import net.shibboleth.idp.attribute.IdPAttribute;
import net.shibboleth.idp.attribute.transcoding.AttributeTranscoder;
import net.shibboleth.idp.attribute.transcoding.AttributeTranscoderRegistry;
+import net.shibboleth.idp.profile.logic.RelyingPartyIdPredicate;
import net.shibboleth.utilities.java.support.annotation.constraint.NonnullElements;
import net.shibboleth.utilities.java.support.annotation.constraint.NotEmpty;
import net.shibboleth.utilities.java.support.annotation.constraint.Unmodifiable;
+import net.shibboleth.utilities.java.support.component.ComponentInitializationException;
import net.shibboleth.utilities.java.support.component.ComponentSupport;
import net.shibboleth.utilities.java.support.logic.Constraint;
import net.shibboleth.utilities.java.support.primitive.StringSupport;
+import org.opensaml.profile.context.ProfileRequestContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -79,10 +83,10 @@ public class AttributeTranscoderRegistryImpl extends AbstractServiceableComponen
*
* @param registry map of types to naming functions
*/
- public void setNamingRegistry(@Nonnull @NonnullElements final Map<Class<?>,Function<?,String>> registry) {
+ public void addToNamingRegistry(@Nonnull @NonnullElements final Map<Class<?>,Function<?,String>> registry) {
ComponentSupport.ifInitializedThrowUnmodifiabledComponentException(this);
+
if (registry == null) {
- namingFunctionRegistry.clear();
return;
}
@@ -100,10 +104,10 @@ public class AttributeTranscoderRegistryImpl extends AbstractServiceableComponen
*
* @param registry mappings from internal name to transcoding rules
*/
- public void setTranscoderRegistry(@Nonnull @NonnullElements final Map<String,Collection<Properties>> registry) {
+ public void addToTranscoderRegistry(@Nonnull @NonnullElements final Map<String,Collection<Properties>> registry) {
ComponentSupport.ifInitializedThrowUnmodifiabledComponentException(this);
+
if (registry == null) {
- transcodingRegistry.clear();
return;
}
@@ -113,6 +117,14 @@ public class AttributeTranscoderRegistryImpl extends AbstractServiceableComponen
if (internalId != null && entry.getValue() != null && !entry.getValue().isEmpty()) {
for (final Properties props : Collections2.filter(entry.getValue(), Predicates.notNull())) {
+
+ final Predicate activationCondition = buildActivationCondition(props);
+ if (activationCondition != null) {
+ props.put(PROP_CONDITION, activationCondition);
+ } else {
+ props.remove(PROP_CONDITION);
+ }
+
addMapping(internalId, props);
}
}
@@ -190,9 +202,10 @@ public class AttributeTranscoderRegistryImpl extends AbstractServiceableComponen
if (transcoder instanceof String) {
try {
transcoder = Class.forName((String) transcoder).getDeclaredConstructor().newInstance();
+ ((AttributeTranscoder) transcoder).initialize();
} catch (final InstantiationException | IllegalAccessException | IllegalArgumentException
| InvocationTargetException | NoSuchMethodException | SecurityException
- | ClassNotFoundException e) {
+ | ClassNotFoundException | ComponentInitializationException e) {
log.warn("Unable to create AttributeTranscoder of specified type {} in transcoding rule for {}",
transcoder, id, e);
return;
@@ -233,6 +246,46 @@ public class AttributeTranscoderRegistryImpl extends AbstractServiceableComponen
log.warn("Transcoding rule for {} into type {} did not produce an encoded name", id, type.getName());
}
}
+
+ /**
+ * Build an appropriate {@link Predicate} to use as an activation condition within the ruleset.
+ *
+ * @param ruleset transcoding rules
+ *
+ * @return a predicate to install under the ruleset's {@link #PROP_CONDITION}
+ */
+ @Nullable private Predicate<ProfileRequestContext> buildActivationCondition(@Nonnull final Properties ruleset) {
+
+ Predicate effectiveCondition = null;
+
+ final Object baseCondition = ruleset.get(PROP_CONDITION);
+ if (baseCondition instanceof Predicate) {
+ effectiveCondition = (Predicate) baseCondition;
+ } else if (baseCondition != null) {
+ log.error("{} property did not contain a Predicate object, ignored", PROP_CONDITION);
+ }
+
+ Predicate relyingPartyCondition = null;
+
+ final Object relyingParties = ruleset.get(PROP_RELYINGPARTIES);
+ if (relyingParties instanceof Collection) {
+ relyingPartyCondition = new RelyingPartyIdPredicate((Collection<String>) relyingParties);
+ } else if (relyingParties instanceof String) {
+ final Collection<String> parsed = StringSupport.normalizeStringCollection(
+ StringSupport.stringToList((String) relyingParties, " "));
+ relyingPartyCondition = new RelyingPartyIdPredicate(parsed);
+ } else if (relyingParties != null) {
+ log.error("{} property did not contain a Collection or String, ignored", PROP_RELYINGPARTIES);
+ }
+
+ if (effectiveCondition == null) {
+ return relyingPartyCondition;
+ } else if (relyingPartyCondition != null) {
+ return effectiveCondition.and(relyingPartyCondition);
+ } else {
+ return effectiveCondition;
+ }
+ }
/**
* Convert an input type into the appropriate type (possibly itself) to use in looking up
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/AttributeTranscoderRegistryImplTest.java
similarity index 62%
rename from idp-attribute-impl/src/test/java/net/shibboleth/idp/attribute/transcoding/impl/AttributeTranscoderRegistryTest.java
rename to idp-attribute-impl/src/test/java/net/shibboleth/idp/attribute/transcoding/impl/AttributeTranscoderRegistryImplTest.java
index c12b30b..2f76108 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/AttributeTranscoderRegistryImplTest.java
@@ -26,11 +26,13 @@ import java.util.List;
import java.util.Map;
import java.util.Properties;
-import org.testng.Assert;
+import static org.testng.Assert.*;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
+import com.google.common.base.Predicates;
+
import net.shibboleth.idp.attribute.AttributeDecodingException;
import net.shibboleth.idp.attribute.AttributeEncodingException;
import net.shibboleth.idp.attribute.EmptyAttributeValue;
@@ -44,9 +46,9 @@ import net.shibboleth.utilities.java.support.collection.Pair;
import net.shibboleth.utilities.java.support.component.ComponentInitializationException;
/**
- * Test for {@link AttributeTranscoderRegistry}.
+ * Test for {@link AttributeTranscoderRegistryImpl}.
*/
-public class AttributeTranscoderRegistryTest {
+public class AttributeTranscoderRegistryImplTest {
private AttributeTranscoderRegistryImpl registry;
@@ -54,10 +56,11 @@ public class AttributeTranscoderRegistryTest {
registry = new AttributeTranscoderRegistryImpl();
registry.setId("test");
- registry.setNamingRegistry(Collections.singletonMap(
+ registry.addToNamingRegistry(Collections.singletonMap(
Pair.class, (Pair p) -> "{Pair}" + p.getFirst().toString()));
final PairTranscoder transcoder = new PairTranscoder();
+ transcoder.initialize();
final Map<String,Collection<Properties>> mappings = new HashMap<>();
@@ -69,10 +72,15 @@ public class AttributeTranscoderRegistryTest {
ruleset2.put(AttributeTranscoderRegistry.PROP_TRANSCODER, "net.shibboleth.idp.attribute.transcoding.impl.PairTranscoder");
ruleset2.setProperty("name", "baz");
- mappings.put("foo", Arrays.asList(ruleset1, ruleset2));
+ final Properties ruleset3 = new Properties();
+ ruleset3.put(AttributeTranscoderRegistry.PROP_TRANSCODER, transcoder);
+ ruleset3.put(AttributeTranscoderRegistry.PROP_CONDITION, Predicates.alwaysFalse());
+ ruleset3.setProperty("name", "ban");
+
+ mappings.put("foo", Arrays.asList(ruleset1, ruleset2, ruleset3));
mappings.put("foo2", Collections.singletonList(ruleset2));
- registry.setTranscoderRegistry(mappings);
+ registry.addToTranscoderRegistry(mappings);
registry.initialize();
}
@@ -83,39 +91,52 @@ public class AttributeTranscoderRegistryTest {
}
- // Test no mappings to encode IdPAttribute.
@Test public void testEncodeNoMappings() throws AttributeEncodingException {
- Assert.assertTrue(registry.getTranscodingProperties(new IdPAttribute("frobnitz"), Pair.class).isEmpty());
- Assert.assertTrue(registry.getTranscodingProperties(new IdPAttribute("frobnitz"), MyPair.class).isEmpty());
- Assert.assertTrue(registry.getTranscodingProperties(new IdPAttribute("foo"), String.class).isEmpty());
+ assertTrue(registry.getTranscodingProperties(new IdPAttribute("frobnitz"), Pair.class).isEmpty());
+ assertTrue(registry.getTranscodingProperties(new IdPAttribute("frobnitz"), MyPair.class).isEmpty());
+ assertTrue(registry.getTranscodingProperties(new IdPAttribute("foo"), String.class).isEmpty());
}
- // Test no reverse mappings from a Pair/String to an IdPAttribute
@Test public void testDecodeNoMappings() throws AttributeDecodingException {
- Assert.assertTrue(registry.getTranscodingProperties(new Pair("foo", "value")).isEmpty());
- Assert.assertTrue(registry.getTranscodingProperties(new MyPair("foo", "value")).isEmpty());
- Assert.assertTrue(registry.getTranscodingProperties(new String("bar")).isEmpty());
+ assertTrue(registry.getTranscodingProperties(new Pair("foo", "value")).isEmpty());
+ assertTrue(registry.getTranscodingProperties(new MyPair("foo", "value")).isEmpty());
+ assertTrue(registry.getTranscodingProperties(new String("bar")).isEmpty());
}
-
+
+ @Test public void testDecodeInactive() throws AttributeDecodingException {
+
+ final Pair p = new Pair("ban", "value");
+ final Collection<Properties> rulesets = registry.getTranscodingProperties(p);
+ assertEquals(rulesets.size(), 1);
+
+ final Properties ruleset = rulesets.iterator().next();
+
+ final AttributeTranscoder<Pair> t = TranscoderSupport.getTranscoder(ruleset);
+ assertNull(t.decode(null, p, ruleset));
+ }
+
@Test public void testEncodeNoValues() throws AttributeEncodingException {
final IdPAttribute foo = new IdPAttribute("foo");
final List<Pair> pairs = new ArrayList<>();
for (final Properties ruleset : registry.getTranscodingProperties(foo, Pair.class)) {
- final AttributeTranscoder<Pair> t = TranscoderSupport.getTranscoder(ruleset);
- pairs.add(t.encode(null, foo, Pair.class, ruleset));
+ final AttributeTranscoder<Pair> t = TranscoderSupport.getTranscoder(ruleset);
+ final Pair p = t.encode(null, foo, Pair.class, ruleset);
+ if (p != null) {
+ pairs.add(p);
+ }
}
- Assert.assertEquals(pairs.size(), 2);
+ assertEquals(pairs.size(), 2);
- Assert.assertEquals(pairs.get(0).getFirst(), "bar");
- Assert.assertNull(pairs.get(0).getSecond());
+ assertEquals(pairs.get(0).getFirst(), "bar");
+ assertNull(pairs.get(0).getSecond());
- Assert.assertEquals(pairs.get(1).getFirst(), "baz");
- Assert.assertNull(pairs.get(1).getSecond());
+ assertEquals(pairs.get(1).getFirst(), "baz");
+ assertNull(pairs.get(1).getSecond());
}
@Test public void testDecodeOneNoValues() throws AttributeDecodingException {
@@ -125,14 +146,14 @@ public class AttributeTranscoderRegistryTest {
final List<IdPAttribute> attributes = new ArrayList<>();
for (final Properties ruleset : registry.getTranscodingProperties(bar)) {
- final AttributeTranscoder<Pair> t = TranscoderSupport.getTranscoder(ruleset);
+ final AttributeTranscoder<Pair> t = TranscoderSupport.getTranscoder(ruleset);
attributes.add(t.decode(null, bar, ruleset));
}
- Assert.assertEquals(attributes.size(), 1);
+ assertEquals(attributes.size(), 1);
- Assert.assertEquals(attributes.get(0).getId(), "foo");
- Assert.assertTrue(attributes.get(0).getValues().isEmpty());
+ assertEquals(attributes.get(0).getId(), "foo");
+ assertTrue(attributes.get(0).getValues().isEmpty());
}
@Test public void testDecodeTwoNoValues() throws AttributeDecodingException {
@@ -142,17 +163,17 @@ public class AttributeTranscoderRegistryTest {
final List<IdPAttribute> attributes = new ArrayList<>();
for (final Properties ruleset : registry.getTranscodingProperties(baz)) {
- final AttributeTranscoder<Pair> t = TranscoderSupport.getTranscoder(ruleset);
+ final AttributeTranscoder<Pair> t = TranscoderSupport.getTranscoder(ruleset);
attributes.add(t.decode(null, baz, ruleset));
}
- Assert.assertEquals(attributes.size(), 2);
+ assertEquals(attributes.size(), 2);
- Assert.assertEquals(attributes.get(0).getId(), "foo");
- Assert.assertTrue(attributes.get(0).getValues().isEmpty());
+ assertEquals(attributes.get(0).getId(), "foo");
+ assertTrue(attributes.get(0).getValues().isEmpty());
- Assert.assertEquals(attributes.get(1).getId(), "foo2");
- Assert.assertTrue(attributes.get(1).getValues().isEmpty());
+ assertEquals(attributes.get(1).getId(), "foo2");
+ assertTrue(attributes.get(1).getValues().isEmpty());
}
@Test public void testEncodeStringValues() throws AttributeEncodingException {
@@ -162,17 +183,20 @@ public class AttributeTranscoderRegistryTest {
final List<Pair> pairs = new ArrayList<>();
for (final Properties ruleset : registry.getTranscodingProperties(foo, Pair.class)) {
- final AttributeTranscoder<Pair> t = TranscoderSupport.getTranscoder(ruleset);
- pairs.add(t.encode(null, foo, Pair.class, ruleset));
+ final AttributeTranscoder<Pair> t = TranscoderSupport.getTranscoder(ruleset);
+ final Pair p = t.encode(null, foo, Pair.class, ruleset);
+ if (p != null) {
+ pairs.add(p);
+ }
}
- Assert.assertEquals(pairs.size(), 2);
+ assertEquals(pairs.size(), 2);
- Assert.assertEquals(pairs.get(0).getFirst(), "bar");
- Assert.assertEquals(pairs.get(0).getSecond(), "value");
+ assertEquals(pairs.get(0).getFirst(), "bar");
+ assertEquals(pairs.get(0).getSecond(), "value");
- Assert.assertEquals(pairs.get(1).getFirst(), "baz");
- Assert.assertEquals(pairs.get(1).getSecond(), "value");
+ assertEquals(pairs.get(1).getFirst(), "baz");
+ assertEquals(pairs.get(1).getSecond(), "value");
}
@Test public void testEncodeSubtypeStringValues() throws AttributeEncodingException {
@@ -182,17 +206,20 @@ public class AttributeTranscoderRegistryTest {
final List<MyPair> pairs = new ArrayList<>();
for (final Properties ruleset : registry.getTranscodingProperties(foo, MyPair.class)) {
- final AttributeTranscoder<MyPair> t = TranscoderSupport.getTranscoder(ruleset);
- pairs.add(t.encode(null, foo, MyPair.class, ruleset));
+ final AttributeTranscoder<MyPair> t = TranscoderSupport.getTranscoder(ruleset);
+ final MyPair p = t.encode(null, foo, MyPair.class, ruleset);
+ if (p != null) {
+ pairs.add(p);
+ }
}
- Assert.assertEquals(pairs.size(), 2);
+ assertEquals(pairs.size(), 2);
- Assert.assertEquals(pairs.get(0).getFirst(), "bar");
- Assert.assertEquals(pairs.get(0).getSecond(), "value");
+ assertEquals(pairs.get(0).getFirst(), "bar");
+ assertEquals(pairs.get(0).getSecond(), "value");
- Assert.assertEquals(pairs.get(1).getFirst(), "baz");
- Assert.assertEquals(pairs.get(1).getSecond(), "value");
+ assertEquals(pairs.get(1).getFirst(), "baz");
+ assertEquals(pairs.get(1).getSecond(), "value");
}
@Test public void testDecodeOneStringValues() throws AttributeDecodingException {
@@ -202,14 +229,14 @@ public class AttributeTranscoderRegistryTest {
final List<IdPAttribute> attributes = new ArrayList<>();
for (final Properties ruleset : registry.getTranscodingProperties(bar)) {
- final AttributeTranscoder<Pair> t = TranscoderSupport.getTranscoder(ruleset);
+ final AttributeTranscoder<Pair> t = TranscoderSupport.getTranscoder(ruleset);
attributes.add(t.decode(null, bar, ruleset));
}
- Assert.assertEquals(attributes.size(), 1);
+ assertEquals(attributes.size(), 1);
- Assert.assertEquals(attributes.get(0).getId(), "foo");
- Assert.assertEquals(attributes.get(0).getValues().get(0).getValue(), "value");
+ assertEquals(attributes.get(0).getId(), "foo");
+ assertEquals(attributes.get(0).getValues().get(0).getValue(), "value");
}
@Test public void testDecodeTwoStringValues() throws AttributeDecodingException {
@@ -219,17 +246,17 @@ public class AttributeTranscoderRegistryTest {
final List<IdPAttribute> attributes = new ArrayList<>();
for (final Properties ruleset : registry.getTranscodingProperties(baz)) {
- final AttributeTranscoder<Pair> t = TranscoderSupport.getTranscoder(ruleset);
+ final AttributeTranscoder<Pair> t = TranscoderSupport.getTranscoder(ruleset);
attributes.add(t.decode(null, baz, ruleset));
}
- Assert.assertEquals(attributes.size(), 2);
+ assertEquals(attributes.size(), 2);
- Assert.assertEquals(attributes.get(0).getId(), "foo");
- Assert.assertEquals(attributes.get(0).getValues().get(0).getValue(), "value");
+ assertEquals(attributes.get(0).getId(), "foo");
+ assertEquals(attributes.get(0).getValues().get(0).getValue(), "value");
- Assert.assertEquals(attributes.get(1).getId(), "foo2");
- Assert.assertEquals(attributes.get(1).getValues().get(0).getValue(), "value");
+ assertEquals(attributes.get(1).getId(), "foo2");
+ assertEquals(attributes.get(1).getValues().get(0).getValue(), "value");
}
@Test public void testEncodeUnsupportedValues() throws AttributeEncodingException {
@@ -239,17 +266,20 @@ public class AttributeTranscoderRegistryTest {
final List<Pair> pairs = new ArrayList<>();
for (final Properties ruleset : registry.getTranscodingProperties(foo, Pair.class)) {
- final AttributeTranscoder<Pair> t = TranscoderSupport.getTranscoder(ruleset);
- pairs.add(t.encode(null, foo, Pair.class, ruleset));
+ final AttributeTranscoder<Pair> t = TranscoderSupport.getTranscoder(ruleset);
+ final Pair p = t.encode(null, foo, Pair.class, ruleset);
+ if (p != null) {
+ pairs.add(p);
+ }
}
- Assert.assertEquals(pairs.size(), 2);
+ assertEquals(pairs.size(), 2);
- Assert.assertEquals(pairs.get(0).getFirst(), "bar");
- Assert.assertNull(pairs.get(0).getSecond());
+ assertEquals(pairs.get(0).getFirst(), "bar");
+ assertNull(pairs.get(0).getSecond());
- Assert.assertEquals(pairs.get(1).getFirst(), "baz");
- Assert.assertNull(pairs.get(0).getSecond());
+ assertEquals(pairs.get(1).getFirst(), "baz");
+ assertNull(pairs.get(0).getSecond());
}
@Test public void testDecodeOneUnsupportedValues() throws AttributeDecodingException {
@@ -259,14 +289,14 @@ public class AttributeTranscoderRegistryTest {
final List<IdPAttribute> attributes = new ArrayList<>();
for (final Properties ruleset : registry.getTranscodingProperties(bar)) {
- final AttributeTranscoder<Pair> t = TranscoderSupport.getTranscoder(ruleset);
+ final AttributeTranscoder<Pair> t = TranscoderSupport.getTranscoder(ruleset);
attributes.add(t.decode(null, bar, ruleset));
}
- Assert.assertEquals(attributes.size(), 1);
+ assertEquals(attributes.size(), 1);
- Assert.assertEquals(attributes.get(0).getId(), "foo");
- Assert.assertTrue(attributes.get(0).getValues().isEmpty());
+ assertEquals(attributes.get(0).getId(), "foo");
+ assertTrue(attributes.get(0).getValues().isEmpty());
}
@Test public void testDecodeTwoUnsupportedValues() throws AttributeDecodingException {
@@ -276,17 +306,17 @@ public class AttributeTranscoderRegistryTest {
final List<IdPAttribute> attributes = new ArrayList<>();
for (final Properties ruleset : registry.getTranscodingProperties(baz)) {
- final AttributeTranscoder<Pair> t = TranscoderSupport.getTranscoder(ruleset);
+ final AttributeTranscoder<Pair> t = TranscoderSupport.getTranscoder(ruleset);
attributes.add(t.decode(null, baz, ruleset));
}
- Assert.assertEquals(attributes.size(), 2);
+ assertEquals(attributes.size(), 2);
- Assert.assertEquals(attributes.get(0).getId(), "foo");
- Assert.assertTrue(attributes.get(0).getValues().isEmpty());
+ assertEquals(attributes.get(0).getId(), "foo");
+ assertTrue(attributes.get(0).getValues().isEmpty());
- Assert.assertEquals(attributes.get(1).getId(), "foo2");
- Assert.assertTrue(attributes.get(1).getValues().isEmpty());
+ assertEquals(attributes.get(1).getId(), "foo2");
+ assertTrue(attributes.get(1).getValues().isEmpty());
}
/** Marker class to exercise subtype support. */
diff --git a/idp-attribute-impl/src/test/java/net/shibboleth/idp/attribute/transcoding/impl/PairTranscoder.java b/idp-attribute-impl/src/test/java/net/shibboleth/idp/attribute/transcoding/impl/PairTranscoder.java
index e38287a..0617bcd 100644
--- a/idp-attribute-impl/src/test/java/net/shibboleth/idp/attribute/transcoding/impl/PairTranscoder.java
+++ b/idp-attribute-impl/src/test/java/net/shibboleth/idp/attribute/transcoding/impl/PairTranscoder.java
@@ -53,7 +53,8 @@ public class PairTranscoder extends AbstractAttributeTranscoder<Pair> {
}
/** {@inheritDoc} */
- public Pair encode(ProfileRequestContext profileRequestContext, IdPAttribute attribute, Class<? extends Pair> to, Properties properties)
+ @Override
+ public Pair doEncode(ProfileRequestContext profileRequestContext, IdPAttribute attribute, Class<? extends Pair> to, Properties properties)
throws AttributeEncodingException {
final String name = StringSupport.trimOrNull(properties.getProperty("name"));
@@ -74,7 +75,8 @@ public class PairTranscoder extends AbstractAttributeTranscoder<Pair> {
}
/** {@inheritDoc} */
- public IdPAttribute decode(ProfileRequestContext profileRequestContext, Pair input, Properties properties)
+ @Override
+ public IdPAttribute doDecode(ProfileRequestContext profileRequestContext, Pair input, Properties properties)
throws AttributeDecodingException {
final String id = StringSupport.trimOrNull(properties.getProperty(AttributeTranscoderRegistry.PROP_ID));
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 624e0a8..137b119 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
@@ -33,8 +33,6 @@ 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;
-import net.shibboleth.utilities.java.support.logic.Constraint;
import net.shibboleth.utilities.java.support.xml.DOMTypeSupport;
import org.opensaml.core.xml.XMLObject;
@@ -69,19 +67,13 @@ public abstract class AbstractSAMLAttributeTranscoder<AttributeType extends SAML
@Nonnull private final Logger log = LoggerFactory.getLogger(AbstractSAMLAttributeTranscoder.class);
/** {@inheritDoc} */
- @Nullable public AttributeType encode(@Nullable final ProfileRequestContext profileRequestContext,
+ @Override
+ @Nullable public AttributeType doEncode(@Nullable final ProfileRequestContext profileRequestContext,
@Nonnull final IdPAttribute attribute, @Nonnull final Class<? extends AttributeType> to,
@Nonnull final Properties properties) throws AttributeEncodingException {
- ComponentSupport.ifNotInitializedThrowUninitializedComponentException(this);
- Constraint.isNotNull(attribute, "Attribute to encode cannot be null");
final String attributeId = attribute.getId();
- if (!getActivationCondition().test(profileRequestContext)) {
- log.debug("Encoder for attribute {} inactive", attributeId);
- return null;
- }
-
log.debug("Beginning to encode attribute {}", attributeId);
final List<XMLObject> samlAttributeValues = new ArrayList<>();
@@ -114,18 +106,12 @@ public abstract class AbstractSAMLAttributeTranscoder<AttributeType extends SAML
}
/** {@inheritDoc} */
- @Nullable public IdPAttribute decode(@Nullable final ProfileRequestContext profileRequestContext,
+ @Override
+ @Nullable public IdPAttribute doDecode(@Nullable final ProfileRequestContext profileRequestContext,
@Nonnull final AttributeType input, @Nonnull final Properties properties)
throws AttributeDecodingException {
- ComponentSupport.ifNotInitializedThrowUninitializedComponentException(this);
- Constraint.isNotNull(input, "Attribute to decode cannot be null");
final String attributeName = getEncodedName(properties);
-
- if (!getActivationCondition().test(profileRequestContext)) {
- log.debug("Decoder for attribute {} inactive", attributeName);
- return null;
- }
log.debug("Beginning to decode attribute {}", attributeName);
diff --git a/idp-saml-impl/src/test/java/net/shibboleth/idp/saml/attribute/transcoding/impl/SAML1ScopedStringAttributeTranscoderTest.java b/idp-saml-impl/src/test/java/net/shibboleth/idp/saml/attribute/transcoding/impl/SAML1ScopedStringAttributeTranscoderTest.java
index d74d925..657624b 100644
--- a/idp-saml-impl/src/test/java/net/shibboleth/idp/saml/attribute/transcoding/impl/SAML1ScopedStringAttributeTranscoderTest.java
+++ b/idp-saml-impl/src/test/java/net/shibboleth/idp/saml/attribute/transcoding/impl/SAML1ScopedStringAttributeTranscoderTest.java
@@ -96,7 +96,7 @@ public class SAML1ScopedStringAttributeTranscoderTest extends OpenSAMLInitBaseTe
final SAML1ScopedStringAttributeTranscoder transcoder = new SAML1ScopedStringAttributeTranscoder();
transcoder.initialize();
- registry.setNamingRegistry(Collections.singletonMap(
+ registry.addToNamingRegistry(Collections.singletonMap(
transcoder.getEncodedType(), new AbstractSAML1AttributeTranscoder.NamingFunction()));
final Map<String,Collection<Properties>> mappings = new HashMap<>();
@@ -112,7 +112,7 @@ public class SAML1ScopedStringAttributeTranscoderTest extends OpenSAMLInitBaseTe
mappings.put(ATTR_NAME, Collections.singletonList(ruleset1));
- registry.setTranscoderRegistry(mappings);
+ registry.addToTranscoderRegistry(mappings);
registry.initialize();
}
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 c737c37..c7521c7 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
@@ -86,7 +86,7 @@ public class SAML1StringAttributeTranscoderTest extends OpenSAMLInitBaseTestCase
final SAML1StringAttributeTranscoder transcoder = new SAML1StringAttributeTranscoder();
transcoder.initialize();
- registry.setNamingRegistry(Collections.singletonMap(
+ registry.addToNamingRegistry(Collections.singletonMap(
transcoder.getEncodedType(), new AbstractSAML1AttributeTranscoder.NamingFunction()));
final Map<String,Collection<Properties>> mappings = new HashMap<>();
@@ -99,7 +99,7 @@ public class SAML1StringAttributeTranscoderTest extends OpenSAMLInitBaseTestCase
mappings.put(ATTR_NAME, Collections.singletonList(ruleset1));
- registry.setTranscoderRegistry(mappings);
+ registry.addToTranscoderRegistry(mappings);
registry.initialize();
}
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 c2d5e58..766b5ea 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
@@ -90,7 +90,7 @@ public class SAML2ScopedStringAttributeTranscoderTest extends OpenSAMLInitBaseTe
final SAML2ScopedStringAttributeTranscoder transcoder = new SAML2ScopedStringAttributeTranscoder();
transcoder.initialize();
- registry.setNamingRegistry(Collections.singletonMap(
+ registry.addToNamingRegistry(Collections.singletonMap(
transcoder.getEncodedType(), new AbstractSAML2AttributeTranscoder.NamingFunction()));
final Map<String,Collection<Properties>> mappings = new HashMap<>();
@@ -106,7 +106,7 @@ public class SAML2ScopedStringAttributeTranscoderTest extends OpenSAMLInitBaseTe
mappings.put(ATTR_NAME, Collections.singletonList(ruleset1));
- registry.setTranscoderRegistry(mappings);
+ registry.addToTranscoderRegistry(mappings);
registry.initialize();
}
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 224f879..1923161 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
@@ -87,7 +87,7 @@ public class SAML2StringAttributeTranscoderTest extends OpenSAMLInitBaseTestCase
final SAML2StringAttributeTranscoder transcoder = new SAML2StringAttributeTranscoder();
transcoder.initialize();
- registry.setNamingRegistry(Collections.singletonMap(
+ registry.addToNamingRegistry(Collections.singletonMap(
transcoder.getEncodedType(), new AbstractSAML2AttributeTranscoder.NamingFunction()));
final Map<String,Collection<Properties>> mappings = new HashMap<>();
@@ -101,7 +101,7 @@ public class SAML2StringAttributeTranscoderTest extends OpenSAMLInitBaseTestCase
mappings.put(ATTR_NAME, Collections.singletonList(ruleset1));
- registry.setTranscoderRegistry(mappings);
+ registry.addToTranscoderRegistry(mappings);
registry.initialize();
}
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the commits
mailing list