[java-identity-provider] 03/51: IDP-1121 Remove Principal Connectors. Implementation and tests

Rod Widdowson rdw at steadingsoftware.com
Wed Feb 6 08:42:34 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=d4cea9dc3327d3780abf49b46c0cdba7004cee43

commit d4cea9dc3327d3780abf49b46c0cdba7004cee43
Author: Rod Widdowson <rdw at steadingsoftware.com>
AuthorDate: Thu Nov 22 10:30:54 2018 +0000

    IDP-1121 Remove Principal Connectors.  Implementation and tests
    
    https://issues.shibboleth.net/jira/browse/IDP-1121
---
 .../impl/AttributeResolverServiceStrategy.java     |   2 -
 .../resolver/spring/AttributeResolverTest.java     |   1 -
 .../saml/nameid/impl/LegacyCanonicalization.java   | 103 +--------
 .../impl/PrincipalConnectorTest.java               | 145 ------------
 .../impl/PrinicpalConnectorCanonicalizerTest.java  | 243 ---------------------
 5 files changed, 6 insertions(+), 488 deletions(-)

diff --git a/idp-attribute-resolver-spring/src/main/java/net/shibboleth/idp/attribute/resolver/spring/impl/AttributeResolverServiceStrategy.java b/idp-attribute-resolver-spring/src/main/java/net/shibboleth/idp/attribute/resolver/spring/impl/AttributeResolverServiceStrategy.java
index e0ee46a..025833e 100644
--- a/idp-attribute-resolver-spring/src/main/java/net/shibboleth/idp/attribute/resolver/spring/impl/AttributeResolverServiceStrategy.java
+++ b/idp-attribute-resolver-spring/src/main/java/net/shibboleth/idp/attribute/resolver/spring/impl/AttributeResolverServiceStrategy.java
@@ -31,8 +31,6 @@ import net.shibboleth.idp.attribute.resolver.AttributeDefinition;
 import net.shibboleth.idp.attribute.resolver.AttributeResolver;
 import net.shibboleth.idp.attribute.resolver.DataConnector;
 import net.shibboleth.idp.attribute.resolver.impl.AttributeResolverImpl;
-import net.shibboleth.idp.saml.attribute.principalconnector.impl.PrincipalConnector;
-import net.shibboleth.idp.saml.attribute.principalconnector.impl.PrinicpalConnectorCanonicalizer;
 import net.shibboleth.utilities.java.support.component.AbstractIdentifiableInitializableComponent;
 import net.shibboleth.utilities.java.support.component.ComponentInitializationException;
 import net.shibboleth.utilities.java.support.service.ServiceException;
diff --git a/idp-attribute-resolver-spring/src/test/java/net/shibboleth/idp/attribute/resolver/spring/AttributeResolverTest.java b/idp-attribute-resolver-spring/src/test/java/net/shibboleth/idp/attribute/resolver/spring/AttributeResolverTest.java
index 10a1a2c..234d901 100644
--- a/idp-attribute-resolver-spring/src/test/java/net/shibboleth/idp/attribute/resolver/spring/AttributeResolverTest.java
+++ b/idp-attribute-resolver-spring/src/test/java/net/shibboleth/idp/attribute/resolver/spring/AttributeResolverTest.java
@@ -51,7 +51,6 @@ import net.shibboleth.idp.attribute.IdPAttribute;
 import net.shibboleth.idp.attribute.IdPAttributeValue;
 import net.shibboleth.idp.attribute.StringAttributeValue;
 import net.shibboleth.idp.attribute.resolver.AttributeResolver;
-import net.shibboleth.idp.attribute.resolver.LegacyPrincipalDecoder;
 import net.shibboleth.idp.attribute.resolver.ResolutionException;
 import net.shibboleth.idp.attribute.resolver.context.AttributeResolutionContext;
 import net.shibboleth.idp.authn.context.SubjectCanonicalizationContext;
diff --git a/idp-saml-impl/src/main/java/net/shibboleth/idp/saml/nameid/impl/LegacyCanonicalization.java b/idp-saml-impl/src/main/java/net/shibboleth/idp/saml/nameid/impl/LegacyCanonicalization.java
index 3a968e9..7615c1a 100644
--- a/idp-saml-impl/src/main/java/net/shibboleth/idp/saml/nameid/impl/LegacyCanonicalization.java
+++ b/idp-saml-impl/src/main/java/net/shibboleth/idp/saml/nameid/impl/LegacyCanonicalization.java
@@ -22,7 +22,6 @@ import java.util.function.Predicate;
 
 import javax.annotation.Nonnull;
 import javax.annotation.Nullable;
