This is an automated email from the ASF dual-hosted git repository. remm pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/main by this push: new 6391070013 Simplify 6391070013 is described below commit 6391070013753c73e2019badb55a3ee2a59b9946 Author: remm <r...@apache.org> AuthorDate: Thu Jun 29 15:54:17 2023 +0200 Simplify Also avoid falling back always to getSource().getResource since it will produce a misleading error when actually using the prefix (which looks like a uri). --- java/org/apache/catalina/Context.java | 2 ++ .../core/PropertiesRoleMappingListener.java | 31 +++------------------- 2 files changed, 6 insertions(+), 27 deletions(-) diff --git a/java/org/apache/catalina/Context.java b/java/org/apache/catalina/Context.java index 4be9f8f72c..243be85ea7 100644 --- a/java/org/apache/catalina/Context.java +++ b/java/org/apache/catalina/Context.java @@ -16,6 +16,7 @@ */ package org.apache.catalina; +import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; import java.net.URISyntaxException; @@ -1997,6 +1998,7 @@ public interface Context extends Container, ContextBind { stream.close(); } } + throw new FileNotFoundException(name); } return ConfigFileLoader.getSource().getResource(name); } diff --git a/java/org/apache/catalina/core/PropertiesRoleMappingListener.java b/java/org/apache/catalina/core/PropertiesRoleMappingListener.java index 10a5d7215c..00ddc5b4af 100644 --- a/java/org/apache/catalina/core/PropertiesRoleMappingListener.java +++ b/java/org/apache/catalina/core/PropertiesRoleMappingListener.java @@ -16,9 +16,7 @@ */ package org.apache.catalina.core; -import java.io.FileNotFoundException; import java.io.IOException; -import java.io.InputStream; import java.util.Map.Entry; import java.util.Objects; import java.util.Properties; @@ -30,6 +28,7 @@ import org.apache.catalina.LifecycleListener; import org.apache.juli.logging.Log; import org.apache.juli.logging.LogFactory; import org.apache.tomcat.util.file.ConfigFileLoader; +import org.apache.tomcat.util.file.ConfigurationSource.Resource; import org.apache.tomcat.util.res.StringManager; /** @@ -107,32 +106,10 @@ public class PropertiesRoleMappingListener implements LifecycleListener { log.warn(sm.getString("listener.notContext", event.getLifecycle().getClass().getSimpleName())); return; } - Context context = (Context) event.getLifecycle(); - - InputStream is; - if (roleMappingFile.startsWith(WEBAPP_PROTOCOL)) { - String path = roleMappingFile.substring(WEBAPP_PROTOCOL.length()); - is = context.getServletContext().getResourceAsStream(path); - } else { - try { - is = ConfigFileLoader.getSource().getResource(roleMappingFile).getInputStream(); - } catch (FileNotFoundException e1) { - is = null; - } catch (IOException e2) { - throw new IllegalStateException( - sm.getString("propertiesRoleMappingListener.roleMappingFileFail", roleMappingFile), e2); - } - } - - if (is == null) { - throw new IllegalStateException( - sm.getString("propertiesRoleMappingListener.roleMappingFileNotFound", roleMappingFile)); - } - Properties props = new Properties(); - - try (InputStream _is = is) { - props.load(_is); + Context context = (Context) event.getLifecycle(); + try (Resource resource = context.findConfigFileResource(roleMappingFile)) { + props.load(resource.getInputStream()); } catch (IOException e) { throw new IllegalStateException( sm.getString("propertiesRoleMappingListener.roleMappingFileFail", roleMappingFile), e); --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org