[java-identity-provider] branch master updated: IDP-1494: Login flow for proxied SAML authentication
Brent Putman
putmanb at georgetown.edu
Sun Mar 8 01:18:26 EST 2020
This is an automated email from the git hooks/post-receive script.
putmanb 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=c38d355d174ae8d030dd952c4d621dfe2b51d340
The following commit(s) were added to refs/heads/master by this push:
new c38d355 IDP-1494: Login flow for proxied SAML authentication
c38d355 is described below
commit c38d355d174ae8d030dd952c4d621dfe2b51d340
Author: Brent Putman <putmanb at georgetown.edu>
AuthorDate: Sun Mar 8 01:11:12 2020 -0500
IDP-1494: Login flow for proxied SAML authentication
Unit tests.
---
.../impl/ProcessAssertionsForAuthentication.java | 42 +-
.../ProcessAssertionsForAuthenticationTest.java | 446 +++++++++++++++++++++
2 files changed, 478 insertions(+), 10 deletions(-)
diff --git a/idp-saml-impl/src/main/java/net/shibboleth/idp/saml/saml2/profile/impl/ProcessAssertionsForAuthentication.java b/idp-saml-impl/src/main/java/net/shibboleth/idp/saml/saml2/profile/impl/ProcessAssertionsForAuthentication.java
index 8a05630..4382c02 100644
--- a/idp-saml-impl/src/main/java/net/shibboleth/idp/saml/saml2/profile/impl/ProcessAssertionsForAuthentication.java
+++ b/idp-saml-impl/src/main/java/net/shibboleth/idp/saml/saml2/profile/impl/ProcessAssertionsForAuthentication.java
@@ -46,6 +46,8 @@ import org.slf4j.LoggerFactory;
import net.shibboleth.idp.authn.AbstractAuthenticationAction;
import net.shibboleth.idp.authn.AuthnEventIds;
import net.shibboleth.idp.authn.context.AuthenticationContext;
+import net.shibboleth.utilities.java.support.annotation.constraint.NonnullAfterInit;
+import net.shibboleth.utilities.java.support.component.ComponentInitializationException;
import net.shibboleth.utilities.java.support.component.ComponentSupport;
import net.shibboleth.utilities.java.support.logic.Constraint;
@@ -59,16 +61,16 @@ public class ProcessAssertionsForAuthentication extends AbstractAuthenticationAc
private final Logger log = LoggerFactory.getLogger(ProcessAssertionsForAuthentication.class);
/** The resolver for the response to be processed. */
- @Nonnull private Function<ProfileRequestContext, Response> responseResolver;
+ @NonnullAfterInit private Function<ProfileRequestContext, Response> responseResolver;
/** Lookup strategy to locate the SAML context. */
- @Nonnull private Function<ProfileRequestContext,SAMLAuthnContext> samlContextLookupStrategy;
+ @NonnullAfterInit private Function<ProfileRequestContext,SAMLAuthnContext> samlContextLookupStrategy;
/** Selection strategy for multiple valid authn Assertions. */
- @Nonnull private Function<List<Assertion>,Assertion> authnAssertionSelectionStrategy;
+ @NonnullAfterInit private Function<List<Assertion>,Assertion> authnAssertionSelectionStrategy;
/** Selection strategy for multiple AuthnStatements. */
- @Nonnull private Function<Assertion,AuthnStatement> authnStatementSelectionStrategy;
+ @NonnullAfterInit private Function<Assertion,AuthnStatement> authnStatementSelectionStrategy;
/** The Response to process. */
private Response response;
@@ -119,9 +121,9 @@ public class ProcessAssertionsForAuthentication extends AbstractAuthenticationAc
*/
public void setAuthnAssertionSelectionStrategy(@Nonnull final Function<List<Assertion>, Assertion> strategy) {
ComponentSupport.ifInitializedThrowUnmodifiabledComponentException(this);
+ ComponentSupport.ifDestroyedThrowDestroyedComponentException(this);
- authnAssertionSelectionStrategy = Constraint.isNotNull(strategy,
- "The Assertion selection strategy may not be null");
+ authnAssertionSelectionStrategy = strategy;
}
/**
@@ -131,9 +133,9 @@ public class ProcessAssertionsForAuthentication extends AbstractAuthenticationAc
*/
public void setAuthnStatementSelectionStrategy(@Nonnull final Function<Assertion, AuthnStatement> strategy) {
ComponentSupport.ifInitializedThrowUnmodifiabledComponentException(this);
+ ComponentSupport.ifDestroyedThrowDestroyedComponentException(this);
- authnStatementSelectionStrategy = Constraint.isNotNull(strategy,
- "The AuthnStatement selection strategy may not be null");
+ authnStatementSelectionStrategy = strategy;
}
/**
@@ -143,8 +145,9 @@ public class ProcessAssertionsForAuthentication extends AbstractAuthenticationAc
*/
public void setResponseResolver(@Nonnull final Function<ProfileRequestContext, Response> strategy) {
ComponentSupport.ifInitializedThrowUnmodifiabledComponentException(this);
+ ComponentSupport.ifDestroyedThrowDestroyedComponentException(this);
- responseResolver = Constraint.isNotNull(strategy, "The Response resolver strategy may not be null");
+ responseResolver = strategy;
}
/**
@@ -155,8 +158,27 @@ public class ProcessAssertionsForAuthentication extends AbstractAuthenticationAc
public void setSAMLAuthnContextLookupStrategy(
@Nonnull final Function<ProfileRequestContext,SAMLAuthnContext> strategy) {
ComponentSupport.ifInitializedThrowUnmodifiabledComponentException(this);
+ ComponentSupport.ifDestroyedThrowDestroyedComponentException(this);
- samlContextLookupStrategy = Constraint.isNotNull(strategy, "SAMLAuthnContext lookup strategy may not be null");
+ samlContextLookupStrategy = strategy;
+ }
+
+ /** {@inheritDoc} */
+ protected void doInitialize() throws ComponentInitializationException {
+ super.doInitialize();
+
+ if (authnAssertionSelectionStrategy == null) {
+ throw new ComponentInitializationException("Authentication Assertion selection strategy cannot be null");
+ }
+ if (authnStatementSelectionStrategy == null) {
+ throw new ComponentInitializationException("AuthnStatement selection strategy cannot be null");
+ }
+ if (responseResolver == null) {
+ throw new ComponentInitializationException("Response resolver cannot be null");
+ }
+ if (samlContextLookupStrategy == null) {
+ throw new ComponentInitializationException("SAMLAuthnContext lookup strategy cannot be null");
+ }
}
/** {@inheritDoc} */
diff --git a/idp-saml-impl/src/test/java/net/shibboleth/idp/saml/saml2/profile/impl/ProcessAssertionsForAuthenticationTest.java b/idp-saml-impl/src/test/java/net/shibboleth/idp/saml/saml2/profile/impl/ProcessAssertionsForAuthenticationTest.java
new file mode 100644
index 0000000..8a052b5
--- /dev/null
+++ b/idp-saml-impl/src/test/java/net/shibboleth/idp/saml/saml2/profile/impl/ProcessAssertionsForAuthenticationTest.java
@@ -0,0 +1,446 @@
+/*
+ * 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.saml2.profile.impl;
+
+import java.time.Duration;
+import java.time.Instant;
+import java.util.function.Function;
+
+import org.opensaml.core.OpenSAMLInitBaseTestCase;
+import org.opensaml.core.xml.util.XMLObjectSupport;
+import org.opensaml.messaging.decoder.MessageDecoder;
+import org.opensaml.profile.RequestContextBuilder;
+import org.opensaml.profile.action.ActionTestingSupport;
+import org.opensaml.profile.action.ProfileAction;
+import org.opensaml.profile.context.ProfileRequestContext;
+import org.opensaml.saml.common.assertion.ValidationContext;
+import org.opensaml.saml.common.assertion.ValidationProcessingData;
+import org.opensaml.saml.common.assertion.ValidationResult;
+import org.opensaml.saml.saml2.assertion.SAML2AssertionValidationParameters;
+import org.opensaml.saml.saml2.core.Assertion;
+import org.opensaml.saml.saml2.core.Response;
+import org.opensaml.saml.saml2.core.Subject;
+import org.opensaml.saml.saml2.core.SubjectConfirmation;
+import org.opensaml.saml.saml2.profile.SAML2ActionTestingSupport;
+import org.springframework.mock.web.MockHttpServletRequest;
+import org.springframework.mock.web.MockHttpServletResponse;
+import org.testng.Assert;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+
+import com.google.common.base.Predicates;
+import com.google.common.collect.Lists;
+
+import net.shibboleth.idp.authn.AuthnEventIds;
+import net.shibboleth.idp.authn.context.AuthenticationContext;
+import net.shibboleth.utilities.java.support.component.ComponentInitializationException;
+
+public class ProcessAssertionsForAuthenticationTest extends OpenSAMLInitBaseTestCase {
+
+ private ProcessAssertionsForAuthentication action;
+
+ private ProfileRequestContext prc, prcInner;
+
+ private SAMLAuthnContext samlAuthnContext;
+
+ private Response samlResponse;
+
+ private MockHttpServletRequest httpRequest;
+ private MockHttpServletResponse httpResponse;
+
+ @BeforeMethod
+ public void beforeMethod() {
+ httpRequest = new MockHttpServletRequest();
+ httpResponse = new MockHttpServletResponse();
+
+ action = new ProcessAssertionsForAuthentication();
+ action.setHttpServletRequest(httpRequest);
+ action.setHttpServletResponse(httpResponse);
+
+
+ samlResponse = SAML2ActionTestingSupport.buildResponse();
+
+ prcInner = new RequestContextBuilder().setInboundMessage(samlResponse).buildProfileRequestContext();
+
+ prc = new RequestContextBuilder().buildProfileRequestContext();
+
+ AuthenticationContext authnContext = prc.getSubcontext(AuthenticationContext.class, true);
+ samlAuthnContext = new SAMLAuthnContext(new MockProfileAction(), new MockMessageDecoderFunction());
+ authnContext.addSubcontext(samlAuthnContext);
+ authnContext.addSubcontext(prcInner);
+ }
+
+ @Test
+ public void testValid() throws ComponentInitializationException {
+ Assertion assertion1 = buildAssertion(ValidationResult.VALID);
+ samlResponse.getAssertions().add(assertion1);
+
+ action.initialize();
+
+ action.execute(prc);
+ ActionTestingSupport.assertProceedEvent(prc);
+ Assert.assertSame(samlAuthnContext.getSubject(), assertion1.getSubject());
+ Assert.assertSame(samlAuthnContext.getAuthnStatement(), assertion1.getAuthnStatements().get(0));
+ Assert.assertEquals(samlResponse.getAssertions(), Lists.newArrayList(assertion1));
+ }
+
+ @Test
+ public void testInvalid() throws ComponentInitializationException {
+ Assertion assertion1 = buildAssertion(ValidationResult.INVALID);
+ samlResponse.getAssertions().add(assertion1);
+
+ action.initialize();
+
+ action.execute(prc);
+ ActionTestingSupport.assertEvent(prc, AuthnEventIds.INVALID_CREDENTIALS);
+ Assert.assertNull(samlAuthnContext.getSubject());
+ Assert.assertNull(samlAuthnContext.getAuthnStatement());
+ Assert.assertEquals(samlResponse.getAssertions(), Lists.newArrayList());
+ }
+
+ @Test
+ public void testIndeterminate() throws ComponentInitializationException {
+ Assertion assertion1 = buildAssertion(ValidationResult.INDETERMINATE);
+ samlResponse.getAssertions().add(assertion1);
+
+ action.initialize();
+
+ action.execute(prc);
+ ActionTestingSupport.assertEvent(prc, AuthnEventIds.INVALID_CREDENTIALS);
+ Assert.assertNull(samlAuthnContext.getSubject());
+ Assert.assertNull(samlAuthnContext.getAuthnStatement());
+ Assert.assertEquals(samlResponse.getAssertions(), Lists.newArrayList());
+ }
+
+ @Test
+ public void testMultipleValidNoSessionInstant() throws ComponentInitializationException {
+ Assertion assertion1 = buildAssertion(ValidationResult.VALID);
+ samlResponse.getAssertions().add(assertion1);
+ Assertion assertion2 = buildAssertion(ValidationResult.VALID);
+ samlResponse.getAssertions().add(assertion2);
+
+ action.initialize();
+
+ action.execute(prc);
+ ActionTestingSupport.assertProceedEvent(prc);
+ Assert.assertSame(samlAuthnContext.getSubject(), assertion1.getSubject());
+ Assert.assertSame(samlAuthnContext.getAuthnStatement(), assertion1.getAuthnStatements().get(0));
+ Assert.assertEquals(samlResponse.getAssertions(), Lists.newArrayList(assertion1, assertion2));
+ }
+
+ @Test
+ public void testMultipleValidMixedSessionInstant() throws ComponentInitializationException {
+ // Assertion1 doesn't have session instant, so pick assertion 2
+ Assertion assertion1 = buildAssertion(ValidationResult.VALID);
+ samlResponse.getAssertions().add(assertion1);
+ Assertion assertion2 = buildAssertion(ValidationResult.VALID);
+ assertion2.getAuthnStatements().get(0).setSessionNotOnOrAfter(Instant.now().plus(Duration.ofHours(2)));
+ samlResponse.getAssertions().add(assertion2);
+
+ action.initialize();
+
+ action.execute(prc);
+ ActionTestingSupport.assertProceedEvent(prc);
+ Assert.assertSame(samlAuthnContext.getSubject(), assertion2.getSubject());
+ Assert.assertSame(samlAuthnContext.getAuthnStatement(), assertion2.getAuthnStatements().get(0));
+ Assert.assertEquals(samlResponse.getAssertions(), Lists.newArrayList(assertion1, assertion2));
+ }
+
+ @Test
+ public void testMixedValidity() throws ComponentInitializationException {
+ Assertion assertion1 = buildAssertion(ValidationResult.INVALID);
+ samlResponse.getAssertions().add(assertion1);
+ Assertion assertion2 = buildAssertion(ValidationResult.VALID);
+ samlResponse.getAssertions().add(assertion2);
+ Assertion assertion3 = buildAssertion(ValidationResult.INDETERMINATE);
+ samlResponse.getAssertions().add(assertion3);
+ Assertion assertion4 = buildAssertion(ValidationResult.VALID);
+ samlResponse.getAssertions().add(assertion4);
+
+ action.initialize();
+
+ action.execute(prc);
+ ActionTestingSupport.assertProceedEvent(prc);
+ Assert.assertSame(samlAuthnContext.getSubject(), assertion2.getSubject());
+ Assert.assertSame(samlAuthnContext.getAuthnStatement(), assertion2.getAuthnStatements().get(0));
+ Assert.assertEquals(samlResponse.getAssertions(), Lists.newArrayList(assertion2, assertion4));
+ }
+
+ @Test
+ public void testMultipleValidBothSessionInstant() throws ComponentInitializationException {
+ // Assertion1 has earlier session instant, so pick assertion 1
+ Assertion assertion1 = buildAssertion(ValidationResult.VALID);
+ assertion1.getAuthnStatements().get(0).setSessionNotOnOrAfter(Instant.now().plus(Duration.ofHours(1)));
+ samlResponse.getAssertions().add(assertion1);
+ Assertion assertion2 = buildAssertion(ValidationResult.VALID);
+ assertion2.getAuthnStatements().get(0).setSessionNotOnOrAfter(Instant.now().plus(Duration.ofHours(2)));
+ samlResponse.getAssertions().add(assertion2);
+
+ action.initialize();
+
+ action.execute(prc);
+ ActionTestingSupport.assertProceedEvent(prc);
+ Assert.assertSame(samlAuthnContext.getSubject(), assertion1.getSubject());
+ Assert.assertSame(samlAuthnContext.getAuthnStatement(), assertion1.getAuthnStatements().get(0));
+ Assert.assertEquals(samlResponse.getAssertions(), Lists.newArrayList(assertion1, assertion2));
+ }
+
+ @Test
+ public void testMultipleAuthnStatementsNoSessionInstant() throws ComponentInitializationException {
+ Assertion assertion1 = buildAssertion(ValidationResult.VALID);
+ assertion1.getAuthnStatements().add(SAML2ActionTestingSupport.buildAuthnStatement());
+ samlResponse.getAssertions().add(assertion1);
+
+ action.initialize();
+
+ action.execute(prc);
+ ActionTestingSupport.assertProceedEvent(prc);
+ Assert.assertSame(samlAuthnContext.getSubject(), assertion1.getSubject());
+ Assert.assertSame(samlAuthnContext.getAuthnStatement(), assertion1.getAuthnStatements().get(0));
+ Assert.assertEquals(samlResponse.getAssertions(), Lists.newArrayList(assertion1));
+ }
+
+ @Test
+ public void testMultipleAuthnStatementsMixedSessionInstant() throws ComponentInitializationException {
+ Assertion assertion1 = buildAssertion(ValidationResult.VALID);
+ assertion1.getAuthnStatements().add(SAML2ActionTestingSupport.buildAuthnStatement());
+ assertion1.getAuthnStatements().get(1).setSessionNotOnOrAfter(Instant.now().plus(Duration.ofHours(2)));
+ samlResponse.getAssertions().add(assertion1);
+
+ action.initialize();
+
+ action.execute(prc);
+ ActionTestingSupport.assertProceedEvent(prc);
+ Assert.assertSame(samlAuthnContext.getSubject(), assertion1.getSubject());
+ Assert.assertSame(samlAuthnContext.getAuthnStatement(), assertion1.getAuthnStatements().get(1));
+ Assert.assertEquals(samlResponse.getAssertions(), Lists.newArrayList(assertion1));
+ }
+
+ @Test
+ public void testMultipleAuthnStatementsBothSessionInstant() throws ComponentInitializationException {
+ Assertion assertion1 = buildAssertion(ValidationResult.VALID);
+ assertion1.getAuthnStatements().get(0).setSessionNotOnOrAfter(Instant.now().plus(Duration.ofHours(1)));
+ assertion1.getAuthnStatements().add(SAML2ActionTestingSupport.buildAuthnStatement());
+ assertion1.getAuthnStatements().get(1).setSessionNotOnOrAfter(Instant.now().plus(Duration.ofHours(2)));
+ samlResponse.getAssertions().add(assertion1);
+
+ action.initialize();
+
+ action.execute(prc);
+ ActionTestingSupport.assertProceedEvent(prc);
+ Assert.assertSame(samlAuthnContext.getSubject(), assertion1.getSubject());
+ Assert.assertSame(samlAuthnContext.getAuthnStatement(), assertion1.getAuthnStatements().get(0));
+ Assert.assertEquals(samlResponse.getAssertions(), Lists.newArrayList(assertion1));
+ }
+
+ @Test
+ public void testNoResponse() throws ComponentInitializationException {
+ prcInner.getInboundMessageContext().setMessage(null);
+
+ action.initialize();
+
+ action.execute(prc);
+ ActionTestingSupport.assertEvent(prc, AuthnEventIds.INVALID_CREDENTIALS);
+ Assert.assertNull(samlAuthnContext.getSubject());
+ Assert.assertNull(samlAuthnContext.getAuthnStatement());
+ Assert.assertEquals(samlResponse.getAssertions(), Lists.newArrayList());
+ }
+
+ @Test
+ public void testNoAssertions() throws ComponentInitializationException {
+ action.initialize();
+
+ action.execute(prc);
+ ActionTestingSupport.assertEvent(prc, AuthnEventIds.INVALID_CREDENTIALS);
+ Assert.assertNull(samlAuthnContext.getSubject());
+ Assert.assertNull(samlAuthnContext.getAuthnStatement());
+ Assert.assertEquals(samlResponse.getAssertions(), Lists.newArrayList());
+ }
+
+ @Test
+ public void testNoSAMLAuthnContext() throws ComponentInitializationException {
+ Assertion assertion1 = buildAssertion(ValidationResult.VALID);
+ samlResponse.getAssertions().add(assertion1);
+
+ prc.getSubcontext(AuthenticationContext.class).removeSubcontext(SAMLAuthnContext.class);
+
+ action.initialize();
+
+ action.execute(prc);
+ ActionTestingSupport.assertEvent(prc, AuthnEventIds.INVALID_CREDENTIALS);
+ Assert.assertNull(samlAuthnContext.getSubject());
+ Assert.assertNull(samlAuthnContext.getAuthnStatement());
+ Assert.assertEquals(samlResponse.getAssertions(), Lists.newArrayList(assertion1));
+ }
+
+ @Test
+ public void testAssertionNotValidated() throws ComponentInitializationException {
+ Assertion assertion1 = buildAssertion(null);
+ samlResponse.getAssertions().add(assertion1);
+
+ action.initialize();
+
+ action.execute(prc);
+ ActionTestingSupport.assertEvent(prc, AuthnEventIds.INVALID_CREDENTIALS);
+ Assert.assertNull(samlAuthnContext.getSubject());
+ Assert.assertNull(samlAuthnContext.getAuthnStatement());
+ Assert.assertEquals(samlResponse.getAssertions(), Lists.newArrayList());
+ }
+
+ @Test
+ public void testNoAuthnStatement() throws ComponentInitializationException {
+ Assertion assertion1 = buildAssertion(ValidationResult.VALID);
+ assertion1.getAuthnStatements().clear();
+ samlResponse.getAssertions().add(assertion1);
+
+ action.initialize();
+
+ action.execute(prc);
+ ActionTestingSupport.assertEvent(prc, AuthnEventIds.INVALID_CREDENTIALS);
+ Assert.assertNull(samlAuthnContext.getSubject());
+ Assert.assertNull(samlAuthnContext.getAuthnStatement());
+ Assert.assertEquals(samlResponse.getAssertions(), Lists.newArrayList(assertion1));
+ }
+
+ @Test
+ public void testNoConfirmedSubject() throws ComponentInitializationException {
+ Assertion assertion1 = buildAssertion(ValidationResult.VALID);
+ assertion1.getObjectMetadata().get(ValidationProcessingData.class).get(0)
+ .getContext().getDynamicParameters().remove(SAML2AssertionValidationParameters.CONFIRMED_SUBJECT_CONFIRMATION);
+ samlResponse.getAssertions().add(assertion1);
+
+ action.initialize();
+
+ action.execute(prc);
+ ActionTestingSupport.assertEvent(prc, AuthnEventIds.INVALID_CREDENTIALS);
+ Assert.assertNull(samlAuthnContext.getSubject());
+ Assert.assertNull(samlAuthnContext.getAuthnStatement());
+ Assert.assertEquals(samlResponse.getAssertions(), Lists.newArrayList(assertion1));
+ }
+
+ @Test
+ public void testActionInactive() throws ComponentInitializationException {
+ Assertion assertion1 = buildAssertion(ValidationResult.VALID);
+ samlResponse.getAssertions().add(assertion1);
+
+ action.setActivationCondition(Predicates.alwaysFalse());
+
+ action.initialize();
+
+ action.execute(prc);
+ ActionTestingSupport.assertProceedEvent(prc);
+ Assert.assertNull(samlAuthnContext.getSubject());
+ Assert.assertNull(samlAuthnContext.getAuthnStatement());
+ Assert.assertEquals(samlResponse.getAssertions(), Lists.newArrayList(assertion1));
+ }
+
+ @Test(expectedExceptions = ComponentInitializationException.class)
+ public void testNullAuthnAssertionStrategy() throws ComponentInitializationException {
+ Assertion assertion1 = buildAssertion(ValidationResult.VALID);
+ samlResponse.getAssertions().add(assertion1);
+
+ action.setAuthnAssertionSelectionStrategy(null);
+
+ action.initialize();
+ }
+
+ @Test(expectedExceptions = ComponentInitializationException.class)
+ public void testNullAuthnStatementStrategy() throws ComponentInitializationException {
+ Assertion assertion1 = buildAssertion(ValidationResult.VALID);
+ samlResponse.getAssertions().add(assertion1);
+
+ action.setAuthnStatementSelectionStrategy(null);
+
+ action.initialize();
+ }
+
+ @Test(expectedExceptions = ComponentInitializationException.class)
+ public void testNullResponseResolver() throws ComponentInitializationException {
+ Assertion assertion1 = buildAssertion(ValidationResult.VALID);
+ samlResponse.getAssertions().add(assertion1);
+
+ action.setResponseResolver(null);
+
+ action.initialize();
+ }
+
+ @Test(expectedExceptions = ComponentInitializationException.class)
+ public void testNullSAMLAuthnContextStrategy() throws ComponentInitializationException {
+ Assertion assertion1 = buildAssertion(ValidationResult.VALID);
+ samlResponse.getAssertions().add(assertion1);
+
+ action.setSAMLAuthnContextLookupStrategy(null);
+
+ action.initialize();
+ }
+
+
+ // Helpers
+
+ private Assertion buildAssertion(ValidationResult validationResult) {
+ SubjectConfirmation sc = (SubjectConfirmation) XMLObjectSupport.buildXMLObject(SubjectConfirmation.DEFAULT_ELEMENT_NAME);
+ Subject subject = SAML2ActionTestingSupport.buildSubject("testUser");
+ subject.getSubjectConfirmations().add(sc);
+
+ Assertion assertion = SAML2ActionTestingSupport.buildAssertion();
+ assertion.setSubject(subject);
+ assertion.getAuthnStatements().add(SAML2ActionTestingSupport.buildAuthnStatement());
+
+ if (validationResult != null) {
+ assertion.getObjectMetadata().put(new ValidationProcessingData(buildValidationContext(sc), validationResult));
+ }
+
+
+ return assertion;
+ }
+
+ private ValidationContext buildValidationContext(SubjectConfirmation sc) {
+ ValidationContext vc = new ValidationContext();
+ vc.getDynamicParameters().put(SAML2AssertionValidationParameters.CONFIRMED_SUBJECT_CONFIRMATION, sc);
+ return vc;
+ }
+
+ private static class MockProfileAction implements ProfileAction {
+
+ /** {@inheritDoc} */
+ public boolean isInitialized() {
+ return true;
+ }
+
+ /** {@inheritDoc} */
+ public void initialize() throws ComponentInitializationException {
+
+ }
+
+ /** {@inheritDoc} */
+ public void execute(ProfileRequestContext profileRequestContext) {
+
+ }
+
+ }
+
+ private static class MockMessageDecoderFunction implements Function<String, MessageDecoder> {
+
+ /** {@inheritDoc} */
+ public MessageDecoder apply(String t) {
+ return null;
+ }
+
+ }
+
+}
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the commits
mailing list