-import javax.security.auth.Subject;
 
 import org.opensaml.profile.action.ActionSupport;
 import org.opensaml.profile.context.ProfileRequestContext;
@@ -30,8 +29,6 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 import net.shibboleth.idp.attribute.resolver.AttributeResolver;
-import net.shibboleth.idp.attribute.resolver.LegacyPrincipalDecoder;
-import net.shibboleth.idp.attribute.resolver.ResolutionException;
 import net.shibboleth.idp.authn.AbstractSubjectCanonicalizationAction;
 import net.shibboleth.idp.authn.AuthnEventIds;
 import net.shibboleth.idp.authn.context.SubjectCanonicalizationContext;
@@ -41,7 +38,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 net.shibboleth.utilities.java.support.service.ReloadableService;
-import net.shibboleth.utilities.java.support.service.ServiceableComponent;
 
 /**
  * Action to fail if asked to perform C14N ..
@@ -51,9 +47,6 @@ public class LegacyCanonicalization extends AbstractSubjectCanonicalizationActio
     /** Class logger. */
     @Nonnull private final Logger log = LoggerFactory.getLogger(LegacyCanonicalization.class);
     
-    /** Service used to get the resolver used to fetch attributes. */
-    @Nonnull private final ReloadableService<AttributeResolver> attributeResolverService;
-
     /**
      * Constructor.
      * 
@@ -61,7 +54,7 @@ public class LegacyCanonicalization extends AbstractSubjectCanonicalizationActio
      */
     public LegacyCanonicalization(@Nonnull @ParameterName(name="resolverService") 
                         final ReloadableService<AttributeResolver> resolverService) {
-        attributeResolverService = Constraint.isNotNull(resolverService, "AttributeResolver cannot be null");
+        Constraint.isNotNull(resolverService, "AttributeResolver cannot be null");
     }
     
 //CheckStyle: ReturnCount OFF
@@ -69,47 +62,8 @@ public class LegacyCanonicalization extends AbstractSubjectCanonicalizationActio
     @Override protected void doExecute(@Nonnull final ProfileRequestContext profileRequestContext,
             @Nonnull final SubjectCanonicalizationContext c14nContext) {
 
-        ServiceableComponent<AttributeResolver> component = null;
-        try {
-            component = attributeResolverService.getServiceableComponent();
-            if (null == component) {
-                log.error("{} Error resolving PrincipalConnector: Invalid Attribute resolver configuration.",
-                        getLogPrefix());
-                c14nContext.setException(new SubjectCanonicalizationException(
-                        "Error resolving PrincipalConnectore: Invalid Attribute resolver configuration."));
-                ActionSupport.buildEvent(profileRequestContext, AuthnEventIds.INVALID_SUBJECT);
-                return;
-            }
-
-            final AttributeResolver attributeResolver = component.getComponent();
-            if (!(attributeResolver instanceof LegacyPrincipalDecoder)) {
-                log.info("{} Attribute Resolver did not implement LegacyPrincipalDecoder.", getLogPrefix());
-                c14nContext.setException(new SubjectCanonicalizationException(
-                        "Attribute Resolver did not implement LegacyPrincipalDecoder."));
-                ActionSupport.buildEvent(profileRequestContext, AuthnEventIds.INVALID_SUBJECT);
-                return;
-            }
-
-            final LegacyPrincipalDecoder decoder = (LegacyPrincipalDecoder) attributeResolver;
-
-            final String decodedPrincipal = decoder.canonicalize(c14nContext);
-            if (null == decodedPrincipal) {
-                log.info("{} Legacy Principal Decoding returned no value", getLogPrefix());
-                c14nContext.setException(new SubjectCanonicalizationException(
-                        "Legacy Principal Decoding returned no value"));
-                ActionSupport.buildEvent(profileRequestContext, AuthnEventIds.INVALID_SUBJECT);
-                return;
-            }
-            
-            c14nContext.setPrincipalName(decodedPrincipal);
-        } catch (final ResolutionException e) {
-            c14nContext.setException(e);
-            ActionSupport.buildEvent(profileRequestContext, AuthnEventIds.SUBJECT_C14N_ERROR);
-        } finally {
-            if (null != component) {
-                component.unpinComponent();
-            }
-        }
+        log.error("legacy C14N no supported");
+        ActionSupport.buildEvent(profileRequestContext, AuthnEventIds.INVALID_SUBJECT_C14N_CTX);
     }
 //CheckStyle: ReturnCount ON
     
