[java-shib-shared] branch main updated: IDP-1972 - Revisit deferred classnames for solving layering conflicts
Scott Cantor
cantor.2 at osu.edu
Thu Aug 3 14:38:12 UTC 2023
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=3b91974235d415772b916a5d33d42de8c896b195
The following commit(s) were added to refs/heads/main by this push:
new 3b919742 IDP-1972 - Revisit deferred classnames for solving layering conflicts
3b919742 is described below
commit 3b91974235d415772b916a5d33d42de8c896b195
Author: Scott Cantor <cantor.2 at osu.edu>
AuthorDate: Thu Aug 3 10:38:08 2023 -0400
IDP-1972 - Revisit deferred classnames for solving layering conflicts
https://shibboleth.atlassian.net/browse/IDP-1972
Load a Properties bag statically to expose custom settings to parsers.
---
.../custom/AbstractCustomBeanDefinitionParser.java | 57 +++++++++++++++++++++-
1 file changed, 55 insertions(+), 2 deletions(-)
diff --git a/shib-spring/src/main/java/net/shibboleth/shared/spring/custom/AbstractCustomBeanDefinitionParser.java b/shib-spring/src/main/java/net/shibboleth/shared/spring/custom/AbstractCustomBeanDefinitionParser.java
index 538c5e3a..be12028b 100644
--- a/shib-spring/src/main/java/net/shibboleth/shared/spring/custom/AbstractCustomBeanDefinitionParser.java
+++ b/shib-spring/src/main/java/net/shibboleth/shared/spring/custom/AbstractCustomBeanDefinitionParser.java
@@ -14,7 +14,12 @@
package net.shibboleth.shared.spring.custom;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Properties;
+
import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
import org.slf4j.Logger;
@@ -22,6 +27,7 @@ import org.springframework.beans.factory.config.BeanDefinitionHolder;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.beans.factory.xml.AbstractSingleBeanDefinitionParser;
+import net.shibboleth.shared.annotation.constraint.NotEmpty;
import net.shibboleth.shared.primitive.LoggerFactory;
/**
@@ -32,8 +38,16 @@ import net.shibboleth.shared.primitive.LoggerFactory;
*/
public class AbstractCustomBeanDefinitionParser extends AbstractSingleBeanDefinitionParser {
+ /**
+ * Location to look for {@link Properties} that may affect custom parsing.
+ */
+ @Nonnull @NotEmpty
+ public static final String CUSTOM_PARSER_PROPERTIES_LOCATION = "META-INF/net/shibboleth/spring/parser.properties";
+
+ @Nullable private static Properties customProperties;
+
/** Logger. */
- @Nonnull private final Logger log = LoggerFactory.getLogger(AbstractCustomBeanDefinitionParser.class);
+ @Nonnull private static final Logger LOG = LoggerFactory.getLogger(AbstractCustomBeanDefinitionParser.class);
/** {@inheritDoc}
* The override is to warn if there is an ID clash within the same context.
@@ -42,9 +56,48 @@ public class AbstractCustomBeanDefinitionParser extends AbstractSingleBeanDefini
@Nonnull final BeanDefinitionRegistry registry) {
if (registry.containsBeanDefinition(definition.getBeanName())) {
final String claz = definition.getBeanDefinition().getBeanClassName();
- log.warn("Duplicate Definition '{}' of type '{}'", definition.getBeanName(), claz);
+ LOG.warn("Duplicate Definition '{}' of type '{}'", definition.getBeanName(), claz);
}
super.registerBeanDefinition(definition, registry);
}
+ /**
+ * Get a custom parser property, or return the default value specified.
+ *
+ * @param name property name
+ * @param defaultValue default value
+ *
+ * @return the property value or the default if not set
+ *
+ * @since 9.0.0
+ */
+ @Nullable public static String getCustomProperty(@Nonnull final String name, @Nullable final String defaultValue) {
+
+ synchronized (AbstractCustomBeanDefinitionParser.class) {
+ if (customProperties == null) {
+ final Properties props = new Properties();
+ try (final InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream(
+ CUSTOM_PARSER_PROPERTIES_LOCATION)) {
+ // NOTE: in this invocation style via class loader, resource should NOT have a leading slash
+ // because all names are absolute. This is unlike Class.getResourceAsStream
+ // where a leading slash is required for absolute names.
+ if (is != null) {
+ props.load(is);
+ } else {
+ LOG.debug("No custom Spring parser configuration properties loaded from {}",
+ CUSTOM_PARSER_PROPERTIES_LOCATION);
+ }
+ } catch (final IOException e) {
+ LOG.warn("Problem attempting to load custom Spring parser configuration properties '"
+ + CUSTOM_PARSER_PROPERTIES_LOCATION + "' from classpath", e);
+ } finally {
+ customProperties = props;
+ }
+ }
+ }
+
+ assert customProperties != null;
+ return customProperties.getProperty(name, defaultValue);
+ }
+
}
\ 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