[java-shib-shared] branch main updated: JSSH-33 - Spring converters run before property replacement

Scott Cantor cantor.2 at osu.edu
Tue Jun 13 17:54:34 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=52260fcb50d5b6ed230a9eec74360bc9ecc04a67

The following commit(s) were added to refs/heads/main by this push:
     new 52260fcb JSSH-33 - Spring converters run before property replacement
52260fcb is described below

commit 52260fcb50d5b6ed230a9eec74360bc9ecc04a67
Author: Scott Cantor <cantor.2 at osu.edu>
AuthorDate: Tue Jun 13 13:54:30 2023 -0400

    JSSH-33 - Spring converters run before property replacement
    
    https://shibboleth.atlassian.net/browse/JSSH-33
    
    Perform replacement step in StringToResource converter.
    Ensure context is injected when converter is installed programmatically.
---
 .../shared/spring/config/StringToResourceConverter.java  | 16 ++++++++++++----
 .../shared/spring/util/ApplicationContextBuilder.java    |  8 +++++---
 2 files changed, 17 insertions(+), 7 deletions(-)

diff --git a/shib-spring/src/main/java/net/shibboleth/shared/spring/config/StringToResourceConverter.java b/shib-spring/src/main/java/net/shibboleth/shared/spring/config/StringToResourceConverter.java
index 69373869..7a90f569 100644
--- a/shib-spring/src/main/java/net/shibboleth/shared/spring/config/StringToResourceConverter.java
+++ b/shib-spring/src/main/java/net/shibboleth/shared/spring/config/StringToResourceConverter.java
@@ -52,15 +52,23 @@ public class StringToResourceConverter implements Converter<String, Resource>, A
         if (loader == null) {
             loader = new PreferFileSystemResourceLoader();
         }
-        final Resource result = ResourceHelper.of(loader.getResource(source));
+
+        final String replaced;
+        if (applicationContext != null) {
+            replaced = applicationContext.getEnvironment().resolveRequiredPlaceholders(source);
+        } else {
+            replaced = source;
+        }
+        
+        final Resource result = ResourceHelper.of(loader.getResource(replaced));
         
-        if (source.endsWith(" ") || log.isDebugEnabled()) {
+        if (replaced.endsWith(" ") || log.isDebugEnabled()) {
             if (!result.exists()) {
                 if (log.isDebugEnabled()) {
-                    log.debug("Resource at '{}' does not exist", source);
+                    log.debug("Resource at '{}' does not exist", replaced);
                 }
                 if (source.endsWith(" ")) {
-                    log.warn("Missing path '{}' ends with a space, check for stray characters", source);
+                    log.warn("Missing path '{}' ends with a space, check for stray characters", replaced);
                 }
             }
         }
diff --git a/shib-spring/src/main/java/net/shibboleth/shared/spring/util/ApplicationContextBuilder.java b/shib-spring/src/main/java/net/shibboleth/shared/spring/util/ApplicationContextBuilder.java
index 05045b97..dfa10e6f 100644
--- a/shib-spring/src/main/java/net/shibboleth/shared/spring/util/ApplicationContextBuilder.java
+++ b/shib-spring/src/main/java/net/shibboleth/shared/spring/util/ApplicationContextBuilder.java
@@ -344,13 +344,15 @@ public class ApplicationContextBuilder {
         if (conversionService != null) {
             context.getBeanFactory().setConversionService(conversionService);
         } else {
+            final var resourceConverter = new StringToResourceConverter();
+            resourceConverter.setApplicationContext(context);
             final ConversionServiceFactoryBean service = new ConversionServiceFactoryBean();
-            service.setConverters(new HashSet<>(Arrays.asList(
+            service.setConverters(CollectionSupport.setOf(
+                    resourceConverter,
                     new StringToIPRangeConverter(),
                     new BooleanToPredicateConverter(),
                     new StringBooleanToPredicateConverter(),
-                    new StringToResourceConverter(),
-                    new StringToDurationConverter())));
+                    new StringToDurationConverter()));
             service.afterPropertiesSet();
             context.getBeanFactory().setConversionService(service.getObject());
         }

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the commits mailing list