[java-identity-provider] branch main updated: IDP-2015 - Review web.xml for improvements via code or annotations
Scott Cantor
cantor.2 at osu.edu
Mon Oct 3 14:25:13 UTC 2022
This is an automated email from the git hooks/post-receive script.
scantor pushed a commit to branch main
in repository java-identity-provider.
View the commit online:
http://git.shibboleth.net/view/?p=java-identity-provider.git;a=commit;h=3d0d8b628f15b6b1b24a80fc40433cfbec24cdc7
The following commit(s) were added to refs/heads/main by this push:
new 3d0d8b628 IDP-2015 - Review web.xml for improvements via code or annotations
3d0d8b628 is described below
commit 3d0d8b628f15b6b1b24a80fc40433cfbec24cdc7
Author: Scott Cantor <cantor.2 at osu.edu>
AuthorDate: Mon Oct 3 10:25:10 2022 -0400
IDP-2015 - Review web.xml for improvements via code or annotations
https://shibboleth.atlassian.net/browse/IDP-2015
Stub original MDC filter and replace with Spring-wired version.
---
.../shibboleth/idp/log/SLF4JMDCServletFilter.java | 81 ++--------------------
idp-conf-impl/pom.xml | 5 ++
.../idp/conf/impl}/SLF4JMDCServletFilter.java | 42 ++++++-----
.../resources/net/shibboleth/idp/conf/filters.xml | 5 ++
idp-conf/src/main/resources/conf/idp.properties | 10 ++-
idp-war/src/main/webapp/WEB-INF/web.xml | 13 ----
6 files changed, 44 insertions(+), 112 deletions(-)
diff --git a/idp-admin-api/src/main/java/net/shibboleth/idp/log/SLF4JMDCServletFilter.java b/idp-admin-api/src/main/java/net/shibboleth/idp/log/SLF4JMDCServletFilter.java
index fe1519437..ad6d4a110 100644
--- a/idp-admin-api/src/main/java/net/shibboleth/idp/log/SLF4JMDCServletFilter.java
+++ b/idp-admin-api/src/main/java/net/shibboleth/idp/log/SLF4JMDCServletFilter.java
@@ -17,82 +17,15 @@
package net.shibboleth.idp.log;
-import java.io.IOException;
-
-import javax.annotation.Nonnull;
-
-import org.slf4j.MDC;
-
-import jakarta.servlet.Filter;
-import jakarta.servlet.FilterChain;
-import jakarta.servlet.FilterConfig;
-import jakarta.servlet.ServletException;
-import jakarta.servlet.ServletRequest;
-import jakarta.servlet.ServletResponse;
-import jakarta.servlet.http.HttpServletRequest;
-import jakarta.servlet.http.HttpSession;
-import net.shibboleth.idp.Version;
-import net.shibboleth.shared.annotation.constraint.NotEmpty;
-import net.shibboleth.shared.servlet.HttpServletSupport;
+import net.shibboleth.shared.servlet.impl.StubbedFilter;
/**
- * Servlet filter that sets some interesting MDC attributes as the request comes in and clears the MDC as the response
- * is returned.
+ * Legacy stub.
+ *
+ * @deprecated
*/
-public class SLF4JMDCServletFilter implements Filter {
-
- /** MDC attribute name for host name of the server to which the current request was sent. */
- @Nonnull @NotEmpty public static final String SERVER_ADDRESS_MDC_ATTRIBUTE = "idp.server_hostname";
-
- /** MDC attribute name for port number to which the current request was sent. */
- @Nonnull @NotEmpty public static final String SERVER_PORT_MDC_ATTRIBUTE = "idp.server_port";
-
- /** MDC attribute name for client address. */
- @Nonnull @NotEmpty public static final String CLIENT_ADDRESS_MDC_ATTRIBUTE = "idp.remote_addr";
-
- /** MDC attribute name for container session ID. */
- @Nonnull @NotEmpty public static final String JSESSIONID_MDC_ATTRIBUTE = "idp.jsessionid";
-
- /** Whether to create a session if it doesn't already exist. */
- private boolean createSession;
-
- /** {@inheritDoc} */
- @Override
- public void doFilter(final ServletRequest request, final ServletResponse response, final FilterChain chain)
- throws IOException, ServletException {
- try {
- MDC.put(Version.MDC_ATTRIBUTE, Version.getVersion());
- MDC.put(CLIENT_ADDRESS_MDC_ATTRIBUTE, HttpServletSupport.getRemoteAddr(request));
- MDC.put(SERVER_ADDRESS_MDC_ATTRIBUTE, request.getServerName());
- MDC.put(SERVER_PORT_MDC_ATTRIBUTE, Integer.toString(request.getServerPort()));
- if (request instanceof HttpServletRequest) {
- final HttpSession session = ((HttpServletRequest) request).getSession(createSession);
- if (session != null) {
- MDC.put(JSESSIONID_MDC_ATTRIBUTE, session.getId());
- }
- }
-
- chain.doFilter(request, response);
- } finally {
- MDC.clear();
- }
- }
-
- /** {@inheritDoc} */
- @Override
- public void init(final FilterConfig filterConfig) throws ServletException {
- final String param = filterConfig.getInitParameter("createSession");
- if (param != null) {
- createSession = Boolean.valueOf(param);
- } else {
- createSession = true;
- }
- }
+ at Deprecated(since="5.0.0", forRemoval=true)
+public class SLF4JMDCServletFilter extends StubbedFilter {
- /** {@inheritDoc} */
- @Override
- public void destroy() {
- // nothing to do
- }
-}
+}
\ No newline at end of file
diff --git a/idp-conf-impl/pom.xml b/idp-conf-impl/pom.xml
index fee771f3d..edca98625 100644
--- a/idp-conf-impl/pom.xml
+++ b/idp-conf-impl/pom.xml
@@ -33,6 +33,11 @@
<version>${project.version}</version>
</dependency>
+ <dependency>
+ <groupId>${shib-shared.groupId}</groupId>
+ <artifactId>shib-networking-spring</artifactId>
+ </dependency>
+
<!-- Provided Dependencies -->
<dependency>
<groupId>jakarta.servlet</groupId>
diff --git a/idp-admin-api/src/main/java/net/shibboleth/idp/log/SLF4JMDCServletFilter.java b/idp-conf-impl/src/main/java/net/shibboleth/idp/conf/impl/SLF4JMDCServletFilter.java
similarity index 81%
copy from idp-admin-api/src/main/java/net/shibboleth/idp/log/SLF4JMDCServletFilter.java
copy to idp-conf-impl/src/main/java/net/shibboleth/idp/conf/impl/SLF4JMDCServletFilter.java
index fe1519437..a1cd74709 100644
--- a/idp-admin-api/src/main/java/net/shibboleth/idp/log/SLF4JMDCServletFilter.java
+++ b/idp-conf-impl/src/main/java/net/shibboleth/idp/conf/impl/SLF4JMDCServletFilter.java
@@ -15,7 +15,7 @@
* limitations under the License.
*/
-package net.shibboleth.idp.log;
+package net.shibboleth.idp.conf.impl;
import java.io.IOException;
@@ -23,9 +23,7 @@ import javax.annotation.Nonnull;
import org.slf4j.MDC;
-import jakarta.servlet.Filter;
import jakarta.servlet.FilterChain;
-import jakarta.servlet.FilterConfig;
import jakarta.servlet.ServletException;
import jakarta.servlet.ServletRequest;
import jakarta.servlet.ServletResponse;
@@ -33,14 +31,16 @@ import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpSession;
import net.shibboleth.idp.Version;
import net.shibboleth.shared.annotation.constraint.NotEmpty;
+import net.shibboleth.shared.servlet.AbstractConditionalFilter;
import net.shibboleth.shared.servlet.HttpServletSupport;
+import net.shibboleth.shared.spring.servlet.ChainableFilter;
/**
* Servlet filter that sets some interesting MDC attributes as the request comes in and clears the MDC as the response
* is returned.
*/
-public class SLF4JMDCServletFilter implements Filter {
+public class SLF4JMDCServletFilter extends AbstractConditionalFilter implements ChainableFilter {
/** MDC attribute name for host name of the server to which the current request was sent. */
@Nonnull @NotEmpty public static final String SERVER_ADDRESS_MDC_ATTRIBUTE = "idp.server_hostname";
@@ -56,10 +56,24 @@ public class SLF4JMDCServletFilter implements Filter {
/** Whether to create a session if it doesn't already exist. */
private boolean createSession;
+
+ /** Constructor. */
+ public SLF4JMDCServletFilter() {
+ createSession = true;
+ }
+ /**
+ * Sets whether to create a session if one does not exist.
+ *
+ * @param flag flag to set
+ */
+ public void setCreateSession(final boolean flag) {
+ createSession = flag;
+ }
+
/** {@inheritDoc} */
@Override
- public void doFilter(final ServletRequest request, final ServletResponse response, final FilterChain chain)
+ protected void runFilter(final ServletRequest request, final ServletResponse response, final FilterChain chain)
throws IOException, ServletException {
try {
MDC.put(Version.MDC_ATTRIBUTE, Version.getVersion());
@@ -79,20 +93,4 @@ public class SLF4JMDCServletFilter implements Filter {
}
}
- /** {@inheritDoc} */
- @Override
- public void init(final FilterConfig filterConfig) throws ServletException {
- final String param = filterConfig.getInitParameter("createSession");
- if (param != null) {
- createSession = Boolean.valueOf(param);
- } else {
- createSession = true;
- }
- }
-
- /** {@inheritDoc} */
- @Override
- public void destroy() {
- // nothing to do
- }
-}
+}
\ No newline at end of file
diff --git a/idp-conf-impl/src/main/resources/net/shibboleth/idp/conf/filters.xml b/idp-conf-impl/src/main/resources/net/shibboleth/idp/conf/filters.xml
index c3e0b3c47..09ee95083 100644
--- a/idp-conf-impl/src/main/resources/net/shibboleth/idp/conf/filters.xml
+++ b/idp-conf-impl/src/main/resources/net/shibboleth/idp/conf/filters.xml
@@ -59,6 +59,11 @@
p:encoding="UTF-8"
p:forceEncoding="true" />
+ <!-- Runs NEUTRAL, can be disabled if desired. -->
+ <bean class="net.shibboleth.idp.conf.impl.SLF4JMDCServletFilter"
+ p:activationCondition="%{idp.logging.MDC.enabled:true}"
+ p:createSession="%{idp.logging.MDC.createSession:true}" />
+
<!--
This was, Scott thinks, needed for client storage to work, but if it runs, it has to be after the
SameSite filter; i.e. it needs to execute on the response before that one does, so runs NEUTRAL.
diff --git a/idp-conf/src/main/resources/conf/idp.properties b/idp-conf/src/main/resources/conf/idp.properties
index f630f8e73..ceaac7563 100644
--- a/idp-conf/src/main/resources/conf/idp.properties
+++ b/idp-conf/src/main/resources/conf/idp.properties
@@ -46,6 +46,10 @@ idp.csrf.enabled = true
# Set to false to disable filter that forcibly applies UTF-8 encoding
#idp.encoding.forceUTF8 = true
+# Enable and control MDC filter
+#idp.logging.MDC.enabled = true
+#idp.logging.MDC.createSession = true
+
# Set the location of user-supplied web flow definitions
#idp.webflows = %{idp.home}/flows
@@ -63,9 +67,9 @@ idp.csrf.enabled = true
idp.sealer.storeResource = %{idp.home}/credentials/sealer.jks
idp.sealer.versionResource = %{idp.home}/credentials/sealer.kver
-# Settings for public/private signing and encryption key(s)
-# During decryption key rollover, point the ".2" properties at a second
-# keypair, uncomment in credentials.xml, then publish it in your metadata.
+# Settings for public/private signing and encryption key(s):
+# During decryption key rollover, point the ".2" properties at a second
+# keypair, uncomment in credentials.xml, then publish it in your metadata.
idp.signing.key = %{idp.home}/credentials/idp-signing.key
idp.signing.cert = %{idp.home}/credentials/idp-signing.crt
idp.encryption.key = %{idp.home}/credentials/idp-encryption.key
diff --git a/idp-war/src/main/webapp/WEB-INF/web.xml b/idp-war/src/main/webapp/WEB-INF/web.xml
index b4c58c01e..b155a8806 100644
--- a/idp-war/src/main/webapp/WEB-INF/web.xml
+++ b/idp-war/src/main/webapp/WEB-INF/web.xml
@@ -26,19 +26,6 @@
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
- <!-- Filters and filter mappings -->
-
- <!-- Manages logging MDC. -->
- <filter>
- <filter-name>SLF4JMDCServletFilter</filter-name>
- <filter-class>net.shibboleth.idp.log.SLF4JMDCServletFilter</filter-class>
- </filter>
-
- <filter-mapping>
- <filter-name>SLF4JMDCServletFilter</filter-name>
- <url-pattern>/*</url-pattern>
- </filter-mapping>
-
<!-- Servlets and servlet mappings -->
<servlet>
<servlet-name>idp</servlet-name>
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the commits
mailing list