[java-shib-shared] branch main updated: JSSH-8 - Servlet filter that implements its own filter-mapping layer
Scott Cantor
cantor.2 at osu.edu
Mon Oct 3 14:01:23 UTC 2022
This is an automated email from the git hooks/post-receive script.
scantor pushed a commit to branch main
in repository java-shib-shared.
View the commit online:
http://git.shibboleth.net/view/?p=java-shib-shared.git;a=commit;h=e1c8bb30d68d6ccf294544d1dabe00bf0df36771
The following commit(s) were added to refs/heads/main by this push:
new e1c8bb30 JSSH-8 - Servlet filter that implements its own filter-mapping layer
e1c8bb30 is described below
commit e1c8bb30d68d6ccf294544d1dabe00bf0df36771
Author: Scott Cantor <cantor.2 at osu.edu>
AuthorDate: Mon Oct 3 10:01:20 2022 -0400
JSSH-8 - Servlet filter that implements its own filter-mapping layer
https://shibboleth.atlassian.net/browse/JSSH-8
Add subclass of Spring CharacterEncodingFilter to allow conditional use.
---
shib-networking-spring/pom.xml | 13 ++--
.../servlet/impl/CharacterEncodingFilter.java | 85 ++++++++++++++++++++++
2 files changed, 93 insertions(+), 5 deletions(-)
diff --git a/shib-networking-spring/pom.xml b/shib-networking-spring/pom.xml
index 81366753..a0d269e6 100644
--- a/shib-networking-spring/pom.xml
+++ b/shib-networking-spring/pom.xml
@@ -50,6 +50,10 @@
<artifactId>httpclient-cache</artifactId>
</dependency>
+ <dependency>
+ <groupId>${spring.groupId}</groupId>
+ <artifactId>spring-context</artifactId>
+ </dependency>
<dependency>
<groupId>${spring.groupId}</groupId>
<artifactId>spring-core</artifactId>
@@ -58,6 +62,10 @@
<groupId>${spring.groupId}</groupId>
<artifactId>spring-beans</artifactId>
</dependency>
+ <dependency>
+ <groupId>${spring.groupId}</groupId>
+ <artifactId>spring-web</artifactId>
+ </dependency>
<!-- Provided dependencies -->
<dependency>
@@ -76,11 +84,6 @@
<scope>test</scope>
</dependency>
- <dependency>
- <groupId>${spring.groupId}</groupId>
- <artifactId>spring-context</artifactId>
- <scope>test</scope>
- </dependency>
<dependency>
<groupId>${spring.groupId}</groupId>
<artifactId>spring-test</artifactId>
diff --git a/shib-networking-spring/src/main/java/net/shibboleth/shared/spring/servlet/impl/CharacterEncodingFilter.java b/shib-networking-spring/src/main/java/net/shibboleth/shared/spring/servlet/impl/CharacterEncodingFilter.java
new file mode 100644
index 00000000..e6d6a29a
--- /dev/null
+++ b/shib-networking-spring/src/main/java/net/shibboleth/shared/spring/servlet/impl/CharacterEncodingFilter.java
@@ -0,0 +1,85 @@
+/*
+ * 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 net.shibboleth.shared.spring.servlet.impl;
+
+import java.io.IOException;
+import java.util.function.Predicate;
+
+import javax.annotation.Nonnull;
+
+import com.google.common.base.Predicates;
+
+import jakarta.servlet.FilterChain;
+import jakarta.servlet.ServletException;
+import jakarta.servlet.ServletRequest;
+import jakarta.servlet.http.HttpServletRequest;
+import jakarta.servlet.http.HttpServletResponse;
+import net.shibboleth.shared.logic.Constraint;
+import net.shibboleth.shared.spring.servlet.ChainableFilter;
+
+/**
+ * Adapts Spring filter into a chainable/conditional one.
+ */
+public class CharacterEncodingFilter extends org.springframework.web.filter.CharacterEncodingFilter implements ChainableFilter {
+
+ /** Whether filter should run or not. */
+ @Nonnull private Predicate<ServletRequest> activationCondition;
+
+ /** Constructor. */
+ public CharacterEncodingFilter() {
+ activationCondition = Predicates.alwaysTrue();
+ }
+
+ /**
+ * Get the condition to control activation of this filter.
+ *
+ * @return condition
+ */
+ @Nonnull public Predicate<ServletRequest> getActivationCondition() {
+ return activationCondition;
+ }
+
+ /**
+ * Set the condition to control activation of this filter.
+ *
+ * @param condition run condition
+ */
+ public void setActivationCondition(@Nonnull Predicate<ServletRequest> condition) {
+ activationCondition = Constraint.isNotNull(condition, "Run condition cannot be null");
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public int getOrder() {
+ return FilterOrder.NEUTRAL.getValue();
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ protected void doFilterInternal(final HttpServletRequest request, final HttpServletResponse response,
+ final FilterChain filterChain) throws ServletException, IOException {
+
+ if (!activationCondition.test(request)) {
+ filterChain.doFilter(request, response);
+ return;
+ }
+
+ super.doFilterInternal(request, response, filterChain);
+ }
+
+}
\ 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