[java-opensaml] branch main updated: IDP-2069 - Null Handling Task
Scott Cantor
cantor.2 at osu.edu
Tue Mar 21 19:49:01 UTC 2023
This is an automated email from the git hooks/post-receive script.
scantor pushed a commit to branch main
in repository java-opensaml.
View the commit online:
http://git.shibboleth.net/view/?p=java-opensaml.git;a=commit;h=c75995eaecdf4d8de9224d0dc4776a1dec7ad47a
The following commit(s) were added to refs/heads/main by this push:
new c75995eae IDP-2069 - Null Handling Task
c75995eae is described below
commit c75995eaecdf4d8de9224d0dc4776a1dec7ad47a
Author: Scott Cantor <cantor.2 at osu.edu>
AuthorDate: Tue Mar 21 15:48:58 2023 -0400
IDP-2069 - Null Handling Task
https://shibboleth.atlassian.net/browse/IDP-2069
Clean opensaml-profile-impl/messaging-impl.
---
.../handler/impl/CheckExpectedIssuer.java | 2 +-
.../impl/MessageHandlerErrorStrategyAdapter.java | 8 +++---
.../handler/impl/SchemaValidateXMLMessage.java | 23 +++++++---------
.../impl/URLEvaluatingMessageChannelSecurity.java | 18 ++++++++-----
.../handler/impl/CheckExpectedIssuerTest.java | 1 +
.../impl/CheckMandatoryAuthenticationTest.java | 1 +
.../handler/impl/CheckMandatoryIssuerTest.java | 1 +
.../URLEvaluatingMessageChannelSecurityTest.java | 31 +++++++++++-----------
.../AbstractHandlerDelegatingProfileAction.java | 7 ++---
.../opensaml/profile/action/impl/CheckAccess.java | 25 +++++++----------
.../profile/action/impl/DecodeMessage.java | 12 ++++++---
.../profile/action/impl/EncodeMessage.java | 27 ++++++++++++-------
.../HttpServletRequestMessageChannelSecurity.java | 23 +++++++++++++---
.../org/opensaml/profile/action/impl/LogEvent.java | 21 +++++++--------
.../PopulateClientTLSValidationParameters.java | 2 +-
.../action/impl/PopulateDecryptionParameters.java | 2 +-
.../profile/action/impl/PopulateMetricContext.java | 2 +-
.../PopulateSignatureValidationParameters.java | 7 ++---
.../action/impl/StaticMessageChannelSecurity.java | 15 ++++++++++-
.../profile/action/impl/DecodeMessageTest.java | 9 +++++--
.../profile/action/impl/EncodeMessageTest.java | 11 +++++---
.../PopulateClientTLSValidationParametersTest.java | 30 ++++++++++++++-------
.../impl/PopulateDecryptionParametersTest.java | 30 ++++++++++++++-------
.../PopulateSignatureValidationParametersTest.java | 30 ++++++++++++++-------
.../profile/action/impl/SetProfileIdTest.java | 11 +-------
25 files changed, 207 insertions(+), 142 deletions(-)
diff --git a/opensaml-messaging-impl/src/main/java/org/opensaml/messaging/handler/impl/CheckExpectedIssuer.java b/opensaml-messaging-impl/src/main/java/org/opensaml/messaging/handler/impl/CheckExpectedIssuer.java
index e9939f74e..d3e6bc4e0 100644
--- a/opensaml-messaging-impl/src/main/java/org/opensaml/messaging/handler/impl/CheckExpectedIssuer.java
+++ b/opensaml-messaging-impl/src/main/java/org/opensaml/messaging/handler/impl/CheckExpectedIssuer.java
@@ -26,11 +26,11 @@ import org.opensaml.messaging.context.MessageContext;
import org.opensaml.messaging.handler.AbstractMessageHandler;
import org.opensaml.messaging.handler.MessageHandlerException;
import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
import net.shibboleth.shared.annotation.constraint.NonnullAfterInit;
import net.shibboleth.shared.component.ComponentInitializationException;
import net.shibboleth.shared.logic.Constraint;
+import net.shibboleth.shared.primitive.LoggerFactory;
/**
* Message handler that checks that a message context has an issuer.
diff --git a/opensaml-messaging-impl/src/main/java/org/opensaml/messaging/handler/impl/MessageHandlerErrorStrategyAdapter.java b/opensaml-messaging-impl/src/main/java/org/opensaml/messaging/handler/impl/MessageHandlerErrorStrategyAdapter.java
index 196eab229..c3c4f2adc 100644
--- a/opensaml-messaging-impl/src/main/java/org/opensaml/messaging/handler/impl/MessageHandlerErrorStrategyAdapter.java
+++ b/opensaml-messaging-impl/src/main/java/org/opensaml/messaging/handler/impl/MessageHandlerErrorStrategyAdapter.java
@@ -22,7 +22,9 @@ import java.util.List;
import javax.annotation.Nonnull;
import net.shibboleth.shared.annotation.constraint.NonnullElements;
+import net.shibboleth.shared.collection.CollectionSupport;
import net.shibboleth.shared.logic.Constraint;
+import net.shibboleth.shared.primitive.LoggerFactory;
import org.opensaml.messaging.context.MessageContext;
import org.opensaml.messaging.error.TypedMessageErrorHandler;
@@ -30,7 +32,6 @@ import org.opensaml.messaging.handler.AbstractMessageHandler;
import org.opensaml.messaging.handler.MessageHandler;
import org.opensaml.messaging.handler.MessageHandlerException;
import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
/**
* A {@link MessageHandler} which wraps and invokes another handler, catches any {@link Throwable} which is
@@ -83,8 +84,7 @@ public class MessageHandlerErrorStrategyAdapter extends AbstractMessageHandler {
public MessageHandlerErrorStrategyAdapter(@Nonnull final MessageHandler messageHandler,
@Nonnull @NonnullElements final List<TypedMessageErrorHandler> typedErrorHandlers) {
wrappedHandler = Constraint.isNotNull(messageHandler, "Wrapped MessageHandler cannot be null");
- errorHandlers = List.copyOf(
- Constraint.isNotNull(typedErrorHandlers, "List of TypedMessageErroHandlers cannot be null"));
+ errorHandlers = CollectionSupport.copyToList(typedErrorHandlers);
rethrowIfHandled = false;
rethrowIfNotHandled = true;
@@ -116,7 +116,7 @@ public class MessageHandlerErrorStrategyAdapter extends AbstractMessageHandler {
/** {@inheritDoc} */
- protected void doInvoke(final MessageContext messageContext) throws MessageHandlerException {
+ protected void doInvoke(@Nonnull final MessageContext messageContext) throws MessageHandlerException {
try {
wrappedHandler.invoke(messageContext);
} catch (final Throwable t) {
diff --git a/opensaml-messaging-impl/src/main/java/org/opensaml/messaging/handler/impl/SchemaValidateXMLMessage.java b/opensaml-messaging-impl/src/main/java/org/opensaml/messaging/handler/impl/SchemaValidateXMLMessage.java
index 7bc4b4391..4132cf91d 100644
--- a/opensaml-messaging-impl/src/main/java/org/opensaml/messaging/handler/impl/SchemaValidateXMLMessage.java
+++ b/opensaml-messaging-impl/src/main/java/org/opensaml/messaging/handler/impl/SchemaValidateXMLMessage.java
@@ -20,7 +20,6 @@ package org.opensaml.messaging.handler.impl;
import java.io.IOException;
import javax.annotation.Nonnull;
-import javax.annotation.Nullable;
import javax.xml.transform.dom.DOMSource;
import javax.xml.validation.Schema;
import javax.xml.validation.Validator;
@@ -30,10 +29,10 @@ import org.opensaml.messaging.context.MessageContext;
import org.opensaml.messaging.handler.AbstractMessageHandler;
import org.opensaml.messaging.handler.MessageHandlerException;
import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
import org.xml.sax.SAXException;
import net.shibboleth.shared.logic.Constraint;
+import net.shibboleth.shared.primitive.LoggerFactory;
/**
* A handler that schema validates an XML-based message.
@@ -47,9 +46,6 @@ public class SchemaValidateXMLMessage extends AbstractMessageHandler {
/** Schema used to validate incoming messages. */
@Nonnull private final Schema validationSchema;
-
- /** The message to validate. */
- @Nullable private XMLObject message;
/**
* Constructor.
@@ -85,13 +81,6 @@ public class SchemaValidateXMLMessage extends AbstractMessageHandler {
throw new MessageHandlerException("Message context did not contain an XMLObject, unable to proceed.");
}
- message = (XMLObject) messageContext.getMessage();
-
- if (message.getDOM() == null) {
- log.debug("{} Message doesn't contain a DOM, unable to proceed", getLogPrefix());
- throw new MessageHandlerException("Message doesn't contain a DOM, unable to proceed.");
- }
-
return true;
}
@@ -100,7 +89,15 @@ public class SchemaValidateXMLMessage extends AbstractMessageHandler {
throws MessageHandlerException {
log.debug("{} Attempting to schema validate incoming message", getLogPrefix());
-
+
+ final XMLObject message = (XMLObject) messageContext.getMessage();
+ assert message != null;
+ if (message.getDOM() == null) {
+ log.debug("{} Message doesn't contain a DOM, unable to proceed", getLogPrefix());
+ throw new MessageHandlerException("Message doesn't contain a DOM, unable to proceed.");
+ }
+
+
try {
final Validator schemaValidator = validationSchema.newValidator();
schemaValidator.validate(new DOMSource(message.getDOM()));
diff --git a/opensaml-messaging-impl/src/main/java/org/opensaml/messaging/handler/impl/URLEvaluatingMessageChannelSecurity.java b/opensaml-messaging-impl/src/main/java/org/opensaml/messaging/handler/impl/URLEvaluatingMessageChannelSecurity.java
index 5dd5e0303..7e954bbf3 100644
--- a/opensaml-messaging-impl/src/main/java/org/opensaml/messaging/handler/impl/URLEvaluatingMessageChannelSecurity.java
+++ b/opensaml-messaging-impl/src/main/java/org/opensaml/messaging/handler/impl/URLEvaluatingMessageChannelSecurity.java
@@ -27,11 +27,11 @@ import org.opensaml.messaging.context.MessageChannelSecurityContext;
import org.opensaml.messaging.context.MessageContext;
import org.opensaml.messaging.handler.MessageHandlerException;
import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
import net.shibboleth.shared.annotation.constraint.NonnullAfterInit;
import net.shibboleth.shared.component.ComponentInitializationException;
import net.shibboleth.shared.net.URLBuilder;
+import net.shibboleth.shared.primitive.LoggerFactory;
/**
* Message handler which populates a {@link MessageChannelSecurityContext} based on evaluating a
@@ -121,18 +121,22 @@ public class URLEvaluatingMessageChannelSecurity extends AbstractMessageChannelS
protected void doInvoke(@Nonnull final MessageContext messageContext) {
final MessageChannelSecurityContext channelContext =
getParentContext().ensureSubcontext(MessageChannelSecurityContext.class);
-
+
+ assert urlBuilder != null;
final String scheme = urlBuilder.getScheme();
// Note that below we don't care about port if scheme != https,
// so only need to worry about default port for https, not all possible schemes.
- final Integer port = urlBuilder.getPort() != null
- ? urlBuilder.getPort()
- : "https".equalsIgnoreCase(scheme) ? 443 : null;
-
+ assert urlBuilder != null;
+ Integer port = urlBuilder.getPort();
+ if (port == null) {
+ port = "https".equalsIgnoreCase(scheme) ? 443 : null;
+ }
+
log.debug("Evaluating message channel security for scheme '{}' and port '{}' for URL: {}",
scheme, port, url);
- if ("https".equalsIgnoreCase(scheme) && (!defaultPortInsecure || port != 443)) {
+ // Port can't actually be null in this expression....
+ if ("https".equalsIgnoreCase(scheme) && (!defaultPortInsecure || port == null || port != 443)) {
channelContext.setConfidentialityActive(true);
channelContext.setIntegrityActive(true);
} else {
diff --git a/opensaml-messaging-impl/src/test/java/org/opensaml/messaging/handler/impl/CheckExpectedIssuerTest.java b/opensaml-messaging-impl/src/test/java/org/opensaml/messaging/handler/impl/CheckExpectedIssuerTest.java
index 2f048b36f..a5c7ef20f 100644
--- a/opensaml-messaging-impl/src/test/java/org/opensaml/messaging/handler/impl/CheckExpectedIssuerTest.java
+++ b/opensaml-messaging-impl/src/test/java/org/opensaml/messaging/handler/impl/CheckExpectedIssuerTest.java
@@ -25,6 +25,7 @@ import net.shibboleth.shared.component.ComponentInitializationException;
import net.shibboleth.shared.logic.FunctionSupport;
/** Unit test for {@link CheckMandatoryIssuer}. */
+ at SuppressWarnings("javadoc")
public class CheckExpectedIssuerTest {
@Test
diff --git a/opensaml-messaging-impl/src/test/java/org/opensaml/messaging/handler/impl/CheckMandatoryAuthenticationTest.java b/opensaml-messaging-impl/src/test/java/org/opensaml/messaging/handler/impl/CheckMandatoryAuthenticationTest.java
index 02ce6a88c..4f37ad895 100644
--- a/opensaml-messaging-impl/src/test/java/org/opensaml/messaging/handler/impl/CheckMandatoryAuthenticationTest.java
+++ b/opensaml-messaging-impl/src/test/java/org/opensaml/messaging/handler/impl/CheckMandatoryAuthenticationTest.java
@@ -24,6 +24,7 @@ import org.testng.annotations.Test;
import net.shibboleth.shared.logic.FunctionSupport;
/** Unit test for {@link CheckMandatoryAuthentication}. */
+ at SuppressWarnings("javadoc")
public class CheckMandatoryAuthenticationTest {
@Test public void testAuthenticated() throws Exception {
diff --git a/opensaml-messaging-impl/src/test/java/org/opensaml/messaging/handler/impl/CheckMandatoryIssuerTest.java b/opensaml-messaging-impl/src/test/java/org/opensaml/messaging/handler/impl/CheckMandatoryIssuerTest.java
index 0becfbfa1..5724f9343 100644
--- a/opensaml-messaging-impl/src/test/java/org/opensaml/messaging/handler/impl/CheckMandatoryIssuerTest.java
+++ b/opensaml-messaging-impl/src/test/java/org/opensaml/messaging/handler/impl/CheckMandatoryIssuerTest.java
@@ -24,6 +24,7 @@ import org.testng.annotations.Test;
import net.shibboleth.shared.logic.FunctionSupport;
/** Unit test for {@link CheckMandatoryIssuer}. */
+ at SuppressWarnings("javadoc")
public class CheckMandatoryIssuerTest {
@Test public void testWithIssuer() throws Exception {
diff --git a/opensaml-messaging-impl/src/test/java/org/opensaml/messaging/handler/impl/URLEvaluatingMessageChannelSecurityTest.java b/opensaml-messaging-impl/src/test/java/org/opensaml/messaging/handler/impl/URLEvaluatingMessageChannelSecurityTest.java
index 778af0d50..adad0603e 100644
--- a/opensaml-messaging-impl/src/test/java/org/opensaml/messaging/handler/impl/URLEvaluatingMessageChannelSecurityTest.java
+++ b/opensaml-messaging-impl/src/test/java/org/opensaml/messaging/handler/impl/URLEvaluatingMessageChannelSecurityTest.java
@@ -27,6 +27,7 @@ import org.testng.annotations.Test;
import net.shibboleth.shared.component.ComponentInitializationException;
import net.shibboleth.shared.logic.FunctionSupport;
+ at SuppressWarnings("javadoc")
public class URLEvaluatingMessageChannelSecurityTest {
private URLEvaluatingMessageChannelSecurity handler;
@@ -46,8 +47,8 @@ public class URLEvaluatingMessageChannelSecurityTest {
handler.invoke(messageContext);
- MessageChannelSecurityContext channelSecurityContext = messageContext.getSubcontext(MessageChannelSecurityContext.class);
- Assert.assertNotNull(channelSecurityContext);
+ final MessageChannelSecurityContext channelSecurityContext = messageContext.getSubcontext(MessageChannelSecurityContext.class);
+ assert channelSecurityContext != null;
Assert.assertFalse(channelSecurityContext.isIntegrityActive());
Assert.assertFalse(channelSecurityContext.isConfidentialityActive());
}
@@ -59,8 +60,8 @@ public class URLEvaluatingMessageChannelSecurityTest {
handler.invoke(messageContext);
- MessageChannelSecurityContext channelSecurityContext = messageContext.getSubcontext(MessageChannelSecurityContext.class);
- Assert.assertNotNull(channelSecurityContext);
+ final MessageChannelSecurityContext channelSecurityContext = messageContext.getSubcontext(MessageChannelSecurityContext.class);
+ assert channelSecurityContext != null;
Assert.assertFalse(channelSecurityContext.isIntegrityActive());
Assert.assertFalse(channelSecurityContext.isConfidentialityActive());
}
@@ -73,8 +74,8 @@ public class URLEvaluatingMessageChannelSecurityTest {
handler.invoke(messageContext);
- MessageChannelSecurityContext channelSecurityContext = messageContext.getSubcontext(MessageChannelSecurityContext.class);
- Assert.assertNotNull(channelSecurityContext);
+ final MessageChannelSecurityContext channelSecurityContext = messageContext.getSubcontext(MessageChannelSecurityContext.class);
+ assert channelSecurityContext != null;
Assert.assertTrue(channelSecurityContext.isIntegrityActive());
Assert.assertTrue(channelSecurityContext.isConfidentialityActive());
}
@@ -87,8 +88,8 @@ public class URLEvaluatingMessageChannelSecurityTest {
handler.invoke(messageContext);
- MessageChannelSecurityContext channelSecurityContext = messageContext.getSubcontext(MessageChannelSecurityContext.class);
- Assert.assertNotNull(channelSecurityContext);
+ final MessageChannelSecurityContext channelSecurityContext = messageContext.getSubcontext(MessageChannelSecurityContext.class);
+ assert channelSecurityContext != null;
Assert.assertTrue(channelSecurityContext.isIntegrityActive());
Assert.assertTrue(channelSecurityContext.isConfidentialityActive());
}
@@ -100,8 +101,8 @@ public class URLEvaluatingMessageChannelSecurityTest {
handler.invoke(messageContext);
- MessageChannelSecurityContext channelSecurityContext = messageContext.getSubcontext(MessageChannelSecurityContext.class);
- Assert.assertNotNull(channelSecurityContext);
+ final MessageChannelSecurityContext channelSecurityContext = messageContext.getSubcontext(MessageChannelSecurityContext.class);
+ assert channelSecurityContext != null;
Assert.assertTrue(channelSecurityContext.isIntegrityActive());
Assert.assertTrue(channelSecurityContext.isConfidentialityActive());
}
@@ -113,8 +114,8 @@ public class URLEvaluatingMessageChannelSecurityTest {
handler.invoke(messageContext);
- MessageChannelSecurityContext channelSecurityContext = messageContext.getSubcontext(MessageChannelSecurityContext.class);
- Assert.assertNotNull(channelSecurityContext);
+ final MessageChannelSecurityContext channelSecurityContext = messageContext.getSubcontext(MessageChannelSecurityContext.class);
+ assert channelSecurityContext != null;
Assert.assertFalse(channelSecurityContext.isIntegrityActive());
Assert.assertFalse(channelSecurityContext.isConfidentialityActive());
}
@@ -126,8 +127,8 @@ public class URLEvaluatingMessageChannelSecurityTest {
handler.invoke(messageContext);
- MessageChannelSecurityContext channelSecurityContext = messageContext.getSubcontext(MessageChannelSecurityContext.class);
- Assert.assertNotNull(channelSecurityContext);
+ final MessageChannelSecurityContext channelSecurityContext = messageContext.getSubcontext(MessageChannelSecurityContext.class);
+ assert channelSecurityContext != null;
Assert.assertFalse(channelSecurityContext.isIntegrityActive());
Assert.assertFalse(channelSecurityContext.isConfidentialityActive());
}
@@ -139,7 +140,7 @@ public class URLEvaluatingMessageChannelSecurityTest {
handler.invoke(messageContext);
- MessageChannelSecurityContext channelSecurityContext = messageContext.getSubcontext(MessageChannelSecurityContext.class);
+ final MessageChannelSecurityContext channelSecurityContext = messageContext.getSubcontext(MessageChannelSecurityContext.class);
Assert.assertNull(channelSecurityContext);
}
diff --git a/opensaml-profile-api/src/main/java/org/opensaml/profile/action/AbstractHandlerDelegatingProfileAction.java b/opensaml-profile-api/src/main/java/org/opensaml/profile/action/AbstractHandlerDelegatingProfileAction.java
index 8a9723f47..6a14e2c6c 100644
--- a/opensaml-profile-api/src/main/java/org/opensaml/profile/action/AbstractHandlerDelegatingProfileAction.java
+++ b/opensaml-profile-api/src/main/java/org/opensaml/profile/action/AbstractHandlerDelegatingProfileAction.java
@@ -142,11 +142,8 @@ public abstract class AbstractHandlerDelegatingProfileAction<DelegateType extend
*
* @param <T> the output type of the functions
*/
- @Nullable protected <T> Function<MessageContext, T> adapt(
- @Nullable final Function<ProfileRequestContext, T> function) {
- if (function == null) {
- return null;
- }
+ @Nonnull protected <T> Function<MessageContext, T> adapt(
+ @Nonnull final Function<ProfileRequestContext, T> function) {
return function.compose(PRC_LOOKUP);
}
diff --git a/opensaml-profile-impl/src/main/java/org/opensaml/profile/action/impl/CheckAccess.java b/opensaml-profile-impl/src/main/java/org/opensaml/profile/action/impl/CheckAccess.java
index 959abd645..1d707760e 100644
--- a/opensaml-profile-impl/src/main/java/org/opensaml/profile/action/impl/CheckAccess.java
+++ b/opensaml-profile-impl/src/main/java/org/opensaml/profile/action/impl/CheckAccess.java
@@ -27,13 +27,14 @@ import org.opensaml.profile.action.ActionSupport;
import org.opensaml.profile.action.EventIds;
import org.opensaml.profile.context.ProfileRequestContext;
import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
+import jakarta.servlet.http.HttpServletRequest;
import net.shibboleth.shared.annotation.constraint.NonnullAfterInit;
import net.shibboleth.shared.annotation.constraint.NotEmpty;
import net.shibboleth.shared.component.ComponentInitializationException;
import net.shibboleth.shared.logic.Constraint;
import net.shibboleth.shared.logic.FunctionSupport;
+import net.shibboleth.shared.primitive.LoggerFactory;
import net.shibboleth.shared.primitive.StringSupport;
import net.shibboleth.shared.security.AccessControlService;
@@ -164,29 +165,21 @@ public class CheckAccess extends AbstractProfileAction {
/** {@inheritDoc} */
@Override
- public boolean doPreExecute(@Nonnull final ProfileRequestContext profileRequestContext) {
-
- if (!super.doPreExecute(profileRequestContext)) {
- return false;
- } else if (getHttpServletRequest() == null) {
+ public void doExecute(@Nonnull final ProfileRequestContext profileRequestContext) {
+
+ final HttpServletRequest httpRequest = getHttpServletRequest();
+ if (httpRequest == null) {
log.warn("{} HttpServletRequest was null, disallowing access", getLogPrefix());
ActionSupport.buildEvent(profileRequestContext, EventIds.ACCESS_DENIED);
- return false;
+ return;
}
- return true;
- }
-
- /** {@inheritDoc} */
- @Override
- public void doExecute(@Nonnull final ProfileRequestContext profileRequestContext) {
-
final String policyName = policyNameLookupStrategy.apply(profileRequestContext);
if (policyName == null) {
log.warn("{} No policy name returned by lookup strategy, disallowing access", getLogPrefix());
ActionSupport.buildEvent(profileRequestContext, EventIds.ACCESS_DENIED);
- } else if (!service.getInstance(policyName).checkAccess(
- getHttpServletRequest(), operationLookupStrategy.apply(profileRequestContext),
+ } else if (!service.getInstance(policyName).checkAccess(httpRequest,
+ operationLookupStrategy.apply(profileRequestContext),
resourceLookupStrategy.apply(profileRequestContext))) {
ActionSupport.buildEvent(profileRequestContext, EventIds.ACCESS_DENIED);
}
diff --git a/opensaml-profile-impl/src/main/java/org/opensaml/profile/action/impl/DecodeMessage.java b/opensaml-profile-impl/src/main/java/org/opensaml/profile/action/impl/DecodeMessage.java
index 8a1deb70e..a4bbcc2cc 100644
--- a/opensaml-profile-impl/src/main/java/org/opensaml/profile/action/impl/DecodeMessage.java
+++ b/opensaml-profile-impl/src/main/java/org/opensaml/profile/action/impl/DecodeMessage.java
@@ -27,9 +27,9 @@ import org.opensaml.profile.action.ActionSupport;
import org.opensaml.profile.action.EventIds;
import org.opensaml.profile.context.ProfileRequestContext;
import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
import net.shibboleth.shared.logic.Constraint;
+import net.shibboleth.shared.primitive.LoggerFactory;
/**
* Action that decodes an incoming request into a {@link MessageContext}.
@@ -65,8 +65,14 @@ public class DecodeMessage extends AbstractProfileAction {
decoder.getClass().getName());
decoder.decode();
final MessageContext msgContext = decoder.getMessageContext();
- log.debug("{} Incoming request decoded into a message of type {}", getLogPrefix(),
- msgContext.getMessage().getClass().getName());
+ final Object msg = msgContext != null ? msgContext.getMessage() : null;
+
+ if (msg != null) {
+ log.debug("{} Incoming request decoded into a message of type {}", getLogPrefix(),
+ msg.getClass().getName());
+ } else {
+ log.warn("{} Decoder did not produce an incoming message?", getLogPrefix());
+ }
profileRequestContext.setInboundMessageContext(msgContext);
} catch (final MessageDecodingException e) {
diff --git a/opensaml-profile-impl/src/main/java/org/opensaml/profile/action/impl/EncodeMessage.java b/opensaml-profile-impl/src/main/java/org/opensaml/profile/action/impl/EncodeMessage.java
index 4bd5fb0ef..56652ee75 100644
--- a/opensaml-profile-impl/src/main/java/org/opensaml/profile/action/impl/EncodeMessage.java
+++ b/opensaml-profile-impl/src/main/java/org/opensaml/profile/action/impl/EncodeMessage.java
@@ -25,6 +25,7 @@ import javax.annotation.Nullable;
import net.shibboleth.shared.annotation.constraint.NonnullAfterInit;
import net.shibboleth.shared.component.ComponentInitializationException;
import net.shibboleth.shared.logic.Constraint;
+import net.shibboleth.shared.primitive.LoggerFactory;
import org.opensaml.messaging.context.MessageContext;
import org.opensaml.messaging.encoder.MessageEncoder;
@@ -36,7 +37,6 @@ import org.opensaml.profile.action.ActionSupport;
import org.opensaml.profile.action.EventIds;
import org.opensaml.profile.context.ProfileRequestContext;
import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
/**
* Action that encodes an outbound response from the outbound {@link MessageContext}.
@@ -104,6 +104,10 @@ public class EncodeMessage extends AbstractProfileAction {
@Override
protected boolean doPreExecute(@Nonnull final ProfileRequestContext profileRequestContext) {
+ if (!super.doPreExecute(profileRequestContext)) {
+ return false;
+ }
+
msgContext = profileRequestContext.getOutboundMessageContext();
if (msgContext == null) {
log.debug("{} Outbound message context was null", getLogPrefix());
@@ -111,7 +115,7 @@ public class EncodeMessage extends AbstractProfileAction {
return false;
}
- return super.doPreExecute(profileRequestContext);
+ return true;
}
/** {@inheritDoc} */
@@ -140,19 +144,24 @@ public class EncodeMessage extends AbstractProfileAction {
encoder.prepareContext();
- if (messageHandler != null) {
+ final MessageHandler handlerCopy = messageHandler;
+ if (handlerCopy != null) {
log.debug("{} Invoking message handler of type {} for this response", getLogPrefix(),
- messageHandler.getClass().getName());
- messageHandler.invoke(msgContext);
+ handlerCopy.getClass().getName());
+ assert msgContext != null;
+ handlerCopy.invoke(msgContext);
}
encoder.encode();
- if (msgContext.getMessage() != null) {
- log.debug("{} Outbound message encoded from a message of type {}", getLogPrefix(),
- msgContext.getMessage().getClass().getName());
+ assert msgContext != null;
+ final Object msg = msgContext.getMessage();
+
+ if (msg != null) {
+ log.debug("{} Outbound message encoded to a message of type {}", getLogPrefix(),
+ msg.getClass().getName());
} else {
- log.debug("{} Outbound message was encoded from protocol-specific data "
+ log.debug("{} Outbound message was encoded via protocol-specific data "
+ "rather than MessageContext#getMessage()", getLogPrefix());
}
diff --git a/opensaml-profile-impl/src/main/java/org/opensaml/profile/action/impl/HttpServletRequestMessageChannelSecurity.java b/opensaml-profile-impl/src/main/java/org/opensaml/profile/action/impl/HttpServletRequestMessageChannelSecurity.java
index 823306ae7..7769fe707 100644
--- a/opensaml-profile-impl/src/main/java/org/opensaml/profile/action/impl/HttpServletRequestMessageChannelSecurity.java
+++ b/opensaml-profile-impl/src/main/java/org/opensaml/profile/action/impl/HttpServletRequestMessageChannelSecurity.java
@@ -17,7 +17,12 @@
package org.opensaml.profile.action.impl;
+import javax.annotation.Nonnull;
+
+import org.opensaml.messaging.context.BaseContext;
import org.opensaml.messaging.context.MessageChannelSecurityContext;
+import org.opensaml.profile.action.ActionSupport;
+import org.opensaml.profile.action.EventIds;
import org.opensaml.profile.context.ProfileRequestContext;
import jakarta.servlet.http.HttpServletRequest;
@@ -26,6 +31,9 @@ import net.shibboleth.shared.component.ComponentInitializationException;
/**
* Profile action which populates a {@link MessageChannelSecurityContext} based on a
* {@link jakarta.servlet.http.HttpServletRequest}.
+ *
+ * @event {@link EventIds#PROCEED_EVENT_ID}
+ * @event {@link EventIds#INVALID_PROFILE_CTX}
*/
public class HttpServletRequestMessageChannelSecurity extends AbstractMessageChannelSecurity {
@@ -66,11 +74,18 @@ public class HttpServletRequestMessageChannelSecurity extends AbstractMessageCha
/** {@inheritDoc} */
@Override
- protected void doExecute(final ProfileRequestContext profileRequestContext) {
- final MessageChannelSecurityContext channelContext =
- getParentContext().ensureSubcontext(MessageChannelSecurityContext.class);
+ protected void doExecute(@Nonnull final ProfileRequestContext profileRequestContext) {
+ final BaseContext parent = getParentContext();
final HttpServletRequest request = getHttpServletRequest();
+ if (parent == null || request == null) {
+ ActionSupport.buildEvent(profileRequestContext, EventIds.INVALID_PROFILE_CTX);
+ return;
+ }
+
+ final MessageChannelSecurityContext channelContext =
+ parent.ensureSubcontext(MessageChannelSecurityContext.class);
+
if (request.isSecure() && (!defaultPortInsecure || request.getLocalPort() != 443)) {
channelContext.setConfidentialityActive(true);
channelContext.setIntegrityActive(true);
@@ -80,4 +95,4 @@ public class HttpServletRequestMessageChannelSecurity extends AbstractMessageCha
}
}
-}
+}
\ No newline at end of file
diff --git a/opensaml-profile-impl/src/main/java/org/opensaml/profile/action/impl/LogEvent.java b/opensaml-profile-impl/src/main/java/org/opensaml/profile/action/impl/LogEvent.java
index 544c9a6eb..ad8b693b4 100644
--- a/opensaml-profile-impl/src/main/java/org/opensaml/profile/action/impl/LogEvent.java
+++ b/opensaml-profile-impl/src/main/java/org/opensaml/profile/action/impl/LogEvent.java
@@ -18,7 +18,6 @@
package org.opensaml.profile.action.impl;
import java.util.Collection;
-import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
import java.util.function.Function;
@@ -31,10 +30,11 @@ import org.opensaml.profile.context.EventContext;
import org.opensaml.profile.context.ProfileRequestContext;
import org.opensaml.profile.context.navigate.CurrentOrPreviousEventLookup;
import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
import net.shibboleth.shared.annotation.constraint.NotEmpty;
+import net.shibboleth.shared.collection.CollectionSupport;
import net.shibboleth.shared.logic.Constraint;
+import net.shibboleth.shared.primitive.LoggerFactory;
import net.shibboleth.shared.primitive.StringSupport;
@@ -57,7 +57,7 @@ public class LogEvent extends AbstractProfileAction {
/** Constructor. */
public LogEvent() {
eventContextLookupStrategy = new CurrentOrPreviousEventLookup();
- suppressedEvents = Collections.emptySet();
+ suppressedEvents = CollectionSupport.emptySet();
}
/**
@@ -82,7 +82,7 @@ public class LogEvent extends AbstractProfileAction {
if (events != null) {
suppressedEvents = new HashSet<>(StringSupport.normalizeStringCollection(events));
} else {
- suppressedEvents = Collections.emptySet();
+ suppressedEvents = CollectionSupport.emptySet();
}
}
@@ -91,13 +91,12 @@ public class LogEvent extends AbstractProfileAction {
protected void doExecute(@Nonnull final ProfileRequestContext profileRequestContext) {
final EventContext eventCtx = eventContextLookupStrategy.apply(profileRequestContext);
- if (eventCtx == null || eventCtx.getEvent() == null) {
- return;
- }
-
- final String eventString = eventCtx.getEvent().toString();
- if (!suppressedEvents.contains(eventString)) {
- log.warn("A non-proceed event occurred while processing the request: {}", eventString);
+ final Object event = eventCtx != null ? eventCtx.getEvent() : null;
+ if (event != null) {
+ final String eventString = event.toString();
+ if (!suppressedEvents.contains(eventString)) {
+ log.warn("A non-proceed event occurred while processing the request: {}", eventString);
+ }
}
}
diff --git a/opensaml-profile-impl/src/main/java/org/opensaml/profile/action/impl/PopulateClientTLSValidationParameters.java b/opensaml-profile-impl/src/main/java/org/opensaml/profile/action/impl/PopulateClientTLSValidationParameters.java
index 730f22ffe..95311f95d 100644
--- a/opensaml-profile-impl/src/main/java/org/opensaml/profile/action/impl/PopulateClientTLSValidationParameters.java
+++ b/opensaml-profile-impl/src/main/java/org/opensaml/profile/action/impl/PopulateClientTLSValidationParameters.java
@@ -36,11 +36,11 @@ import org.opensaml.security.x509.tls.ClientTLSValidationConfigurationCriterion;
import org.opensaml.security.x509.tls.ClientTLSValidationParameters;
import org.opensaml.security.x509.tls.ClientTLSValidationParametersResolver;
import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
import net.shibboleth.shared.annotation.constraint.NonnullAfterInit;
import net.shibboleth.shared.component.ComponentInitializationException;
import net.shibboleth.shared.logic.Constraint;
+import net.shibboleth.shared.primitive.LoggerFactory;
import net.shibboleth.shared.resolver.CriteriaSet;
import net.shibboleth.shared.resolver.ResolverException;
diff --git a/opensaml-profile-impl/src/main/java/org/opensaml/profile/action/impl/PopulateDecryptionParameters.java b/opensaml-profile-impl/src/main/java/org/opensaml/profile/action/impl/PopulateDecryptionParameters.java
index 8ca577b7b..716bcbe36 100644
--- a/opensaml-profile-impl/src/main/java/org/opensaml/profile/action/impl/PopulateDecryptionParameters.java
+++ b/opensaml-profile-impl/src/main/java/org/opensaml/profile/action/impl/PopulateDecryptionParameters.java
@@ -36,11 +36,11 @@ import org.opensaml.xmlsec.SecurityConfigurationSupport;
import org.opensaml.xmlsec.context.SecurityParametersContext;
import org.opensaml.xmlsec.criterion.DecryptionConfigurationCriterion;
import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
import net.shibboleth.shared.annotation.constraint.NonnullAfterInit;
import net.shibboleth.shared.component.ComponentInitializationException;
import net.shibboleth.shared.logic.Constraint;
+import net.shibboleth.shared.primitive.LoggerFactory;
import net.shibboleth.shared.resolver.CriteriaSet;
import net.shibboleth.shared.resolver.ResolverException;
diff --git a/opensaml-profile-impl/src/main/java/org/opensaml/profile/action/impl/PopulateMetricContext.java b/opensaml-profile-impl/src/main/java/org/opensaml/profile/action/impl/PopulateMetricContext.java
index 28f016330..fa0b525a6 100644
--- a/opensaml-profile-impl/src/main/java/org/opensaml/profile/action/impl/PopulateMetricContext.java
+++ b/opensaml-profile-impl/src/main/java/org/opensaml/profile/action/impl/PopulateMetricContext.java
@@ -26,10 +26,10 @@ import org.opensaml.profile.action.AbstractProfileAction;
import org.opensaml.profile.context.MetricContext;
import org.opensaml.profile.context.ProfileRequestContext;
import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
import net.shibboleth.shared.annotation.constraint.NonnullAfterInit;
import net.shibboleth.shared.component.ComponentInitializationException;
+import net.shibboleth.shared.primitive.LoggerFactory;
/**
diff --git a/opensaml-profile-impl/src/main/java/org/opensaml/profile/action/impl/PopulateSignatureValidationParameters.java b/opensaml-profile-impl/src/main/java/org/opensaml/profile/action/impl/PopulateSignatureValidationParameters.java
index aff2d0fbf..26b4547b4 100644
--- a/opensaml-profile-impl/src/main/java/org/opensaml/profile/action/impl/PopulateSignatureValidationParameters.java
+++ b/opensaml-profile-impl/src/main/java/org/opensaml/profile/action/impl/PopulateSignatureValidationParameters.java
@@ -34,8 +34,6 @@ import org.opensaml.xmlsec.SignatureValidationParameters;
import org.opensaml.xmlsec.SignatureValidationParametersResolver;
import org.opensaml.xmlsec.context.SecurityParametersContext;
import org.opensaml.xmlsec.messaging.impl.PopulateSignatureValidationParametersHandler;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
import net.shibboleth.shared.annotation.constraint.NonnullAfterInit;
import net.shibboleth.shared.component.ComponentInitializationException;
@@ -51,9 +49,6 @@ import net.shibboleth.shared.logic.Constraint;
*/
public class PopulateSignatureValidationParameters
extends AbstractHandlerDelegatingProfileAction<PopulateSignatureValidationParametersHandler> {
-
- /** Class logger. */
- @Nonnull private final Logger log = LoggerFactory.getLogger(PopulateSignatureValidationParameters.class);
/** Strategy used to look up the {@link SecurityParametersContext} to set the parameters for. */
@Nonnull private Function<ProfileRequestContext,SecurityParametersContext> securityParametersContextLookupStrategy;
@@ -132,7 +127,9 @@ public class PopulateSignatureValidationParameters
}
final PopulateSignatureValidationParametersHandler delegate = getDelegate();
+ assert resolver != null;
delegate.setSignatureValidationParametersResolver(resolver);
+ assert configurationLookupStrategy != null;
delegate.setConfigurationLookupStrategy(adapt(configurationLookupStrategy));
delegate.setSecurityParametersContextLookupStrategy(adapt(securityParametersContextLookupStrategy));
delegate.initialize();
diff --git a/opensaml-profile-impl/src/main/java/org/opensaml/profile/action/impl/StaticMessageChannelSecurity.java b/opensaml-profile-impl/src/main/java/org/opensaml/profile/action/impl/StaticMessageChannelSecurity.java
index 84295d5a4..0735958af 100644
--- a/opensaml-profile-impl/src/main/java/org/opensaml/profile/action/impl/StaticMessageChannelSecurity.java
+++ b/opensaml-profile-impl/src/main/java/org/opensaml/profile/action/impl/StaticMessageChannelSecurity.java
@@ -19,11 +19,17 @@ package org.opensaml.profile.action.impl;
import javax.annotation.Nonnull;
+import org.opensaml.messaging.context.BaseContext;
import org.opensaml.messaging.context.MessageChannelSecurityContext;
+import org.opensaml.profile.action.ActionSupport;
+import org.opensaml.profile.action.EventIds;
import org.opensaml.profile.context.ProfileRequestContext;
/**
* Profile action which populates a {@link MessageChannelSecurityContext} based on static configuration flags.
+ *
+ * @event {@link EventIds#PROCEED_EVENT_ID}
+ * @event {@link EventIds#INVALID_PROFILE_CTX}
*/
public class StaticMessageChannelSecurity extends AbstractMessageChannelSecurity {
@@ -72,8 +78,15 @@ public class StaticMessageChannelSecurity extends AbstractMessageChannelSecurity
/** {@inheritDoc} */
@Override
protected void doExecute(@Nonnull final ProfileRequestContext profileRequestContext) {
+
+ final BaseContext parent = getParentContext();
+ if (parent == null) {
+ ActionSupport.buildEvent(profileRequestContext, EventIds.INVALID_PROFILE_CTX);
+ return;
+ }
+
final MessageChannelSecurityContext channelContext =
- getParentContext().ensureSubcontext(MessageChannelSecurityContext.class);
+ parent.ensureSubcontext(MessageChannelSecurityContext.class);
channelContext.setConfidentialityActive(isConfidentialityActive());
channelContext.setIntegrityActive(isIntegrityActive());
}
diff --git a/opensaml-profile-impl/src/test/java/org/opensaml/profile/action/impl/DecodeMessageTest.java b/opensaml-profile-impl/src/test/java/org/opensaml/profile/action/impl/DecodeMessageTest.java
index b504e79f6..a8fb1bedd 100644
--- a/opensaml-profile-impl/src/test/java/org/opensaml/profile/action/impl/DecodeMessageTest.java
+++ b/opensaml-profile-impl/src/test/java/org/opensaml/profile/action/impl/DecodeMessageTest.java
@@ -39,6 +39,10 @@ public class DecodeMessageTest {
private ProfileRequestContext profileCtx;
+ /**
+ * Test setup.
+ * @throws ComponentInitializationException
+ */
@BeforeMethod
public void setUp() throws ComponentInitializationException {
message = new MockMessage();
@@ -62,8 +66,9 @@ public class DecodeMessageTest {
ActionTestingSupport.assertProceedEvent(profileCtx);
- Assert.assertNotNull(profileCtx.getInboundMessageContext());
- Assert.assertEquals(profileCtx.getInboundMessageContext().getMessage(), message);
+ final MessageContext mc = profileCtx.getInboundMessageContext();
+ assert mc != null;
+ Assert.assertEquals(mc.getMessage(), message);
}
/**
diff --git a/opensaml-profile-impl/src/test/java/org/opensaml/profile/action/impl/EncodeMessageTest.java b/opensaml-profile-impl/src/test/java/org/opensaml/profile/action/impl/EncodeMessageTest.java
index eea0016ea..daa1f83d5 100644
--- a/opensaml-profile-impl/src/test/java/org/opensaml/profile/action/impl/EncodeMessageTest.java
+++ b/opensaml-profile-impl/src/test/java/org/opensaml/profile/action/impl/EncodeMessageTest.java
@@ -19,7 +19,6 @@ package org.opensaml.profile.action.impl;
import java.util.function.Function;
-import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import org.opensaml.messaging.context.MessageContext;
@@ -37,6 +36,7 @@ import org.testng.annotations.Test;
import net.shibboleth.shared.component.ComponentInitializationException;
/** Unit test for {@link EncodeMessage}. */
+ at SuppressWarnings("javadoc")
public class EncodeMessageTest {
private MockMessage message;
@@ -143,14 +143,19 @@ public class EncodeMessageTest {
if (throwException) {
throw new MessageEncodingException();
}
- message = ((MockMessage) getMessageContext().getMessage()).getEncoded();
+ final MessageContext mc = getMessageContext();
+ assert mc != null;
+
+ final MockMessage msg = (MockMessage) mc.getMessage();
+ assert msg != null;
+ message = msg.getEncoded();
}
}
private class MockEncoderFactory implements Function<ProfileRequestContext,MessageEncoder> {
/** {@inheritDoc} */
- @Nullable public MessageEncoder apply(@Nonnull final ProfileRequestContext profileRequestContext) {
+ @Nullable public MessageEncoder apply(@Nullable final ProfileRequestContext profileRequestContext) {
return encoder;
}
diff --git a/opensaml-profile-impl/src/test/java/org/opensaml/profile/action/impl/PopulateClientTLSValidationParametersTest.java b/opensaml-profile-impl/src/test/java/org/opensaml/profile/action/impl/PopulateClientTLSValidationParametersTest.java
index 881a401c8..c08d24741 100644
--- a/opensaml-profile-impl/src/test/java/org/opensaml/profile/action/impl/PopulateClientTLSValidationParametersTest.java
+++ b/opensaml-profile-impl/src/test/java/org/opensaml/profile/action/impl/PopulateClientTLSValidationParametersTest.java
@@ -17,14 +17,17 @@
package org.opensaml.profile.action.impl;
-import java.util.Collections;
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
+import net.shibboleth.shared.collection.CollectionSupport;
import net.shibboleth.shared.component.ComponentInitializationException;
import net.shibboleth.shared.logic.Constraint;
import net.shibboleth.shared.resolver.CriteriaSet;
import net.shibboleth.shared.resolver.ResolverException;
import org.opensaml.core.testing.OpenSAMLInitBaseTestCase;
+import org.opensaml.messaging.context.MessageContext;
import org.opensaml.profile.action.EventIds;
import org.opensaml.profile.context.ProfileRequestContext;
import org.opensaml.profile.testing.ActionTestingSupport;
@@ -38,6 +41,7 @@ import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
/** Unit test for {@link PopulateClientTLSValidationParameters}. */
+ at SuppressWarnings("javadoc")
public class PopulateClientTLSValidationParametersTest extends OpenSAMLInitBaseTestCase {
private ProfileRequestContext prc;
@@ -78,8 +82,12 @@ public class PopulateClientTLSValidationParametersTest extends OpenSAMLInitBaseT
action.execute(prc);
ActionTestingSupport.assertProceedEvent(prc);
- Assert.assertNotNull(prc.getInboundMessageContext().getSubcontext(
- ClientTLSSecurityParametersContext.class).getValidationParameters());
+
+ final MessageContext mc = prc.getInboundMessageContext();
+ assert mc != null;
+ final ClientTLSSecurityParametersContext ctx = mc.getSubcontext(ClientTLSSecurityParametersContext.class);
+ assert ctx != null;
+ Assert.assertNotNull(ctx.getValidationParameters());
}
private class MockResolver implements ClientTLSValidationParametersResolver {
@@ -91,20 +99,22 @@ public class PopulateClientTLSValidationParametersTest extends OpenSAMLInitBaseT
}
/** {@inheritDoc} */
- @Override
- public Iterable<ClientTLSValidationParameters> resolve(CriteriaSet criteria) throws ResolverException {
- return Collections.singletonList(resolveSingle(criteria));
+ @Nonnull public Iterable<ClientTLSValidationParameters> resolve(@Nullable final CriteriaSet criteria) throws ResolverException {
+ return CollectionSupport.singletonList(Constraint.isNotNull(resolveSingle(criteria), "Parameters were null"));
}
/** {@inheritDoc} */
- @Override
- public ClientTLSValidationParameters resolveSingle(CriteriaSet criteria) throws ResolverException {
+ @Nullable public ClientTLSValidationParameters resolveSingle(@Nullable final CriteriaSet criteria) throws ResolverException {
if (throwException) {
throw new ResolverException();
}
- Constraint.isNotNull(criteria.get(ClientTLSValidationConfigurationCriterion.class), "Criterion was null");
- return new ClientTLSValidationParameters();
+ if (criteria != null) {
+ Constraint.isNotNull(criteria.get(ClientTLSValidationConfigurationCriterion.class), "Criterion was null");
+ return new ClientTLSValidationParameters();
+ }
+
+ return null;
}
}
diff --git a/opensaml-profile-impl/src/test/java/org/opensaml/profile/action/impl/PopulateDecryptionParametersTest.java b/opensaml-profile-impl/src/test/java/org/opensaml/profile/action/impl/PopulateDecryptionParametersTest.java
index 255712ff6..3213a121d 100644
--- a/opensaml-profile-impl/src/test/java/org/opensaml/profile/action/impl/PopulateDecryptionParametersTest.java
+++ b/opensaml-profile-impl/src/test/java/org/opensaml/profile/action/impl/PopulateDecryptionParametersTest.java
@@ -17,14 +17,17 @@
package org.opensaml.profile.action.impl;
-import java.util.Collections;
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
+import net.shibboleth.shared.collection.CollectionSupport;
import net.shibboleth.shared.component.ComponentInitializationException;
import net.shibboleth.shared.logic.Constraint;
import net.shibboleth.shared.resolver.CriteriaSet;
import net.shibboleth.shared.resolver.ResolverException;
import org.opensaml.core.testing.OpenSAMLInitBaseTestCase;
+import org.opensaml.messaging.context.MessageContext;
import org.opensaml.profile.action.EventIds;
import org.opensaml.profile.context.ProfileRequestContext;
import org.opensaml.profile.testing.ActionTestingSupport;
@@ -38,6 +41,7 @@ import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
/** Unit test for {@link PopulateDecryptionParameters}. */
+ at SuppressWarnings("javadoc")
public class PopulateDecryptionParametersTest extends OpenSAMLInitBaseTestCase {
private ProfileRequestContext prc;
@@ -78,8 +82,12 @@ public class PopulateDecryptionParametersTest extends OpenSAMLInitBaseTestCase {
action.execute(prc);
ActionTestingSupport.assertProceedEvent(prc);
- Assert.assertNotNull(prc.getInboundMessageContext().getSubcontext(
- SecurityParametersContext.class).getDecryptionParameters());
+
+ final MessageContext mc = prc.getInboundMessageContext();
+ assert mc != null;
+ final SecurityParametersContext ctx = mc.getSubcontext(SecurityParametersContext.class);
+ assert ctx != null;
+ Assert.assertNotNull(ctx.getDecryptionParameters());
}
private class MockResolver implements DecryptionParametersResolver {
@@ -91,20 +99,22 @@ public class PopulateDecryptionParametersTest extends OpenSAMLInitBaseTestCase {
}
/** {@inheritDoc} */
- @Override
- public Iterable<DecryptionParameters> resolve(CriteriaSet criteria) throws ResolverException {
- return Collections.singletonList(resolveSingle(criteria));
+ @Nonnull public Iterable<DecryptionParameters> resolve(@Nullable final CriteriaSet criteria) throws ResolverException {
+ return CollectionSupport.singletonList(Constraint.isNotNull(resolveSingle(criteria), "Parameters were null"));
}
/** {@inheritDoc} */
- @Override
- public DecryptionParameters resolveSingle(CriteriaSet criteria) throws ResolverException {
+ @Nullable public DecryptionParameters resolveSingle(@Nullable CriteriaSet criteria) throws ResolverException {
if (throwException) {
throw new ResolverException();
}
- Constraint.isNotNull(criteria.get(DecryptionConfigurationCriterion.class), "Criterion was null");
- return new DecryptionParameters();
+ if (criteria != null) {
+ Constraint.isNotNull(criteria.get(DecryptionConfigurationCriterion.class), "Criterion was null");
+ return new DecryptionParameters();
+ }
+
+ return null;
}
}
diff --git a/opensaml-profile-impl/src/test/java/org/opensaml/profile/action/impl/PopulateSignatureValidationParametersTest.java b/opensaml-profile-impl/src/test/java/org/opensaml/profile/action/impl/PopulateSignatureValidationParametersTest.java
index 030748104..11dd15edd 100644
--- a/opensaml-profile-impl/src/test/java/org/opensaml/profile/action/impl/PopulateSignatureValidationParametersTest.java
+++ b/opensaml-profile-impl/src/test/java/org/opensaml/profile/action/impl/PopulateSignatureValidationParametersTest.java
@@ -17,14 +17,17 @@
package org.opensaml.profile.action.impl;
-import java.util.Collections;
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
+import net.shibboleth.shared.collection.CollectionSupport;
import net.shibboleth.shared.component.ComponentInitializationException;
import net.shibboleth.shared.logic.Constraint;
import net.shibboleth.shared.resolver.CriteriaSet;
import net.shibboleth.shared.resolver.ResolverException;
import org.opensaml.core.testing.OpenSAMLInitBaseTestCase;
+import org.opensaml.messaging.context.MessageContext;
import org.opensaml.profile.action.EventIds;
import org.opensaml.profile.context.ProfileRequestContext;
import org.opensaml.profile.testing.ActionTestingSupport;
@@ -38,6 +41,7 @@ import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
/** Unit test for {@link PopulateSignatureValidationParameters}. */
+ at SuppressWarnings("javadoc")
public class PopulateSignatureValidationParametersTest extends OpenSAMLInitBaseTestCase {
private ProfileRequestContext prc;
@@ -78,8 +82,12 @@ public class PopulateSignatureValidationParametersTest extends OpenSAMLInitBaseT
action.execute(prc);
ActionTestingSupport.assertProceedEvent(prc);
- Assert.assertNotNull(prc.getInboundMessageContext().getSubcontext(
- SecurityParametersContext.class).getSignatureValidationParameters());
+
+ final MessageContext mc = prc.getInboundMessageContext();
+ assert mc != null;
+ final SecurityParametersContext ctx = mc.getSubcontext(SecurityParametersContext.class);
+ assert ctx != null;
+ Assert.assertNotNull(ctx.getSignatureValidationParameters());
}
private class MockResolver implements SignatureValidationParametersResolver {
@@ -91,20 +99,22 @@ public class PopulateSignatureValidationParametersTest extends OpenSAMLInitBaseT
}
/** {@inheritDoc} */
- @Override
- public Iterable<SignatureValidationParameters> resolve(CriteriaSet criteria) throws ResolverException {
- return Collections.singletonList(resolveSingle(criteria));
+ @Nonnull public Iterable<SignatureValidationParameters> resolve(@Nullable final CriteriaSet criteria) throws ResolverException {
+ return CollectionSupport.singletonList(Constraint.isNotNull(resolveSingle(criteria), "Parameters were null"));
}
/** {@inheritDoc} */
- @Override
- public SignatureValidationParameters resolveSingle(CriteriaSet criteria) throws ResolverException {
+ @Nullable public SignatureValidationParameters resolveSingle(@Nullable CriteriaSet criteria) throws ResolverException {
if (throwException) {
throw new ResolverException();
}
- Constraint.isNotNull(criteria.get(SignatureValidationConfigurationCriterion.class), "Criterion was null");
- return new SignatureValidationParameters();
+ if (criteria != null) {
+ Constraint.isNotNull(criteria.get(SignatureValidationConfigurationCriterion.class), "Criterion was null");
+ return new SignatureValidationParameters();
+ }
+
+ return null;
}
}
diff --git a/opensaml-profile-impl/src/test/java/org/opensaml/profile/action/impl/SetProfileIdTest.java b/opensaml-profile-impl/src/test/java/org/opensaml/profile/action/impl/SetProfileIdTest.java
index 2c2698783..dce05fa0b 100644
--- a/opensaml-profile-impl/src/test/java/org/opensaml/profile/action/impl/SetProfileIdTest.java
+++ b/opensaml-profile-impl/src/test/java/org/opensaml/profile/action/impl/SetProfileIdTest.java
@@ -24,22 +24,13 @@ import org.testng.annotations.Test;
import net.shibboleth.shared.logic.ConstraintViolationException;
-/**
- *
- */
+ at SuppressWarnings("javadoc")
public class SetProfileIdTest {
@Test
public void testInstantiation() {
new SetProfileId("foo");
- try {
- new SetProfileId(null);
- Assert.fail();
- } catch (ConstraintViolationException e) {
- // expected this
- }
-
try {
new SetProfileId(" ");
Assert.fail();
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the commits
mailing list