[java-plugin-shibd] branch main updated: Predicate usable as an activation condition for token consumer flows.
Scott Cantor
cantor.2 at osu.edu
Tue Aug 27 16:06:10 UTC 2024
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=238423aa75d916f226dd29692d6948e1f37b0a03
The following commit(s) were added to refs/heads/main by this push:
new 238423a Predicate usable as an activation condition for token consumer flows.
238423a is described below
commit 238423aa75d916f226dd29692d6948e1f37b0a03
Author: Scott Cantor <cantor.2 at osu.edu>
AuthorDate: Tue Aug 27 12:06:07 2024 -0400
Predicate usable as an activation condition for token consumer flows.
---
.../context/logic/HttpSeevletRequestPredicate.java | 126 +++++++++++++++++++++
.../sp/profile/context/logic/package-info.java | 18 +++
2 files changed, 144 insertions(+)
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
new file mode 100644
index 0000000..8c7d919
--- /dev/null
+++ b/sp-server-api/src/main/java/net/shibboleth/sp/profile/context/logic/HttpSeevletRequestPredicate.java
@@ -0,0 +1,126 @@
+/*
+ * 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;
+
+ /** 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 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;
+ }
+
+ 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/package-info.java b/sp-server-api/src/main/java/net/shibboleth/sp/profile/context/logic/package-info.java
new file mode 100644
index 0000000..7192b7a
--- /dev/null
+++ b/sp-server-api/src/main/java/net/shibboleth/sp/profile/context/logic/package-info.java
@@ -0,0 +1,18 @@
+/*
+ * 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.
+ */
+
+/**
+ * Predicates that evaluate profile context state.
+ */
+package net.shibboleth.sp.profile.context.logic;
\ 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