@@ -126,8 +80,7 @@ public class LegacyCanonicalization extends AbstractSubjectCanonicalizationActio
     }
 
     /**
-     * A predicate that determines if this action can run or not - it does this by inspecting the attribute resolver for
-     * principal connectors.
+     * A predicate that determines if this action can run or not.  This can never run.
      */
     public static class ActivationCondition implements Predicate<ProfileRequestContext> {
 
@@ -146,54 +99,10 @@ public class LegacyCanonicalization extends AbstractSubjectCanonicalizationActio
         /**
          * {@inheritDoc}
          * 
-         * <p>Iff there is a valid service and there are no parsing errors and the service does understand
-         * principal connectors and there were some configured we will proceed.</p>
+         * <p>Never run this</p>
          */
         public boolean test(@Nullable final ProfileRequestContext input) {
-
-            if (null == input) {
-                return false;
-            }
-            
-            final SubjectCanonicalizationContext c14nContext =
-                    input.getSubcontext(SubjectCanonicalizationContext.class);
-            if (null == c14nContext) {
-                return false;
-            }
-
-            final Subject subject = c14nContext.getSubject();
-            if (null == subject) {
-                return false;
-            }
-            
-            final Set<NameIDPrincipal> nameIDs = subject.getPrincipals(NameIDPrincipal.class);
-            final Set<NameIdentifierPrincipal> nameIdentifiers = subject.getPrincipals(NameIdentifierPrincipal.class);
-            if (1 != nameIDs.size() + nameIdentifiers.size()) {
-                return false;
-            }
-            
-            if (null == attributeResolverService) {
-                return false;
-            }
-
-            ServiceableComponent<AttributeResolver> component = null;
-            try {
-                component = attributeResolverService.getServiceableComponent();
-                if (null == component) {
-                    return false;
-                }
-
-                final AttributeResolver attributeResolver = component.getComponent();
-                if (!(attributeResolver instanceof LegacyPrincipalDecoder)) {
-                    return false;
-                }
-                return ((LegacyPrincipalDecoder) attributeResolver).hasValidConnectors();
-            } finally {
-                if (null != component) {
-                    component.unpinComponent();
-                }
-            }
+            return false;
         }
     }
-
 }
