[java-opensaml] branch main updated: OSJ-427: Simple signature verification fails to detect parameter ...
Brent Putman
putmanb at georgetown.edu
Thu Mar 20 00:22:36 UTC 2025
This is an automated email from the git hooks/post-receive script.
putmanb 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=3f3b8b505192c31366be6e5edc5851def3e1c9f6
The following commit(s) were added to refs/heads/main by this push:
new 3f3b8b505 OSJ-427: Simple signature verification fails to detect parameter ...
3f3b8b505 is described below
commit 3f3b8b505192c31366be6e5edc5851def3e1c9f6
Author: Brent Putman <putmanb at georgetown.edu>
AuthorDate: Wed Mar 19 20:17:15 2025 -0400
OSJ-427: Simple signature verification fails to detect parameter ...
ProfileAction impl for HttpServletRequest validation.
---
opensaml-profile-impl/pom.xml | 5 ++
.../action/impl/ValidateHttpServletRequest.java | 89 ++++++++++++++++++++++
.../impl/ValidateHttpServletRequestTest.java | 88 +++++++++++++++++++++
3 files changed, 182 insertions(+)
diff --git a/opensaml-profile-impl/pom.xml b/opensaml-profile-impl/pom.xml
index e947897bd..c2b9fb1b0 100644
--- a/opensaml-profile-impl/pom.xml
+++ b/opensaml-profile-impl/pom.xml
@@ -83,6 +83,11 @@
<version>${project.version}</version>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>${spring.groupId}</groupId>
+ <artifactId>spring-test</artifactId>
+ <scope>test</scope>
+ </dependency>
<!-- Managed Dependencies -->
</dependencies>
diff --git a/opensaml-profile-impl/src/main/java/org/opensaml/profile/action/impl/ValidateHttpServletRequest.java b/opensaml-profile-impl/src/main/java/org/opensaml/profile/action/impl/ValidateHttpServletRequest.java
new file mode 100644
index 000000000..edf7a74b9
--- /dev/null
+++ b/opensaml-profile-impl/src/main/java/org/opensaml/profile/action/impl/ValidateHttpServletRequest.java
@@ -0,0 +1,89 @@
+/*
+ * Licensed 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.profile.action.impl;
+
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
+
+import org.opensaml.profile.action.AbstractConditionalProfileAction;
+import org.opensaml.profile.action.ActionSupport;
+import org.opensaml.profile.action.EventIds;
+import org.opensaml.profile.context.ProfileRequestContext;
+import org.slf4j.Logger;
+
+import jakarta.servlet.ServletException;
+import net.shibboleth.shared.annotation.constraint.NonnullAfterInit;
+import net.shibboleth.shared.component.ComponentInitializationException;
+import net.shibboleth.shared.primitive.LoggerFactory;
+import net.shibboleth.shared.servlet.HttpServletRequestValidator;
+
+/**
+ * Profile action that validates an HTTP request via an instance of {@link HttpServletRequestValidator}.
+ */
+public class ValidateHttpServletRequest extends AbstractConditionalProfileAction {
+
+ /** Logger. */
+ @Nonnull private Logger log = LoggerFactory.getLogger(ValidateHttpServletRequest.class);
+
+ /** Request validator. */
+ @NonnullAfterInit private HttpServletRequestValidator validator;
+
+ /**
+ * Get the request validator.
+ *
+ * @return the validator
+ */
+ @NonnullAfterInit public HttpServletRequestValidator getValidator() {
+ return validator;
+ }
+
+ /**
+ * Set the request validator.
+ *
+ * @param newValidator the request validator
+ */
+ public void setValidator(final @Nullable HttpServletRequestValidator newValidator) {
+ checkSetterPreconditions();
+ validator = newValidator;
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ protected void doInitialize() throws ComponentInitializationException {
+ super.doInitialize();
+
+ if (getHttpServletRequest() == null) {
+ throw new ComponentInitializationException("HttpServletRequest was null");
+ }
+
+ if (getValidator() == null) {
+ throw new ComponentInitializationException("HttpServletRequestValidator was null");
+ }
+
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ protected void doExecute(@Nonnull final ProfileRequestContext profileContext) {
+ try {
+ getValidator().validate(getHttpServletRequest());
+ ActionSupport.buildProceedEvent(profileContext);
+ } catch (final ServletException e) {
+ log.warn("HttpServletRequest failed validation", e);
+ ActionSupport.buildEvent(profileContext, EventIds.INVALID_MESSAGE);
+ }
+ }
+
+}
diff --git a/opensaml-profile-impl/src/test/java/org/opensaml/profile/action/impl/ValidateHttpServletRequestTest.java b/opensaml-profile-impl/src/test/java/org/opensaml/profile/action/impl/ValidateHttpServletRequestTest.java
new file mode 100644
index 000000000..71c4dbbd9
--- /dev/null
+++ b/opensaml-profile-impl/src/test/java/org/opensaml/profile/action/impl/ValidateHttpServletRequestTest.java
@@ -0,0 +1,88 @@
+/*
+ * Licensed 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.profile.action.impl;
+
+import javax.annotation.Nonnull;
+
+import org.opensaml.profile.action.EventIds;
+import org.opensaml.profile.context.ProfileRequestContext;
+import org.opensaml.profile.testing.ActionTestingSupport;
+import org.springframework.mock.web.MockHttpServletRequest;
+import org.testng.annotations.Test;
+
+import jakarta.servlet.ServletException;
+import jakarta.servlet.http.HttpServletRequest;
+import net.shibboleth.shared.component.ComponentInitializationException;
+import net.shibboleth.shared.servlet.HttpServletRequestValidator;
+
+/**
+ * Unit test for {@link ValidateHttpServletRequest}.
+ */
+public class ValidateHttpServletRequestTest {
+
+ @Test(expectedExceptions = ComponentInitializationException.class)
+ public void nullValidator() throws Exception {
+ ValidateHttpServletRequest action = new ValidateHttpServletRequest();
+ action.initialize();
+ }
+
+ @Test
+ public void valid() throws Exception {
+ ValidateHttpServletRequest action = new ValidateHttpServletRequest();
+ action.setValidator(new MockValidator(true));
+ action.setHttpServletRequestSupplier(() -> new MockHttpServletRequest());
+ action.initialize();
+
+ ProfileRequestContext profileContext = new ProfileRequestContext();
+
+ action.execute(profileContext);
+
+ ActionTestingSupport.assertProceedEvent(profileContext);
+ }
+
+ @Test
+ public void invalid() throws Exception {
+ ValidateHttpServletRequest action = new ValidateHttpServletRequest();
+ action.setValidator(new MockValidator(false));
+ action.setHttpServletRequestSupplier(() -> new MockHttpServletRequest());
+ action.initialize();
+
+ ProfileRequestContext profileContext = new ProfileRequestContext();
+
+ action.execute(profileContext);
+
+ ActionTestingSupport.assertEvent(profileContext, EventIds.INVALID_MESSAGE);
+ }
+
+ public class MockValidator implements HttpServletRequestValidator {
+
+ private boolean valid;
+
+ public MockValidator(boolean result) {
+ valid = result ;
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public void validate(@Nonnull HttpServletRequest request) throws ServletException {
+ if (!valid) {
+ throw new ServletException("Request was invalid");
+ }
+
+ }
+
+ }
+
+}
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the commits
mailing list