[java-identity-provider] 50/51: IDP-1408 Make Legacy Generators minimal implementations
Rod Widdowson
rdw at steadingsoftware.com
Wed Feb 6 08:43:21 EST 2019
This is an automated email from the git hooks/post-receive script.
rdw pushed a commit to branch master
in repository java-identity-provider.
View the commit online:
http://git.shibboleth.net/view/?p=java-identity-provider.git;a=commit;h=00ea231e8f485b5623fe8a85897b69a7174c0eea
commit 00ea231e8f485b5623fe8a85897b69a7174c0eea
Author: Rod Widdowson <rdw at steadingsoftware.com>
AuthorDate: Thu Jan 31 15:42:01 2019 +0000
IDP-1408 Make Legacy Generators minimal implementations
https://issues.shibboleth.net/jira/browse/IDP-1408
---
.../nameid/impl/LegacyNameIdentifierGenerator.java | 65 ++------
.../impl/LegacySAML1NameIdentifierGenerator.java | 9 +-
.../nameid/impl/LegacySAML2NameIDGenerator.java | 9 +-
.../LegacySAML1NameIdentifierGeneratorTest.java | 167 --------------------
.../impl/LegacySAML2NameIDGeneratorTest.java | 168 ---------------------
5 files changed, 14 insertions(+), 404 deletions(-)
diff --git a/idp-saml-impl/src/main/java/net/shibboleth/idp/saml/nameid/impl/LegacyNameIdentifierGenerator.java b/idp-saml-impl/src/main/java/net/shibboleth/idp/saml/nameid/impl/LegacyNameIdentifierGenerator.java
index 64e83ce..4495571 100644
--- a/idp-saml-impl/src/main/java/net/shibboleth/idp/saml/nameid/impl/LegacyNameIdentifierGenerator.java
+++ b/idp-saml-impl/src/main/java/net/shibboleth/idp/saml/nameid/impl/LegacyNameIdentifierGenerator.java
@@ -23,9 +23,16 @@ import java.util.function.Predicate;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
-import net.shibboleth.idp.attribute.AttributeEncoder;
-import net.shibboleth.idp.attribute.AttributeEncodingException;
-import net.shibboleth.idp.attribute.IdPAttribute;
+import org.opensaml.messaging.context.navigate.ChildContextLookup;
+import org.opensaml.profile.context.ProfileRequestContext;
+import org.opensaml.saml.common.SAMLException;
+import org.opensaml.saml.common.SAMLObject;
+import org.opensaml.saml.common.profile.NameIdentifierGenerator;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.base.Predicates;
+
import net.shibboleth.idp.attribute.context.AttributeContext;
import net.shibboleth.idp.profile.context.RelyingPartyContext;
import net.shibboleth.idp.saml.nameid.NameIdentifierAttributeEncoder;
@@ -37,16 +44,6 @@ import net.shibboleth.utilities.java.support.logic.Constraint;
import net.shibboleth.utilities.java.support.primitive.DeprecationSupport;
import net.shibboleth.utilities.java.support.primitive.DeprecationSupport.ObjectType;
-import org.opensaml.messaging.context.navigate.ChildContextLookup;
-import org.opensaml.profile.context.ProfileRequestContext;
-import org.opensaml.saml.common.SAMLException;
-import org.opensaml.saml.common.SAMLObject;
-import org.opensaml.saml.common.profile.NameIdentifierGenerator;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import com.google.common.base.Predicates;
-
/**
* Legacy generator of name identifier objects that relies on resolved attributes having
* {@link NameIdentifierAttributeEncoder}s attached.
@@ -74,17 +71,13 @@ public class LegacyNameIdentifierGenerator<NameIdType extends SAMLObject>
/** Lookup strategy for {@link AttributeContext}. */
@Nonnull private Function<ProfileRequestContext, AttributeContext> attributeContextLookupStrategy;
- /** Type of encoder to check for when looping. */
- @Nonnull private Class<? extends NameIdentifierAttributeEncoder> encoderType;
/**
* Constructor.
*
- * @param clazz encoder class type
*/
- protected LegacyNameIdentifierGenerator(@Nonnull final Class<? extends NameIdentifierAttributeEncoder> clazz) {
+ protected LegacyNameIdentifierGenerator() {
activationCondition = Predicates.alwaysTrue();
- encoderType = Constraint.isNotNull(clazz, "Encoder class type cannot be null");
// ProfileRequestContext -> RelyingPartyContext -> AttributeContext
attributeContextLookupStrategy = new ChildContextLookup<>(AttributeContext.class).compose(
@@ -123,47 +116,13 @@ public class LegacyNameIdentifierGenerator<NameIdType extends SAMLObject>
DeprecationSupport.warn(ObjectType.CLASS, getClass().getName(), null, null);
}
- // Checkstyle: CyclomaticComplexity OFF
/** {@inheritDoc} */
@Override
@Nullable public NameIdType generate(@Nonnull final ProfileRequestContext profileRequestContext,
@Nonnull @NotEmpty final String format) throws SAMLException {
ComponentSupport.ifNotInitializedThrowUninitializedComponentException(this);
Constraint.isNotNull(format, "Format cannot be null or empty");
-
- if (!activationCondition.test(profileRequestContext)) {
- return null;
- }
-
- final AttributeContext attributeContext = attributeContextLookupStrategy.apply(profileRequestContext);
- if (attributeContext == null || attributeContext.getIdPAttributes().isEmpty()) {
- log.debug("No AttributeContext or resolved IdPAttributes found, nothing to do");
- return null;
- }
-
- for (final IdPAttribute idpAttribute : attributeContext.getIdPAttributes().values()) {
- if (idpAttribute.getValues().isEmpty()) {
- continue;
- }
- for (final AttributeEncoder encoder : idpAttribute.getEncoders()) {
- if (encoderType.isInstance(encoder) && ((NameIdentifierAttributeEncoder) encoder).test(format)
- && encoder.getActivationCondition().test(profileRequestContext)) {
- try {
- // The encoders throw unless they return an object.
- final NameIdType nameId = (NameIdType) encoder.encode(idpAttribute);
- log.debug("Encoded attribute {} into name identifier with format {}", idpAttribute.getId(),
- format);
- return nameId;
- } catch (final AttributeEncodingException e) {
- log.error("Error encoding IdPAttribute into name identifier", e);
- }
- }
- }
- }
-
- log.debug("Unable to obtain name identifier from legacy attribute encoders");
+ log.error("Legacy encoding as NameID not supported");
return null;
}
-// Checkstyle: CyclomaticComplexity ON
-
}
\ No newline at end of file
diff --git a/idp-saml-impl/src/main/java/net/shibboleth/idp/saml/nameid/impl/LegacySAML1NameIdentifierGenerator.java b/idp-saml-impl/src/main/java/net/shibboleth/idp/saml/nameid/impl/LegacySAML1NameIdentifierGenerator.java
index 105b826..7a81b0d 100644
--- a/idp-saml-impl/src/main/java/net/shibboleth/idp/saml/nameid/impl/LegacySAML1NameIdentifierGenerator.java
+++ b/idp-saml-impl/src/main/java/net/shibboleth/idp/saml/nameid/impl/LegacySAML1NameIdentifierGenerator.java
@@ -17,14 +17,11 @@
package net.shibboleth.idp.saml.nameid.impl;
-import net.shibboleth.idp.saml.nameid.SAML1NameIdentifierAttributeEncoder;
-
import org.opensaml.saml.saml1.core.NameIdentifier;
import org.opensaml.saml.saml1.profile.SAML1NameIdentifierGenerator;
/**
- * Legacy generator of {@link NameIdentifier} objects that relies on resolved attributes having
- * {@link SAML1NameIdentifierAttributeEncoder}s attached.
+ * Legacy generator of {@link NameIdentifier} objects that fails
*
* <p>See the base class for additional detail.</p>
*
@@ -33,9 +30,5 @@ import org.opensaml.saml.saml1.profile.SAML1NameIdentifierGenerator;
public class LegacySAML1NameIdentifierGenerator extends LegacyNameIdentifierGenerator<NameIdentifier>
implements SAML1NameIdentifierGenerator {
- /** Constructor. */
- protected LegacySAML1NameIdentifierGenerator() {
- super(SAML1NameIdentifierAttributeEncoder.class);
- }
}
\ No newline at end of file
diff --git a/idp-saml-impl/src/main/java/net/shibboleth/idp/saml/nameid/impl/LegacySAML2NameIDGenerator.java b/idp-saml-impl/src/main/java/net/shibboleth/idp/saml/nameid/impl/LegacySAML2NameIDGenerator.java
index c4a9812..ea1457f 100644
--- a/idp-saml-impl/src/main/java/net/shibboleth/idp/saml/nameid/impl/LegacySAML2NameIDGenerator.java
+++ b/idp-saml-impl/src/main/java/net/shibboleth/idp/saml/nameid/impl/LegacySAML2NameIDGenerator.java
@@ -17,14 +17,11 @@
package net.shibboleth.idp.saml.nameid.impl;
-import net.shibboleth.idp.saml.nameid.SAML2NameIDAttributeEncoder;
-
import org.opensaml.saml.saml2.core.NameID;
import org.opensaml.saml.saml2.profile.SAML2NameIDGenerator;
/**
- * Legacy generator of {@link NameID} objects that relies on resolved attributes having
- * {@link SAML2NameIDAttributeEncoder}s attached.
+ * Legacy generator of {@link NameID} objects that fails
*
* <p>See the base class for additional detail.</p>
*
@@ -33,9 +30,5 @@ import org.opensaml.saml.saml2.profile.SAML2NameIDGenerator;
public class LegacySAML2NameIDGenerator extends LegacyNameIdentifierGenerator<NameID>
implements SAML2NameIDGenerator {
- /** Constructor. */
- protected LegacySAML2NameIDGenerator() {
- super(SAML2NameIDAttributeEncoder.class);
- }
}
\ No newline at end of file
diff --git a/idp-saml-impl/src/test/java/net/shibboleth/idp/saml/nameid/impl/LegacySAML1NameIdentifierGeneratorTest.java b/idp-saml-impl/src/test/java/net/shibboleth/idp/saml/nameid/impl/LegacySAML1NameIdentifierGeneratorTest.java
deleted file mode 100644
index eab773f..0000000
--- a/idp-saml-impl/src/test/java/net/shibboleth/idp/saml/nameid/impl/LegacySAML1NameIdentifierGeneratorTest.java
+++ /dev/null
@@ -1,167 +0,0 @@
-/*
- * 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.nameid.impl;
-
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Collections;
-
-import net.shibboleth.idp.attribute.AttributeEncoder;
-import net.shibboleth.idp.attribute.IdPAttributeValue;
-import net.shibboleth.idp.attribute.IdPAttribute;
-import net.shibboleth.idp.attribute.StringAttributeValue;
-import net.shibboleth.idp.attribute.context.AttributeContext;
-import net.shibboleth.idp.profile.RequestContextBuilder;
-import net.shibboleth.idp.profile.context.RelyingPartyContext;
-import net.shibboleth.idp.saml.attribute.encoding.impl.SAML1StringNameIdentifierEncoder;
-import net.shibboleth.utilities.java.support.component.ComponentInitializationException;
-
-import org.opensaml.core.OpenSAMLInitBaseTestCase;
-import org.opensaml.profile.context.ProfileRequestContext;
-import org.opensaml.saml.saml1.core.NameIdentifier;
-import org.testng.Assert;
-import org.testng.annotations.BeforeMethod;
-import org.testng.annotations.Test;
-
-/** Unit test for {@link LegacySAML1NameIdentifierGenerator}. */
- at SuppressWarnings("deprecation")
-public class LegacySAML1NameIdentifierGeneratorTest extends OpenSAMLInitBaseTestCase {
-
- /** The name we give the test attribute. */
- private final static String ATTR_NAME = "foo";
-
- /** test values. */
- private final static String NAME_1 = "NameId1";
-
- private final static String QUALIFIER = "Qualifier";
-
- private LegacySAML1NameIdentifierGenerator generator;
-
- private ProfileRequestContext prc;
-
- @BeforeMethod public void initTest() throws ComponentInitializationException {
- generator = new LegacySAML1NameIdentifierGenerator();
- generator.setId("this");
- generator.initialize();
- prc = new RequestContextBuilder().buildProfileRequestContext();
- }
-
- @Test public void testNoAttributes() throws Exception {
- NameIdentifier outputNameId = generator.generate(prc, NameIdentifier.X509_SUBJECT);
- Assert.assertNull(outputNameId);
-
- prc.getSubcontext(RelyingPartyContext.class).getSubcontext(AttributeContext.class, true);
- outputNameId = generator.generate(prc, NameIdentifier.X509_SUBJECT);
- Assert.assertNull(outputNameId);
- }
-
- @Test public void testNoValues() throws Exception {
- final IdPAttribute inputAttribute = new IdPAttribute(ATTR_NAME);
-
- final SAML1StringNameIdentifierEncoder encoder = new SAML1StringNameIdentifierEncoder();
- encoder.setNameQualifier(QUALIFIER);
- encoder.setNameFormat(NameIdentifier.EMAIL);
- inputAttribute.setEncoders(Collections.<AttributeEncoder<?>>singleton(encoder));
-
- prc.getSubcontext(RelyingPartyContext.class).getSubcontext(AttributeContext.class, true).setIdPAttributes(
- Collections.singleton(inputAttribute));
-
- NameIdentifier outputNameId = generator.generate(prc, NameIdentifier.X509_SUBJECT);
- Assert.assertNull(outputNameId);
- }
-
- @Test public void testNoEncoders() throws Exception {
- final Collection<? extends IdPAttributeValue<?>> values =
- Collections.singletonList(new StringAttributeValue(NAME_1));
-
- final IdPAttribute inputAttribute = new IdPAttribute(ATTR_NAME);
- inputAttribute.setValues(values);
-
- prc.getSubcontext(RelyingPartyContext.class).getSubcontext(AttributeContext.class, true).setIdPAttributes(
- Collections.singleton(inputAttribute));
-
- NameIdentifier outputNameId = generator.generate(prc, NameIdentifier.X509_SUBJECT);
- Assert.assertNull(outputNameId);
- }
-
- @Test public void testWrongFormat() throws Exception {
- final Collection<? extends IdPAttributeValue<?>> values =
- Collections.singletonList(new StringAttributeValue(NAME_1));
-
- final IdPAttribute inputAttribute = new IdPAttribute(ATTR_NAME);
- inputAttribute.setValues(values);
-
- final SAML1StringNameIdentifierEncoder encoder = new SAML1StringNameIdentifierEncoder();
- encoder.setNameQualifier(QUALIFIER);
- encoder.setNameFormat(NameIdentifier.EMAIL);
- inputAttribute.setEncoders(Collections.<AttributeEncoder<?>>singleton(encoder));
-
- prc.getSubcontext(RelyingPartyContext.class).getSubcontext(AttributeContext.class, true).setIdPAttributes(
- Collections.singleton(inputAttribute));
-
- NameIdentifier outputNameId = generator.generate(prc, NameIdentifier.X509_SUBJECT);
- Assert.assertNull(outputNameId);
- }
-
- @Test public void testSingle() throws Exception {
- final Collection<? extends IdPAttributeValue<?>> values =
- Collections.singletonList(new StringAttributeValue(NAME_1));
-
- final IdPAttribute inputAttribute = new IdPAttribute(ATTR_NAME);
- inputAttribute.setValues(values);
-
- final SAML1StringNameIdentifierEncoder encoder = new SAML1StringNameIdentifierEncoder();
- encoder.setNameQualifier(QUALIFIER);
- encoder.setNameFormat(NameIdentifier.EMAIL);
- inputAttribute.setEncoders(Collections.<AttributeEncoder<?>>singleton(encoder));
-
- prc.getSubcontext(RelyingPartyContext.class).getSubcontext(AttributeContext.class, true).setIdPAttributes(
- Collections.singleton(inputAttribute));
-
- NameIdentifier outputNameId = generator.generate(prc, NameIdentifier.EMAIL);
- Assert.assertNotNull(outputNameId);
- Assert.assertEquals(outputNameId.getValue(), NAME_1);
- Assert.assertEquals(outputNameId.getFormat(), NameIdentifier.EMAIL);
- Assert.assertEquals(outputNameId.getNameQualifier(), QUALIFIER);
- }
-
- @Test public void testMultiple() throws Exception {
- final Collection<? extends IdPAttributeValue<?>> values =
- Collections.singletonList(new StringAttributeValue(NAME_1));
-
- final IdPAttribute inputAttribute = new IdPAttribute(ATTR_NAME);
- inputAttribute.setValues(values);
-
- final SAML1StringNameIdentifierEncoder encoder = new SAML1StringNameIdentifierEncoder();
- encoder.setNameQualifier(QUALIFIER);
- encoder.setNameFormat(NameIdentifier.EMAIL);
- final SAML1StringNameIdentifierEncoder encoder2 = new SAML1StringNameIdentifierEncoder();
- encoder.setNameQualifier(QUALIFIER);
- encoder.setNameFormat(NameIdentifier.X509_SUBJECT);
- inputAttribute.setEncoders(Arrays.<AttributeEncoder<?>>asList(encoder, encoder2));
-
- prc.getSubcontext(RelyingPartyContext.class).getSubcontext(AttributeContext.class, true).setIdPAttributes(
- Collections.singleton(inputAttribute));
-
- NameIdentifier outputNameId = generator.generate(prc, NameIdentifier.X509_SUBJECT);
- Assert.assertNotNull(outputNameId);
- Assert.assertEquals(outputNameId.getValue(), NAME_1);
- Assert.assertEquals(outputNameId.getFormat(), NameIdentifier.X509_SUBJECT);
- Assert.assertEquals(outputNameId.getNameQualifier(), QUALIFIER);
- }
-}
\ No newline at end of file
diff --git a/idp-saml-impl/src/test/java/net/shibboleth/idp/saml/nameid/impl/LegacySAML2NameIDGeneratorTest.java b/idp-saml-impl/src/test/java/net/shibboleth/idp/saml/nameid/impl/LegacySAML2NameIDGeneratorTest.java
deleted file mode 100644
index 754bded..0000000
--- a/idp-saml-impl/src/test/java/net/shibboleth/idp/saml/nameid/impl/LegacySAML2NameIDGeneratorTest.java
+++ /dev/null
@@ -1,168 +0,0 @@
-/*
- * 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.nameid.impl;
-
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Collections;
-
-import net.shibboleth.idp.attribute.AttributeEncoder;
-import net.shibboleth.idp.attribute.IdPAttributeValue;
-import net.shibboleth.idp.attribute.IdPAttribute;
-import net.shibboleth.idp.attribute.StringAttributeValue;
-import net.shibboleth.idp.attribute.context.AttributeContext;
-import net.shibboleth.idp.profile.RequestContextBuilder;
-import net.shibboleth.idp.profile.context.RelyingPartyContext;
-import net.shibboleth.idp.saml.attribute.encoding.impl.SAML2StringNameIDEncoder;
-import net.shibboleth.utilities.java.support.component.ComponentInitializationException;
-
-import org.opensaml.core.OpenSAMLInitBaseTestCase;
-import org.opensaml.profile.context.ProfileRequestContext;
-import org.opensaml.saml.saml1.core.NameIdentifier;
-import org.opensaml.saml.saml2.core.NameID;
-import org.testng.Assert;
-import org.testng.annotations.BeforeMethod;
-import org.testng.annotations.Test;
-
-/** Unit test for {@link LegacySAML2NameIDGenerator}. */
- at SuppressWarnings("deprecation")
-public class LegacySAML2NameIDGeneratorTest extends OpenSAMLInitBaseTestCase {
-
- /** The name we give the test attribute. */
- private final static String ATTR_NAME = "foo";
-
- /** test values. */
- private final static String NAME_1 = "NameId1";
-
- private final static String QUALIFIER = "Qualifier";
-
- private LegacySAML2NameIDGenerator generator;
-
- private ProfileRequestContext prc;
-
- @BeforeMethod public void initTest() throws ComponentInitializationException {
- generator = new LegacySAML2NameIDGenerator();
- generator.setId("test");
- generator.initialize();
- prc = new RequestContextBuilder().buildProfileRequestContext();
- }
-
- @Test public void testNoAttributes() throws Exception {
- NameID outputNameId = generator.generate(prc, NameID.X509_SUBJECT);
- Assert.assertNull(outputNameId);
-
- prc.getSubcontext(RelyingPartyContext.class).getSubcontext(AttributeContext.class, true);
- outputNameId = generator.generate(prc, NameID.X509_SUBJECT);
- Assert.assertNull(outputNameId);
- }
-
- @Test public void testNoValues() throws Exception {
- final IdPAttribute inputAttribute = new IdPAttribute(ATTR_NAME);
-
- final SAML2StringNameIDEncoder encoder = new SAML2StringNameIDEncoder();
- encoder.setNameQualifier(QUALIFIER);
- encoder.setNameFormat(NameIdentifier.EMAIL);
- inputAttribute.setEncoders(Collections.<AttributeEncoder<?>>singleton(encoder));
-
- prc.getSubcontext(RelyingPartyContext.class).getSubcontext(AttributeContext.class, true).setIdPAttributes(
- Collections.singleton(inputAttribute));
-
- NameID outputNameId = generator.generate(prc, NameID.X509_SUBJECT);
- Assert.assertNull(outputNameId);
- }
-
- @Test public void testNoEncoders() throws Exception {
- final Collection<? extends IdPAttributeValue<?>> values =
- Collections.singletonList(new StringAttributeValue(NAME_1));
-
- final IdPAttribute inputAttribute = new IdPAttribute(ATTR_NAME);
- inputAttribute.setValues(values);
-
- prc.getSubcontext(RelyingPartyContext.class).getSubcontext(AttributeContext.class, true).setIdPAttributes(
- Collections.singleton(inputAttribute));
-
- NameID outputNameId = generator.generate(prc, NameID.X509_SUBJECT);
- Assert.assertNull(outputNameId);
- }
-
- @Test public void testWrongFormat() throws Exception {
- final Collection<? extends IdPAttributeValue<?>> values =
- Collections.singletonList(new StringAttributeValue(NAME_1));
-
- final IdPAttribute inputAttribute = new IdPAttribute(ATTR_NAME);
- inputAttribute.setValues(values);
-
- final SAML2StringNameIDEncoder encoder = new SAML2StringNameIDEncoder();
- encoder.setNameQualifier(QUALIFIER);
- encoder.setNameFormat(NameID.EMAIL);
- inputAttribute.setEncoders(Collections.<AttributeEncoder<?>>singleton(encoder));
-
- prc.getSubcontext(RelyingPartyContext.class).getSubcontext(AttributeContext.class, true).setIdPAttributes(
- Collections.singleton(inputAttribute));
-
- NameID outputNameId = generator.generate(prc, NameID.X509_SUBJECT);
- Assert.assertNull(outputNameId);
- }
-
- @Test public void testSingle() throws Exception {
- final Collection<? extends IdPAttributeValue<?>> values =
- Collections.singletonList(new StringAttributeValue(NAME_1));
-
- final IdPAttribute inputAttribute = new IdPAttribute(ATTR_NAME);
- inputAttribute.setValues(values);
-
- final SAML2StringNameIDEncoder encoder = new SAML2StringNameIDEncoder();
- encoder.setNameQualifier(QUALIFIER);
- encoder.setNameFormat(NameID.EMAIL);
- inputAttribute.setEncoders(Collections.<AttributeEncoder<?>>singleton(encoder));
-
- prc.getSubcontext(RelyingPartyContext.class).getSubcontext(AttributeContext.class, true).setIdPAttributes(
- Collections.singleton(inputAttribute));
-
- NameID outputNameId = generator.generate(prc, NameID.EMAIL);
- Assert.assertNotNull(outputNameId);
- Assert.assertEquals(outputNameId.getValue(), NAME_1);
- Assert.assertEquals(outputNameId.getFormat(), NameID.EMAIL);
- Assert.assertEquals(outputNameId.getNameQualifier(), QUALIFIER);
- }
-
- @Test public void testMultiple() throws Exception {
- final Collection<? extends IdPAttributeValue<?>> values =
- Collections.singletonList(new StringAttributeValue(NAME_1));
-
- final IdPAttribute inputAttribute = new IdPAttribute(ATTR_NAME);
- inputAttribute.setValues(values);
-
- final SAML2StringNameIDEncoder encoder = new SAML2StringNameIDEncoder();
- encoder.setNameQualifier(QUALIFIER);
- encoder.setNameFormat(NameID.EMAIL);
- final SAML2StringNameIDEncoder encoder2 = new SAML2StringNameIDEncoder();
- encoder.setNameQualifier(QUALIFIER);
- encoder.setNameFormat(NameID.X509_SUBJECT);
- inputAttribute.setEncoders(Arrays.<AttributeEncoder<?>>asList(encoder, encoder2));
-
- prc.getSubcontext(RelyingPartyContext.class).getSubcontext(AttributeContext.class, true).setIdPAttributes(
- Collections.singleton(inputAttribute));
-
- NameID outputNameId = generator.generate(prc, NameID.X509_SUBJECT);
- Assert.assertNotNull(outputNameId);
- Assert.assertEquals(outputNameId.getValue(), NAME_1);
- Assert.assertEquals(outputNameId.getFormat(), NameID.X509_SUBJECT);
- Assert.assertEquals(outputNameId.getNameQualifier(), QUALIFIER);
- }
-}
\ 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