\ No newline at end of file
diff --git a/idp-saml-impl/src/test/java/net/shibboleth/idp/saml/attribute/principalconnector/impl/PrincipalConnectorTest.java b/idp-saml-impl/src/test/java/net/shibboleth/idp/saml/attribute/principalconnector/impl/PrincipalConnectorTest.java
deleted file mode 100644
index c0702d5..0000000
--- a/idp-saml-impl/src/test/java/net/shibboleth/idp/saml/attribute/principalconnector/impl/PrincipalConnectorTest.java
+++ /dev/null
@@ -1,145 +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.attribute.principalconnector.impl;
-
-import java.util.Collections;
-
-import javax.annotation.Nonnull;
-
-import net.shibboleth.idp.authn.SubjectCanonicalizationException;
-import net.shibboleth.idp.authn.context.SubjectCanonicalizationContext;
-import net.shibboleth.idp.saml.nameid.NameDecoderException;
-import net.shibboleth.idp.saml.nameid.NameIDDecoder;
-import net.shibboleth.idp.saml.nameid.NameIdentifierDecoder;
-import net.shibboleth.idp.saml.nameid.impl.TransformingNameIDDecoder;
-import net.shibboleth.idp.saml.nameid.impl.TransformingNameIdentifierDecoder;
-import net.shibboleth.utilities.java.support.component.ComponentInitializationException;
-import net.shibboleth.utilities.java.support.component.ComponentSupport;
-import net.shibboleth.utilities.java.support.component.UnmodifiableComponentException;
-
-import org.opensaml.core.OpenSAMLInitBaseTestCase;
-import org.opensaml.core.xml.config.XMLObjectProviderRegistrySupport;
-import org.opensaml.saml.common.SAMLObjectBuilder;
-import org.opensaml.saml.saml1.core.NameIdentifier;
-import org.opensaml.saml.saml2.core.NameID;
-import org.testng.Assert;
-import org.testng.annotations.BeforeClass;
-import org.testng.annotations.Test;
-
-/**
- * tests for {@link PrincipalConnector}.
- */
-public class PrincipalConnectorTest extends OpenSAMLInitBaseTestCase {
-    
-    private static final String NAMEID_TEXT = "NAMEID_TEXT";
-
-    private static final String NAMEIDENTIFIER_TEXT = "SAML1_TEXT";
-
-    private static final String RP1 = "https://shibboleth.net/rp1";
-
-    private static final String RP2 = "https://shibboleth.net/rp2";
-    
-    private final TransformingNameIDDecoder nameIDDecoder = new TransformingNameIDDecoder();
-    
-    private final TransformingNameIdentifierDecoder nameIdentifierDecoder = new TransformingNameIdentifierDecoder();
-    
-    @BeforeClass public void setup() throws ComponentInitializationException {
-        nameIDDecoder.setId("nameIDDecoder");
-        ComponentSupport.initialize(nameIDDecoder);
-        nameIdentifierDecoder.setId("nameIdentifierDecoder");
-        ComponentSupport.initialize(nameIdentifierDecoder);
-    }
-    
-    @Test public void format() {
-        final PrincipalConnector connector = newPrincipalConnector(nameIDDecoder, nameIdentifierDecoder, NameID.KERBEROS);
-        
-        Assert.assertEquals(connector.getFormat(), NameID.KERBEROS);
-    }
-    
-    @Test public void relyingParties() throws ComponentInitializationException {
-        
-        PrincipalConnector connector = newPrincipalConnector(nameIDDecoder, nameIdentifierDecoder, NameID.KERBEROS);
-        connector.setId("relyingParties");
-        connector.initialize();
-        
-        Assert.assertTrue(connector.requesterMatches(null));
-        Assert.assertTrue(connector.requesterMatches(RP1));
-        Assert.assertTrue(connector.requesterMatches(RP2));
-        
-        try {
-            connector.setRelyingParties(Collections.singleton(RP1));
-            Assert.fail();
-        } catch (final UnmodifiableComponentException e) {
-            // OK
-        }
-
-        connector = newPrincipalConnector(nameIDDecoder, nameIdentifierDecoder, NameID.KERBEROS);
-        connector.setId("relyingParties");
-        connector.setRelyingParties(Collections.singleton(RP1));
-        connector.initialize();
-        
-        Assert.assertTrue(connector.requesterMatches(null));
-        Assert.assertTrue(connector.requesterMatches(RP1));
-        Assert.assertFalse(connector.requesterMatches(RP2));        
-    }
-    
-    @Test public void saml1() throws ComponentInitializationException, SubjectCanonicalizationException, NameDecoderException {
-        final PrincipalConnector connector = newPrincipalConnector(nameIDDecoder, nameIdentifierDecoder, NameID.KERBEROS);
-        connector.setId("saml1");
-        connector.initialize();
-        
-        final SAMLObjectBuilder<NameIdentifier> builder = (SAMLObjectBuilder<NameIdentifier>)
-                XMLObjectProviderRegistrySupport.getBuilderFactory().<NameIdentifier>getBuilderOrThrow(
-                        NameIdentifier.DEFAULT_ELEMENT_NAME);        
-        final NameIdentifier nameIdentifier = builder.buildObject();
-        nameIdentifier.setValue(NAMEIDENTIFIER_TEXT);
-        
-        final SubjectCanonicalizationContext scc = new SubjectCanonicalizationContext();
-        scc.setRequesterId(RP1);
-
-        Assert.assertEquals(connector.decode(scc, nameIdentifier), NAMEIDENTIFIER_TEXT);
-    }
-    
-    @Test public void saml2() throws ComponentInitializationException, SubjectCanonicalizationException, NameDecoderException {
-        final PrincipalConnector connector = newPrincipalConnector(nameIDDecoder, nameIdentifierDecoder, NameID.KERBEROS);
-        connector.setId("saml1");
-        connector.initialize();
-        
-        final SAMLObjectBuilder<NameID> builder = (SAMLObjectBuilder<NameID>)
-                XMLObjectProviderRegistrySupport.getBuilderFactory().<NameID>getBuilderOrThrow(
-                        NameID.DEFAULT_ELEMENT_NAME);        
-        final NameID nameID = builder.buildObject();
-        nameID.setValue(NAMEID_TEXT);
-
-        final SubjectCanonicalizationContext scc = new SubjectCanonicalizationContext();
-        scc.setRequesterId(RP1);
-
-        Assert.assertEquals(connector.decode(scc, nameID), NAMEID_TEXT);
-    }
-
-    public static PrincipalConnector newPrincipalConnector(@Nonnull  final NameIDDecoder saml2Decoder,
-            @Nonnull final NameIdentifierDecoder saml1Decoder,
-            @Nonnull final String theFormat) {
-        
-        final PrincipalConnector pc = new PrincipalConnector();
-        pc.setFormat(theFormat);
-        pc.setNameIDDecoder(saml2Decoder);
-        pc.setNameIdentifierDecoder(saml1Decoder);
-        return pc;
-    }
-}
diff --git a/idp-saml-impl/src/test/java/net/shibboleth/idp/saml/attribute/principalconnector/impl/PrinicpalConnectorCanonicalizerTest.java b/idp-saml-impl/src/test/java/net/shibboleth/idp/saml/attribute/principalconnector/impl/PrinicpalConnectorCanonicalizerTest.java
deleted file mode 100644
index 1f32ffe..0000000
--- a/idp-saml-impl/src/test/java/net/shibboleth/idp/saml/attribute/principalconnector/impl/PrinicpalConnectorCanonicalizerTest.java
+++ /dev/null
@@ -1,243 +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.attribute.principalconnector.impl;
-
-import java.util.Collection;
-import java.util.HashSet;
-
-import javax.annotation.Nonnull;
-import javax.security.auth.Subject;
-
-import net.shibboleth.idp.attribute.resolver.ResolutionException;
-import net.shibboleth.idp.authn.context.SubjectCanonicalizationContext;
-import net.shibboleth.idp.authn.principal.UsernamePrincipal;
-import net.shibboleth.idp.saml.authn.principal.NameIDPrincipal;
-import net.shibboleth.idp.saml.authn.principal.NameIdentifierPrincipal;
-import net.shibboleth.idp.saml.nameid.NameDecoderException;
-import net.shibboleth.idp.saml.nameid.NameIDDecoder;
-import net.shibboleth.idp.saml.nameid.NameIdentifierDecoder;
-
-import org.opensaml.core.OpenSAMLInitBaseTestCase;
-import org.opensaml.core.xml.config.XMLObjectProviderRegistrySupport;
-import org.opensaml.saml.common.SAMLObjectBuilder;
-import org.opensaml.saml.saml1.core.NameIdentifier;
-import org.opensaml.saml.saml2.core.NameID;
-import org.testng.Assert;
-import org.testng.annotations.BeforeClass;
-import org.testng.annotations.Test;
-
-/**
- * tests for {@link PrinicpalConnectorCanonicalizer}.
- */
-public class PrinicpalConnectorCanonicalizerTest extends OpenSAMLInitBaseTestCase {
-
-    private SAMLObjectBuilder<NameID> nameIDBuilder;        
-
-    private SAMLObjectBuilder<NameIdentifier> nameIdentifierBuilder;
-
-    private TestCanonicalizer testCanon;
-
-    @BeforeClass public void setup() {
-        nameIDBuilder = (SAMLObjectBuilder<NameID>)
-                XMLObjectProviderRegistrySupport.getBuilderFactory().<NameID>getBuilderOrThrow(
-                        NameID.DEFAULT_ELEMENT_NAME);        
-
-        nameIdentifierBuilder = (SAMLObjectBuilder<NameIdentifier>)
-                XMLObjectProviderRegistrySupport.getBuilderFactory().<NameIdentifier>getBuilderOrThrow(
-                        NameIdentifier.DEFAULT_ELEMENT_NAME);        
-
-        final Collection<PrincipalConnector> connectors = new HashSet<>(3);
-
-        MyDecoder decoder = new MyDecoder(NameID.KERBEROS);
-        connectors.add(PrincipalConnectorTest.newPrincipalConnector(decoder, decoder, NameID.KERBEROS));
-
-        decoder = new MyDecoder(NameID.UNSPECIFIED);
-        connectors.add(PrincipalConnectorTest.newPrincipalConnector(decoder, decoder, NameIdentifier.UNSPECIFIED));
-
-        testCanon = new TestCanonicalizer(connectors);
-    }
-
-    @Test public void testCanonicalize() throws ResolutionException {
-
-        final Subject subject = new Subject();
-        final SubjectCanonicalizationContext context = new SubjectCanonicalizationContext();
-
-        context.setSubject(subject);
-        Assert.assertNull(testCanon.canonicalize(context));
-
-        subject.getPrincipals().add(new UsernamePrincipal("user"));
-        context.setSubject(subject);
-        Assert.assertNull(testCanon.canonicalize(context));
-
-        context.setRequesterId("Requester");
-        context.setResponderId("Responder");
-
-        subject.getPrincipals().clear();
-        NameIdentifier nameIdentifier = nameIdentifierBuilder.buildObject();
-        subject.getPrincipals().add(new NameIdentifierPrincipal(nameIdentifier));
-        Assert.assertEquals(testCanon.canonicalize(context), "nameIdentifier");
-
-        nameIdentifier = nameIdentifierBuilder.buildObject();
-        nameIdentifier.setFormat(NameIdentifier.WIN_DOMAIN_QUALIFIED);
-        subject.getPrincipals().add(new NameIdentifierPrincipal(nameIdentifier));
-        Assert.assertNull(testCanon.canonicalize(context), "too many NameIdentifiers");
-
-        NameID nameID = nameIDBuilder.buildObject();
-        subject.getPrincipals().add(new NameIDPrincipal(nameID));
-        Assert.assertEquals(testCanon.canonicalize(context), "nameID");
-
-        nameID = nameIDBuilder.buildObject();
-        nameID.setFormat(NameIdentifier.UNSPECIFIED);
-        subject.getPrincipals().add(new NameIDPrincipal(nameID));
-        Assert.assertNull(testCanon.canonicalize(context), "Too many NameIDs");
-    }
-
-    @Test public void testSAML1() throws ResolutionException {
-        final Subject subject = new Subject();
-        final SubjectCanonicalizationContext context = new SubjectCanonicalizationContext();
-        NameIdentifier nameIdentifier = nameIdentifierBuilder.buildObject();
-        nameIdentifier.setValue("val");
-        subject.getPrincipals().add(new NameIdentifierPrincipal(nameIdentifier));
-        context.setSubject(subject);
-        context.setRequesterId("S1Requester");
-        context.setResponderId("S1Responder");
-
-        Assert.assertEquals(testCanon.doCanonicalize(nameIdentifier, context), NameIdentifier.UNSPECIFIED
-                + nameIdentifier.getValue() + context.getRequesterId() + context.getResponderId());
-
-        subject.getPrincipals().clear();
-        nameIdentifier = nameIdentifierBuilder.buildObject();
-        nameIdentifier.setValue("val2");
-        nameIdentifier.setFormat(NameIdentifier.UNSPECIFIED);
-        subject.getPrincipals().add(new NameIdentifierPrincipal(nameIdentifier));
-        Assert.assertEquals(testCanon.doCanonicalize(nameIdentifier, context), NameIdentifier.UNSPECIFIED
-                + nameIdentifier.getValue() + context.getRequesterId() + context.getResponderId());
-
-        subject.getPrincipals().clear();
-        nameIdentifier = nameIdentifierBuilder.buildObject();
-        nameIdentifier.setValue("val3");
-        nameIdentifier.setFormat(NameIdentifier.WIN_DOMAIN_QUALIFIED);
-        subject.getPrincipals().add(new NameIdentifierPrincipal(nameIdentifier));
-        Assert.assertNull(testCanon.doCanonicalize(nameIdentifier, context));
-
-        subject.getPrincipals().clear();
-        nameIdentifier = nameIdentifierBuilder.buildObject();
-        nameIdentifier.setValue("val4");
-        nameIdentifier.setFormat(NameID.KERBEROS);
-        subject.getPrincipals().add(new NameIdentifierPrincipal(nameIdentifier));
-        Assert.assertEquals(
-                testCanon.doCanonicalize(nameIdentifier, context),
-                NameID.KERBEROS + nameIdentifier.getValue() + context.getRequesterId()
-                        + context.getResponderId());
-    }
-
-    @Test public void testSAML2() throws ResolutionException {
-        final Subject subject = new Subject();
-        final SubjectCanonicalizationContext context = new SubjectCanonicalizationContext();
-        NameID nameID = nameIDBuilder.buildObject();
-        nameID.setValue("NID1");
-        subject.getPrincipals().add(new NameIDPrincipal(nameID));
-        context.setSubject(subject);
-        context.setRequesterId("SAML2Requester");
-        context.setResponderId("SAML2Responder");
-
-        Assert.assertEquals(testCanon.doCanonicalize(nameID, context), nameID.getValue() + context.getRequesterId()
-                + context.getResponderId() + NameID.UNSPECIFIED);
-
-        subject.getPrincipals().clear();
-        nameID = nameIDBuilder.buildObject();
-        nameID.setValue("NID2");
-        nameID.setFormat(NameID.UNSPECIFIED);
-        subject.getPrincipals().add(new NameIDPrincipal(nameID));
-        Assert.assertEquals(testCanon.doCanonicalize(nameID, context), nameID.getValue() + context.getRequesterId()
-                + context.getResponderId() + NameID.UNSPECIFIED);
-
-        subject.getPrincipals().clear();
-        nameID = nameIDBuilder.buildObject();
-        nameID.setValue("NID3");
-        nameID.setFormat(NameID.WIN_DOMAIN_QUALIFIED);
-        subject.getPrincipals().add(new NameIDPrincipal(nameID));
-        Assert.assertNull(testCanon.doCanonicalize(nameID, context));
-
-        subject.getPrincipals().clear();
-        nameID = nameIDBuilder.buildObject();
-        nameID.setValue("NID4");
-        nameID.setFormat(NameID.KERBEROS);
-        subject.getPrincipals().add(new NameIDPrincipal(nameID));
-        Assert.assertEquals(testCanon.doCanonicalize(nameID, context), nameID.getValue() + context.getRequesterId()
-                + context.getResponderId() + NameID.KERBEROS);
-    }
-
-    public static class TestCanonicalizer extends PrinicpalConnectorCanonicalizer {
-
-        /**
-         * Constructor.
-         * 
-         * @param connectors
-         */
-        public TestCanonicalizer(final Collection<PrincipalConnector> connectors) {
-            setConnectors(connectors);
-        }
-
-        @Override protected String canonicalize(final NameIdentifier nameIdentifier,
-                final SubjectCanonicalizationContext c14nContext) throws ResolutionException {
-            return "nameIdentifier";
-        }
-
-        /** Make visible for testing . */
-        public String doCanonicalize(final NameIdentifier nameIdentifier, final SubjectCanonicalizationContext c14nContext)
-                throws ResolutionException {
-            return super.canonicalize(nameIdentifier, c14nContext);
-        }
-
-        @Override protected String canonicalize(final NameID nameID, final SubjectCanonicalizationContext c14nContext)
-                throws ResolutionException {
-            return "nameID";
-        }
-
-        /** Make visible for testing . */
-        public String doCanonicalize(final NameID nameID, final SubjectCanonicalizationContext c14nContext)
-                throws ResolutionException {
-            return super.canonicalize(nameID, c14nContext);
-        }
-    }
-
-    public static class MyDecoder implements NameIdentifierDecoder, NameIDDecoder {
-
-        private final String prefix;
-
-        public MyDecoder(final String thePrefix) {
-            prefix = thePrefix;
-        }
-
-        /** {@inheritDoc} */
-        @Override
-        @Nonnull public String decode(@Nonnull final SubjectCanonicalizationContext scc, @Nonnull final NameIdentifier nameIdentifier)
-                throws NameDecoderException {
-            return prefix + nameIdentifier.getValue() + scc.getRequesterId() + scc.getResponderId();
-        }
-
-        /** {@inheritDoc} */
-        @Override @Nonnull public String decode(@Nonnull final SubjectCanonicalizationContext scc, @Nonnull final NameID nameID)
-                throws NameDecoderException {
-            return nameID.getValue() + scc.getRequesterId() + scc.getResponderId() + prefix;
-        }
-
-    }
-    
-}
\ 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