[java-plugin-shibd] branch main updated: JSHIBDSAML-4 - Redo consumer flow based on new request validator API
Scott Cantor
cantor.2 at osu.edu
Mon Apr 7 19:21:09 UTC 2025
This is an automated email from the git hooks/post-receive script.
scantor pushed a commit to branch main
in repository java-plugin-shibd.
View the commit online:
http://git.shibboleth.net/view/?p=java-plugin-shibd.git;a=commit;h=39446123251000861464a44f2518abc11298db6d
The following commit(s) were added to refs/heads/main by this push:
new 3944612 JSHIBDSAML-4 - Redo consumer flow based on new request validator API
3944612 is described below
commit 39446123251000861464a44f2518abc11298db6d
Author: Scott Cantor <cantor.2 at osu.edu>
AuthorDate: Mon Apr 7 15:20:45 2025 -0400
JSHIBDSAML-4 - Redo consumer flow based on new request validator API
https://shibboleth.atlassian.net/browse/JSHIBDSAML-4
Revise original predicate to leverage new API.
---
.../context/logic/HttpSeevletRequestPredicate.java | 146 ---------------------
.../context/logic/HttpServletRequestPredicate.java | 94 +++++++++++++
2 files changed, 94 insertions(+), 146 deletions(-)
diff --git a/sp-server-api/src/main/java/net/shibboleth/sp/profile/context/logic/HttpSeevletRequestPredicate.java b/sp-server-api/src/main/java/net/shibboleth/sp/profile/context/logic/HttpSeevletRequestPredicate.java
deleted file mode 100644
index a3cda6d..0000000
--- a/sp-server-api/src/main/java/net/shibboleth/sp/profile/context/logic/HttpSeevletRequestPredicate.java
+++ /dev/null
@@ -1,146 +0,0 @@
-/*
- * 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 net.shibboleth.sp.profile.context.logic;
-
-import java.util.Collection;
-import java.util.Set;
-import java.util.function.Predicate;
-
-import javax.annotation.Nonnull;
-
-import org.opensaml.profile.context.ProfileRequestContext;
-import org.slf4j.Logger;
-
-import io.micrometer.common.lang.Nullable;
-import jakarta.servlet.http.HttpServletRequest;
-import net.shibboleth.shared.collection.CollectionSupport;
-import net.shibboleth.shared.primitive.LoggerFactory;
-import net.shibboleth.shared.primitive.NonnullSupplier;
-
-/**
- * A predicate that supports configurable evaluation of servlet request state to
- * produce a result.
- */
-public class HttpSeevletRequestPredicate implements Predicate<ProfileRequestContext> {
-
- /** Class logger. */
- @Nonnull private Logger log = LoggerFactory.getLogger(HttpSeevletRequestPredicate.class);
-
- /** Request supplier. */
- @Nullable private NonnullSupplier<HttpServletRequest> httpServletRequestSupplier;
-
- /** HTTP methods supported. */
- @Nonnull private Set<String> allowedMethods;
-
- /** Required content types. */
- @Nonnull private Set<String> allowedContentTypes;
-
- /** Whether an absent content type is allowed. */
- private boolean allowNullContentType;
-
- /** Required parameters. */
- @Nonnull private Set<String> requiredParameters;
-
- /** Constructor. */
- public HttpSeevletRequestPredicate() {
- allowedMethods = CollectionSupport.emptySet();
- allowedContentTypes = CollectionSupport.emptySet();
- requiredParameters = CollectionSupport.emptySet();
- }
-
- /**
- * Sets the supplier for the {@link HttpServletRequest} to evaluate.
- *
- * @param supplier request supplier
- */
- public void setHttpServletRequestSupplier(@Nullable final NonnullSupplier<HttpServletRequest> supplier) {
- httpServletRequestSupplier = supplier;
- }
-
- /**
- * Sets the allowed HTTP methods.
- *
- * @param methods allowed methods
- */
- public void setAllowedMethods(@Nonnull final Collection<String> methods) {
- allowedMethods = CollectionSupport.copyToSet(methods);
- }
-
- /**
- * Sets the allowed content types.
- *
- * @param types allowed content types
- */
- public void setAllowedContentTypes(@Nonnull final Collection<String> types) {
- allowedContentTypes = CollectionSupport.copyToSet(types);
- }
-
- /**
- * Sets whether to allow an absent content type.
- *
- * <p>Defaults to false.</p>
- *
- * @param flag flag to set
- */
- public void setAllowNullContentType(final boolean flag) {
- allowNullContentType = flag;
- }
-
- /**
- * Sets the required HTTP parameters.
- *
- * @param params required parameters
- */
- public void setRequiredParameters(@Nonnull final Collection<String> params) {
- requiredParameters = CollectionSupport.copyToSet(params);
- }
-
- /** {@inheritDoc} */
- public boolean test(@Nullable final ProfileRequestContext input) {
-
- if (httpServletRequestSupplier == null) {
- return false;
- }
-
- final HttpServletRequest request = httpServletRequestSupplier.get();
-
- if (!allowedMethods.contains(request.getMethod())) {
- log.debug("Disallowed HTTP method: {}", request.getMethod());
- return false;
- }
-
- final String contentType = request.getContentType();
- if (contentType == null) {
- if (!allowNullContentType) {
- log.debug("Disallowd absent content type");
- return false;
- }
- } else if (!allowedContentTypes.contains(request.getContentType())) {
- log.debug("Disallowed content type: {}", request.getContentType());
- return false;
- }
-
- if (!requiredParameters.isEmpty()) {
- final var pmap = request.getParameterMap();
- if (pmap == null || !pmap.keySet().containsAll(requiredParameters)) {
- log.debug("Missing required parameter from among {}", requiredParameters);
- return false;
- }
- }
-
- return true;
- }
-
-}
\ No newline at end of file
diff --git a/sp-server-api/src/main/java/net/shibboleth/sp/profile/context/logic/HttpServletRequestPredicate.java b/sp-server-api/src/main/java/net/shibboleth/sp/profile/context/logic/HttpServletRequestPredicate.java
new file mode 100644
index 0000000..0b8dfb3
--- /dev/null
+++ b/sp-server-api/src/main/java/net/shibboleth/sp/profile/context/logic/HttpServletRequestPredicate.java
@@ -0,0 +1,94 @@
+/*
+ * 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 net.shibboleth.sp.profile.context.logic;
+
+import java.util.function.Predicate;
+
+import javax.annotation.Nonnull;
+
+import org.opensaml.profile.context.ProfileRequestContext;
+import org.slf4j.Logger;
+
+import io.micrometer.common.lang.Nullable;
+import jakarta.servlet.ServletException;
+import jakarta.servlet.http.HttpServletRequest;
+import net.shibboleth.shared.annotation.constraint.NonnullAfterInit;
+import net.shibboleth.shared.component.AbstractInitializableComponent;
+import net.shibboleth.shared.component.ComponentInitializationException;
+import net.shibboleth.shared.logic.Constraint;
+import net.shibboleth.shared.primitive.LoggerFactory;
+import net.shibboleth.shared.primitive.NonnullSupplier;
+import net.shibboleth.shared.servlet.HttpServletRequestValidator;
+
+/**
+ * A predicate that supports configurable evaluation of servlet request state to
+ * produce a result via the {@link HttpServletRequestValidator} interface.
+ */
+public class HttpServletRequestPredicate extends AbstractInitializableComponent
+ implements Predicate<ProfileRequestContext> {
+
+ /** Class logger. */
+ @Nonnull private Logger log = LoggerFactory.getLogger(HttpServletRequestPredicate.class);
+
+ /** Request supplier. */
+ @NonnullAfterInit private NonnullSupplier<HttpServletRequest> httpServletRequestSupplier;
+
+ /** Validator to use. */
+ @NonnullAfterInit private HttpServletRequestValidator requestValidator;
+
+ /**
+ * Sets the supplier for the {@link HttpServletRequest} to evaluate.
+ *
+ * @param supplier request supplier
+ */
+ public void setHttpServletRequestSupplier(@Nullable final NonnullSupplier<HttpServletRequest> supplier) {
+ httpServletRequestSupplier = supplier;
+ }
+
+ /**
+ * Sets the validator to apply.
+ *
+ * @param validator request validator
+ */
+ public void setHttpServletRequestValidator(@Nonnull final HttpServletRequestValidator validator) {
+ requestValidator = Constraint.isNotNull(validator, "HttpServletRequestValidator cannot be null");
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ protected void doInitialize() throws ComponentInitializationException {
+ super.doInitialize();
+
+ if (this.httpServletRequestSupplier == null) {
+ throw new ComponentInitializationException("HttpServletRequest supplier was null");
+ } else if (requestValidator == null) {
+ throw new ComponentInitializationException("HttpServletRequestValidator was null");
+ }
+ }
+
+ /** {@inheritDoc} */
+ public boolean test(@Nullable final ProfileRequestContext input) {
+
+ try {
+ requestValidator.validate(httpServletRequestSupplier.get());
+ } catch (final ServletException e) {
+ log.debug("Request failed validation: {}", e.getMessage());
+ return false;
+ }
+
+ return true;
+ }
+
+}
\ No newline at end of file
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the commits
mailing list