[java-opensaml] 03/04: Rework how some lookup code works.
Brent Putman
putmanb at georgetown.edu
Sat Feb 1 00:32:11 EST 2020
This is an automated email from the git hooks/post-receive script.
putmanb pushed a commit to branch master
in repository java-opensaml.
View the commit online:
http://git.shibboleth.net/view/?p=java-opensaml.git;a=commit;h=bf7eed849bda37a425f8163fb2e3f3fc20b8c9be
commit bf7eed849bda37a425f8163fb2e3f3fc20b8c9be
Author: Brent Putman <putmanb at georgetown.edu>
AuthorDate: Fri Jan 31 22:19:27 2020 -0500
Rework how some lookup code works.
Make better use of existing lookup functions and use composition.
---
.../context/navigate/MessageContextLookup.java | 104 +++++++++++++++
.../context/navigate/MessageContextLookupTest.java | 94 ++++++++++++++
.../messaging/context/SAMLMessageInfoContext.java | 1 +
.../context/navigate/SAMLEntityIDFunction.java | 39 ++++++
.../impl/MessageContextEntityIDLookup.java | 139 ---------------------
.../DefaultAssertionValidationContextBuilder.java | 48 ++++---
.../impl/MessageContextEntityIDLookupTest.java | 91 --------------
7 files changed, 268 insertions(+), 248 deletions(-)
diff --git a/opensaml-messaging-api/src/main/java/org/opensaml/messaging/context/navigate/MessageContextLookup.java b/opensaml-messaging-api/src/main/java/org/opensaml/messaging/context/navigate/MessageContextLookup.java
new file mode 100644
index 0000000..7cbde39
--- /dev/null
+++ b/opensaml-messaging-api/src/main/java/org/opensaml/messaging/context/navigate/MessageContextLookup.java
@@ -0,0 +1,104 @@
+/*
+ * 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 org.opensaml.messaging.context.navigate;
+
+import java.util.function.Function;
+
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
+
+import org.opensaml.messaging.context.BaseContext;
+import org.opensaml.messaging.context.InOutOperationContext;
+import org.opensaml.messaging.context.MessageContext;
+
+import net.shibboleth.utilities.java.support.annotation.ParameterName;
+import net.shibboleth.utilities.java.support.logic.Constraint;
+
+/**
+ * A lookup function for resolving either the inbound or outbound {@link MessageContext} relative to
+ * a particular {@link BaseContext}.
+ *
+ * <p>
+ * This would usually be used in composing other lookup functions.
+ * </p>
+ *
+ * @param <StartContext> the starting context type
+ */
+public class MessageContextLookup<StartContext extends BaseContext>
+ implements ContextDataLookupFunction<StartContext, MessageContext> {
+
+ /** Used to indicate the target message context. */
+ public enum Direction {
+ /** Indicates to use the inbound message context, obtained via
+ * {@link InOutOperationContext#getInboundMessageContext()}. */
+ INBOUND,
+
+ /** Indicates to use the outbound message context, obtained via
+ * {@link InOutOperationContext#getOutboundMessageContext()}. */
+ OUTBOUND,
+ };
+
+ /** The message context to evaluate as the entityContext parent. */
+ @Nonnull private Direction dir;
+
+ /** The operation context lookup. Defaults to {@link RecursiveTypedParentContextLookup}. */
+ @Nonnull private Function<BaseContext, InOutOperationContext> opContextLookup;
+
+ /**
+ * Constructor.
+ *
+ * @param direction the direction in which to operate.
+ */
+ public MessageContextLookup(@Nonnull @ParameterName(name="direction") final Direction direction) {
+ this(direction, new RecursiveTypedParentContextLookup<>(InOutOperationContext.class));
+ }
+
+ /**
+ * Constructor.
+ *
+ * @param direction the direction in which to operate.
+ * @param lookup the operation context lookup
+ */
+ public MessageContextLookup(@Nonnull @ParameterName(name="direction") final Direction direction,
+ @Nonnull @ParameterName(name="lookup") final Function<BaseContext, InOutOperationContext> lookup) {
+ dir = Constraint.isNotNull(direction, "Direction was null");
+ opContextLookup = Constraint.isNotNull(lookup, "InOutOperationContext lookup was null");
+ }
+
+ /** {@inheritDoc} */
+ public MessageContext apply(@Nullable final BaseContext baseContext) {
+ if (baseContext == null) {
+ return null;
+ }
+
+ final InOutOperationContext opContext = opContextLookup.apply(baseContext);
+ if (opContext == null) {
+ return null;
+ }
+
+ switch(dir) {
+ case INBOUND:
+ return opContext.getInboundMessageContext();
+ case OUTBOUND:
+ return opContext.getOutboundMessageContext();
+ default:
+ throw new IllegalArgumentException("Saw unsupported value: " + dir);
+ }
+ }
+
+}
diff --git a/opensaml-messaging-api/src/test/java/org/opensaml/messaging/context/navigate/MessageContextLookupTest.java b/opensaml-messaging-api/src/test/java/org/opensaml/messaging/context/navigate/MessageContextLookupTest.java
new file mode 100644
index 0000000..44957da
--- /dev/null
+++ b/opensaml-messaging-api/src/test/java/org/opensaml/messaging/context/navigate/MessageContextLookupTest.java
@@ -0,0 +1,94 @@
+/*
+ * 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 org.opensaml.messaging.context.navigate;
+
+import org.opensaml.messaging.context.BaseContext;
+import org.opensaml.messaging.context.InOutOperationContext;
+import org.opensaml.messaging.context.MessageContext;
+import org.opensaml.messaging.context.navigate.MessageContextLookup.Direction;
+import org.testng.Assert;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+
+import net.shibboleth.utilities.java.support.logic.ConstraintViolationException;
+
+public class MessageContextLookupTest {
+
+ private InOutOperationContext opContext;
+
+ @BeforeMethod
+ public void setUp() {
+ opContext = new InOutOperationContext(new MessageContext(), new MessageContext());
+ }
+
+ @Test
+ public void testInboundFromSame() {
+ MockContext input = new MockContext();
+ opContext.getInboundMessageContext().addSubcontext(input);
+ MessageContextLookup<BaseContext> lookup = new MessageContextLookup<>(Direction.INBOUND);
+ Assert.assertSame(lookup.apply(input), opContext.getInboundMessageContext());
+ }
+
+ @Test
+ public void testOutboundFromSame() {
+ MockContext input = new MockContext();
+ opContext.getOutboundMessageContext().addSubcontext(input);
+ MessageContextLookup<BaseContext> lookup = new MessageContextLookup<>(Direction.OUTBOUND);
+ Assert.assertSame(lookup.apply(input), opContext.getOutboundMessageContext());
+ }
+
+ @Test
+ public void testInboundFromCrosswalk() {
+ MockContext input = new MockContext();
+ opContext.getOutboundMessageContext().addSubcontext(input);
+ MessageContextLookup<BaseContext> lookup = new MessageContextLookup<>(Direction.INBOUND);
+ Assert.assertSame(lookup.apply(input), opContext.getInboundMessageContext());
+ }
+
+ @Test
+ public void testOutboundFromCrosswalk() {
+ MockContext input = new MockContext();
+ opContext.getInboundMessageContext().addSubcontext(input);
+ MessageContextLookup<BaseContext> lookup = new MessageContextLookup<>(Direction.OUTBOUND);
+ Assert.assertSame(lookup.apply(input), opContext.getOutboundMessageContext());
+ }
+
+ @Test
+ public void testNoParentOpContext() {
+ MessageContextLookup<BaseContext> lookup = new MessageContextLookup<>(Direction.INBOUND);
+ Assert.assertNull(lookup.apply(new MessageContext()));
+ }
+
+ @Test(expectedExceptions=ConstraintViolationException.class)
+ public void testCtorNoDirection() {
+ new MessageContextLookup<>(null);
+ }
+
+ @Test(expectedExceptions=ConstraintViolationException.class)
+ public void testCtorNoLookup() {
+ new MessageContextLookup<>(Direction.INBOUND, null);
+ }
+
+
+ // Helpers
+
+ private static class MockContext extends BaseContext {
+
+ }
+
+}
diff --git a/opensaml-saml-api/src/main/java/org/opensaml/saml/common/messaging/context/SAMLMessageInfoContext.java b/opensaml-saml-api/src/main/java/org/opensaml/saml/common/messaging/context/SAMLMessageInfoContext.java
index 51a684f..ef1ab4b 100644
--- a/opensaml-saml-api/src/main/java/org/opensaml/saml/common/messaging/context/SAMLMessageInfoContext.java
+++ b/opensaml-saml-api/src/main/java/org/opensaml/saml/common/messaging/context/SAMLMessageInfoContext.java
@@ -99,6 +99,7 @@ public final class SAMLMessageInfoContext extends BaseContext {
*/
@Nullable protected String resolveMessageId() {
final SAMLObject samlMessage = resolveSAMLMessage();
+ //SAML 2 Request
if (samlMessage instanceof org.opensaml.saml.saml2.core.RequestAbstractType) {
final org.opensaml.saml.saml2.core.RequestAbstractType request =
(org.opensaml.saml.saml2.core.RequestAbstractType) samlMessage;
diff --git a/opensaml-saml-api/src/main/java/org/opensaml/saml/common/messaging/context/navigate/SAMLEntityIDFunction.java b/opensaml-saml-api/src/main/java/org/opensaml/saml/common/messaging/context/navigate/SAMLEntityIDFunction.java
new file mode 100644
index 0000000..9094df3
--- /dev/null
+++ b/opensaml-saml-api/src/main/java/org/opensaml/saml/common/messaging/context/navigate/SAMLEntityIDFunction.java
@@ -0,0 +1,39 @@
+/*
+ * 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 org.opensaml.saml.common.messaging.context.navigate;
+
+import javax.annotation.Nullable;
+
+import org.opensaml.messaging.context.navigate.ContextDataLookupFunction;
+import org.opensaml.saml.common.messaging.context.AbstractSAMLEntityContext;
+
+/**
+ * A {@link ContextDataLookupFunction} that returns {@link AbstractSAMLEntityContext#getEntityId()}.
+ */
+public class SAMLEntityIDFunction implements ContextDataLookupFunction<AbstractSAMLEntityContext, String> {
+
+ /** {@inheritDoc} */
+ public String apply(@Nullable final AbstractSAMLEntityContext samlEntityContext ) {
+ if (samlEntityContext == null) {
+ return null;
+ }
+
+ return samlEntityContext.getEntityId();
+ }
+
+}
diff --git a/opensaml-saml-impl/src/main/java/org/opensaml/saml/common/binding/security/impl/MessageContextEntityIDLookup.java b/opensaml-saml-impl/src/main/java/org/opensaml/saml/common/binding/security/impl/MessageContextEntityIDLookup.java
deleted file mode 100644
index 91d7516..0000000
--- a/opensaml-saml-impl/src/main/java/org/opensaml/saml/common/binding/security/impl/MessageContextEntityIDLookup.java
+++ /dev/null
@@ -1,139 +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 org.opensaml.saml.common.binding.security.impl;
-
-import java.util.function.Function;
-
-import javax.annotation.Nonnull;
-import javax.annotation.Nullable;
-
-import org.opensaml.messaging.context.InOutOperationContext;
-import org.opensaml.messaging.context.MessageContext;
-import org.opensaml.messaging.context.navigate.ContextDataLookupFunction;
-import org.opensaml.messaging.context.navigate.RecursiveTypedParentContextLookup;
-import org.opensaml.saml.common.messaging.context.AbstractSAMLEntityContext;
-import org.opensaml.saml.common.messaging.context.SAMLPeerEntityContext;
-
-import net.shibboleth.utilities.java.support.logic.Constraint;
-
-/**
- * A general purpose context data lookup function for resolving a SAML entity ID relative to a
- * starting input {@link MessageContext}, configurable for either the inbound or outbound direction,
- * and also to specify the concrete type of {@link AbstractSAMLEntityContext} child context to resolve.
- */
-public class MessageContextEntityIDLookup implements ContextDataLookupFunction<MessageContext, String> {
-
- /** Used to indicate the target message context. */
- public enum Direction {
- /** Indicates to use the inbound message context, obtained via
- * {@link InOutOperationContext#getInboundMessageContext()}. */
- INBOUND,
-
- /** Indicates to use the outbound message context, obtained via
- * {@link InOutOperationContext#getOutboundMessageContext()}. */
- OUTBOUND,
- };
-
- /** The message context to evaluate as the entityContext parent. */
- @Nonnull private Direction direction;
-
- /** The actual context class holding the authenticatable SAML entity. */
- @Nonnull private Class<? extends AbstractSAMLEntityContext> entityContextClass;
-
- /** Parent operation context lookup function. */
- @Nonnull private Function<MessageContext,MessageContext> parentLookup;
-
- /**
- * Constructor.
- *
- * <p>
- * This constructor defaults to {@link SAMLPeerEntityContext} as the entity context class.
- * </p>
- */
- public MessageContextEntityIDLookup() {
- this(SAMLPeerEntityContext.class);
- }
-
- /**
- * Constructor.
- *
- * @param clazz the entity context class.
- */
- public MessageContextEntityIDLookup(
- @Nonnull final Class<? extends AbstractSAMLEntityContext> clazz) {
- entityContextClass = Constraint.isNotNull(clazz, "The SAML Entity context class may not be null;");
- parentLookup = new MessageContextLookup()
- .compose(new RecursiveTypedParentContextLookup<>(InOutOperationContext.class));
- }
-
- /**
- * Set the direction of operation.
- *
- * @param dir the direction of operation
- */
- public void setDirection(@Nonnull final Direction dir) {
- direction = Constraint.isNotNull(dir, "Direction was null");
- }
-
- /** {@inheritDoc} */
- public String apply(@Nullable final MessageContext messageContext) {
- if (messageContext == null) {
- return null;
- }
-
- final MessageContext msgContext = parentLookup.apply(messageContext);
- if (msgContext == null) {
- return null;
- }
-
- final AbstractSAMLEntityContext entityContext = msgContext.getSubcontext(entityContextClass);
- if (entityContext == null) {
- return null;
- }
-
- return entityContext.getEntityId();
- }
-
- /**
- * Class for picking either the inbound or outbound message context, depending on configuration.
- */
- private class MessageContextLookup implements ContextDataLookupFunction<InOutOperationContext, MessageContext> {
-
- /** {@inheritDoc} */
- public MessageContext apply(@Nullable final InOutOperationContext opContext) {
- if (opContext == null) {
- return null;
- }
-
- if (direction == null) {
- throw new IllegalArgumentException("Direction must be supplied");
- }
-
- switch(direction) {
- case INBOUND:
- return opContext.getInboundMessageContext();
- case OUTBOUND:
- return opContext.getOutboundMessageContext();
- default:
- throw new IllegalArgumentException("Saw unsupported value: " + direction);
- }
- }
-
- }
-
-}
diff --git a/opensaml-saml-impl/src/main/java/org/opensaml/saml/saml2/profile/impl/DefaultAssertionValidationContextBuilder.java b/opensaml-saml-impl/src/main/java/org/opensaml/saml/saml2/profile/impl/DefaultAssertionValidationContextBuilder.java
index 37b06fe..d1a1366 100644
--- a/opensaml-saml-impl/src/main/java/org/opensaml/saml/saml2/profile/impl/DefaultAssertionValidationContextBuilder.java
+++ b/opensaml-saml-impl/src/main/java/org/opensaml/saml/saml2/profile/impl/DefaultAssertionValidationContextBuilder.java
@@ -36,32 +36,28 @@ import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import javax.xml.namespace.QName;
-import net.shibboleth.utilities.java.support.collection.LazySet;
-import net.shibboleth.utilities.java.support.collection.Pair;
-import net.shibboleth.utilities.java.support.logic.Constraint;
-import net.shibboleth.utilities.java.support.primitive.StringSupport;
-import net.shibboleth.utilities.java.support.resolver.CriteriaSet;
-
import org.opensaml.core.criterion.EntityIdCriterion;
import org.opensaml.messaging.MessageException;
import org.opensaml.messaging.context.MessageContext;
import org.opensaml.messaging.context.navigate.ChildContextLookup;
+import org.opensaml.messaging.context.navigate.MessageContextLookup;
+import org.opensaml.messaging.context.navigate.MessageContextLookup.Direction;
import org.opensaml.profile.context.ProfileRequestContext;
import org.opensaml.profile.context.navigate.InboundMessageContextLookup;
import org.opensaml.saml.common.assertion.ValidationContext;
import org.opensaml.saml.common.binding.SAMLBindingSupport;
-import org.opensaml.saml.common.binding.security.impl.MessageContextEntityIDLookup;
-import org.opensaml.saml.common.binding.security.impl.MessageContextEntityIDLookup.Direction;
+import org.opensaml.saml.common.messaging.context.SAMLMessageInfoContext;
import org.opensaml.saml.common.messaging.context.SAMLMetadataContext;
import org.opensaml.saml.common.messaging.context.SAMLPeerEntityContext;
import org.opensaml.saml.common.messaging.context.SAMLProtocolContext;
import org.opensaml.saml.common.messaging.context.SAMLSelfEntityContext;
+import org.opensaml.saml.common.messaging.context.navigate.SAMLEntityIDFunction;
+import org.opensaml.saml.common.messaging.context.navigate.SAMLMessageInfoContextIDFunction;
import org.opensaml.saml.criterion.EntityRoleCriterion;
import org.opensaml.saml.criterion.ProtocolCriterion;
import org.opensaml.saml.criterion.RoleDescriptorCriterion;
import org.opensaml.saml.saml2.assertion.SAML2AssertionValidationParameters;
import org.opensaml.saml.saml2.core.Assertion;
-import org.opensaml.saml.saml2.core.RequestAbstractType;
import org.opensaml.saml.saml2.profile.impl.ValidateAssertions.AssertionValidationInput;
import org.opensaml.security.SecurityException;
import org.opensaml.security.credential.UsageType;
@@ -74,6 +70,12 @@ import org.slf4j.LoggerFactory;
import com.google.common.base.Predicates;
+import net.shibboleth.utilities.java.support.collection.LazySet;
+import net.shibboleth.utilities.java.support.collection.Pair;
+import net.shibboleth.utilities.java.support.logic.Constraint;
+import net.shibboleth.utilities.java.support.primitive.StringSupport;
+import net.shibboleth.utilities.java.support.resolver.CriteriaSet;
+
/**
* Function which implements default behavior for building an instance of {@link ValidationContext}
* from an instance of {@link AssertionValidationInput}.
@@ -982,17 +984,26 @@ public class DefaultAssertionValidationContextBuilder
/** Default strategy for resolving the valid InResponseTo value. */
public static class DefaultValidInResponseToLookupFunction implements Function<ProfileRequestContext, String> {
+ /** The lookup delegate. */
+ private Function<MessageContext, String> delegate;
+
+ /** Constructor. */
+ public DefaultValidInResponseToLookupFunction() {
+ delegate = new SAMLMessageInfoContextIDFunction().compose(
+ new ChildContextLookup<>(SAMLMessageInfoContext.class).compose(
+ new MessageContextLookup<>(Direction.OUTBOUND)));
+ }
+
/** {@inheritDoc} */
public String apply(@Nullable final ProfileRequestContext prc) {
- if (prc == null
- || prc.getOutboundMessageContext() == null
- || prc.getOutboundMessageContext().getMessage() == null
- || ! RequestAbstractType.class.isInstance(prc.getOutboundMessageContext().getMessage())) {
+ if (prc == null || prc.getInboundMessageContext() == null) {
return null;
}
- return RequestAbstractType.class.cast(prc.getOutboundMessageContext().getMessage()).getID();
+
+ //Note: Doesn't matter whether we apply to inbound or outbound
+ return delegate.apply(prc.getInboundMessageContext());
}
-
+
}
/**
@@ -1005,12 +1016,13 @@ public class DefaultAssertionValidationContextBuilder
public static class DefaultValidIssuersLookupFunction implements Function<ProfileRequestContext, Set<String>> {
/** The lookup delegate. */
- private MessageContextEntityIDLookup delegate;
+ private Function<MessageContext, String> delegate;
/** Constructor. */
public DefaultValidIssuersLookupFunction() {
- delegate = new MessageContextEntityIDLookup(SAMLPeerEntityContext.class);
- delegate.setDirection(Direction.OUTBOUND);
+ delegate = new SAMLEntityIDFunction().compose(
+ new ChildContextLookup<>(SAMLPeerEntityContext.class).compose(
+ new MessageContextLookup<>(Direction.OUTBOUND)));
}
/** {@inheritDoc} */
diff --git a/opensaml-saml-impl/src/test/java/org/opensaml/saml/common/binding/security/impl/MessageContextEntityIDLookupTest.java b/opensaml-saml-impl/src/test/java/org/opensaml/saml/common/binding/security/impl/MessageContextEntityIDLookupTest.java
deleted file mode 100644
index 6f00ec5..0000000
--- a/opensaml-saml-impl/src/test/java/org/opensaml/saml/common/binding/security/impl/MessageContextEntityIDLookupTest.java
+++ /dev/null
@@ -1,91 +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 org.opensaml.saml.common.binding.security.impl;
-
-import org.opensaml.messaging.context.InOutOperationContext;
-import org.opensaml.messaging.context.MessageContext;
-import org.opensaml.saml.common.binding.security.impl.MessageContextEntityIDLookup.Direction;
-import org.opensaml.saml.common.messaging.context.SAMLPeerEntityContext;
-import org.opensaml.saml.common.messaging.context.SAMLSelfEntityContext;
-import org.testng.annotations.BeforeMethod;
-import org.testng.annotations.Test;
-
-import junit.framework.Assert;
-
-/**
- *
- */
-public class MessageContextEntityIDLookupTest {
-
- private InOutOperationContext opContext;
-
- @BeforeMethod
- public void setUp() {
- opContext = new InOutOperationContext(new MessageContext(), new MessageContext());
- opContext.getInboundMessageContext().getSubcontext(SAMLPeerEntityContext.class, true).setEntityId("inbound-peer");
- opContext.getInboundMessageContext().getSubcontext(SAMLSelfEntityContext.class, true).setEntityId("inbound-self");
- opContext.getOutboundMessageContext().getSubcontext(SAMLPeerEntityContext.class, true).setEntityId("outbound-peer");
- opContext.getOutboundMessageContext().getSubcontext(SAMLSelfEntityContext.class, true).setEntityId("outbound-self");
- }
-
- @Test
- public void testInboundPeer() {
- MessageContextEntityIDLookup lookup = new MessageContextEntityIDLookup(SAMLPeerEntityContext.class);
- lookup.setDirection(Direction.INBOUND);
- Assert.assertEquals("inbound-peer", lookup.apply(opContext.getInboundMessageContext()));
- Assert.assertEquals("inbound-peer", lookup.apply(opContext.getOutboundMessageContext()));
- }
-
- @Test
- public void testInboundSelf() {
- MessageContextEntityIDLookup lookup = new MessageContextEntityIDLookup(SAMLSelfEntityContext.class);
- lookup.setDirection(Direction.INBOUND);
- Assert.assertEquals("inbound-self", lookup.apply(opContext.getInboundMessageContext()));
- Assert.assertEquals("inbound-self", lookup.apply(opContext.getOutboundMessageContext()));
- }
-
- @Test
- public void testOutboundPeer() {
- MessageContextEntityIDLookup lookup = new MessageContextEntityIDLookup(SAMLPeerEntityContext.class);
- lookup.setDirection(Direction.OUTBOUND);
- Assert.assertEquals("outbound-peer", lookup.apply(opContext.getInboundMessageContext()));
- Assert.assertEquals("outbound-peer", lookup.apply(opContext.getOutboundMessageContext()));
- }
-
- @Test
- public void testOutboundSelf() {
- MessageContextEntityIDLookup lookup = new MessageContextEntityIDLookup(SAMLSelfEntityContext.class);
- lookup.setDirection(Direction.OUTBOUND);
- Assert.assertEquals("outbound-self", lookup.apply(opContext.getInboundMessageContext()));
- Assert.assertEquals("outbound-self", lookup.apply(opContext.getOutboundMessageContext()));
- }
-
- @Test
- public void testNoParentOpContext() {
- MessageContextEntityIDLookup lookup = new MessageContextEntityIDLookup(SAMLPeerEntityContext.class);
- Assert.assertNull(lookup.apply(new MessageContext()));
- }
-
- @Test(expectedExceptions=IllegalArgumentException.class)
- public void testNoDirection() {
- MessageContextEntityIDLookup lookup = new MessageContextEntityIDLookup(SAMLPeerEntityContext.class);
- Assert.assertEquals("outbound-peer", lookup.apply(opContext.getInboundMessageContext()));
- }
-
-
-}
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the commits
mailing list