[java-idp-oidc] branch main updated: JOIDC-76 - Facilitate custom response header settings
Henri Mikkonen
henri.mikkonen at iki.fi
Wed Mar 16 09:52:29 UTC 2022
This is an automated email from the git hooks/post-receive script.
hjmikkon pushed a commit to branch main
in repository java-idp-oidc.
View the commit online:
http://git.shibboleth.net/view/?p=java-idp-oidc.git;a=commit;h=375e08cea6ddb29651b3871ef17589fc90ef3482
The following commit(s) were added to refs/heads/main by this push:
new 375e08ce JOIDC-76 - Facilitate custom response header settings
375e08ce is described below
commit 375e08cea6ddb29651b3871ef17589fc90ef3482
Author: Henri Mikkonen <henri.mikkonen at iki.fi>
AuthorDate: Wed Mar 16 11:51:15 2022 +0200
JOIDC-76 - Facilitate custom response header settings
https://shibboleth.atlassian.net/browse/JOIDC-76
Added activation / mappings configuration via system properties.
---
.../RegisterFilterServletContextInitializer.java | 43 +++++++++++++++++++++-
1 file changed, 41 insertions(+), 2 deletions(-)
diff --git a/idp-oidc-extension-impl/src/main/java/net/shibboleth/idp/plugin/oidc/op/servlet/RegisterFilterServletContextInitializer.java b/idp-oidc-extension-impl/src/main/java/net/shibboleth/idp/plugin/oidc/op/servlet/RegisterFilterServletContextInitializer.java
index f9d8390e..8368d5cd 100644
--- a/idp-oidc-extension-impl/src/main/java/net/shibboleth/idp/plugin/oidc/op/servlet/RegisterFilterServletContextInitializer.java
+++ b/idp-oidc-extension-impl/src/main/java/net/shibboleth/idp/plugin/oidc/op/servlet/RegisterFilterServletContextInitializer.java
@@ -29,28 +29,67 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.filter.DelegatingFilterProxy;
+import net.shibboleth.utilities.java.support.primitive.StringSupport;
+
/**
* A {@link ServletContainerInitializer} implementation that registers dynamic response header filter for enabling
* configurable headers. The target bean name is {@link RegisterFilterServletContextInitializer#TARGET_BEAN_NAME}.
+ *
+ * The filter registration can be disabled by setting the system property
+ * {@link RegisterFilterServletContextInitializer#SYSTEM_PROPERTY_ACTIVATION} to <pre>disabled</pre>.
+ *
+ * The filter mappings can be configured via space-separated list on the system property
+ * {@link RegisterFilterServletContextInitializer#SYSTEM_PROPERTY_MAPPINGS}. By default the value is
+ * <pre>/profile/oidc/* /profile/oauth2/</pre>.
*/
public class RegisterFilterServletContextInitializer implements ServletContainerInitializer {
+ /** System property name for the activation flag of this class. */
+ public static final String SYSTEM_PROPERTY_ACTIVATION =
+ RegisterFilterServletContextInitializer.class.getCanonicalName();
+
+ /** System property name for configuring the filter mappings. */
+ public static final String SYSTEM_PROPERTY_MAPPINGS =
+ SYSTEM_PROPERTY_ACTIVATION + ".mappings";
+
/** The filter name for the dynamic response header filter for the OP's flows. */
public static final String FILTER_NAME_DYNAMIC_OIDC_RESPONSE_HEADER = "DynamicOidcResponseHeaderFilter";
/** The target bean name for the dynamic response header filter. */
public static final String TARGET_BEAN_NAME = "shibboleth.oidc.ResponseHeaderFilter";
+ /** The value for the filter mappings, if no custom configuration is set. */
+ public static final String DEFAULT_MAPPINGS = "/profile/oidc/* /profile/oauth2/*";
+
/** Class logger. */
@Nonnull private final Logger log = LoggerFactory.getLogger(RegisterFilterServletContextInitializer.class);
/** {@inheritDoc} */
@Override
public void onStartup(final Set<Class<?>> c, final ServletContext ctx) throws ServletException {
+ final String flag = System.getProperty(SYSTEM_PROPERTY_ACTIVATION);
+ log.debug("The value of the flag {}: {}", SYSTEM_PROPERTY_ACTIVATION, flag);
+ if ("disabled".equalsIgnoreCase(flag)) {
+ log.info("The filter registration is disabled according to the system properties");
+ return;
+ }
+
+ log.debug("Attempting to register filter {}", FILTER_NAME_DYNAMIC_OIDC_RESPONSE_HEADER);
final FilterRegistration.Dynamic headerFilter = ctx.addFilter(FILTER_NAME_DYNAMIC_OIDC_RESPONSE_HEADER,
DelegatingFilterProxy.class);
- headerFilter.addMappingForUrlPatterns(null, false, "/profile/oidc/*");
- headerFilter.addMappingForUrlPatterns(null, false, "/profile/oauth2/*");
+ final String mappings;
+ if (StringSupport.trimOrNull(System.getProperty(SYSTEM_PROPERTY_MAPPINGS)) == null) {
+ mappings = DEFAULT_MAPPINGS;
+ log.debug("Using default mappings: {}", DEFAULT_MAPPINGS);
+ } else {
+ mappings = System.getProperty(SYSTEM_PROPERTY_MAPPINGS);
+ log.debug("Using custom mappings: {}", mappings);
+ }
+
+ for (final String mapping : mappings.split(" ")) {
+ headerFilter.addMappingForUrlPatterns(null, false, mapping);
+ log.debug("Mapping added for the following pattern: {}", mapping);
+ }
headerFilter.setInitParameter("targetBeanName", TARGET_BEAN_NAME);
log.info("Registered the filter '{}'.", FILTER_NAME_DYNAMIC_OIDC_RESPONSE_HEADER);
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the commits
mailing list