This is an automated email from the ASF dual-hosted git repository.

remm pushed a commit to branch 9.0.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git


The following commit(s) were added to refs/heads/9.0.x by this push:
     new 2f6e965b11 Simplify
2f6e965b11 is described below

commit 2f6e965b1142236407c34ea12cb94ad5d62b8745
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).
---
 .../core/PropertiesRoleMappingListener.java        | 31 +++-------------------
 1 file changed, 4 insertions(+), 27 deletions(-)

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

Reply via email to