You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by re...@apache.org on 2023/06/29 14:08:22 UTC
[tomcat] branch 10.1.x updated: Simplify
This is an automated email from the ASF dual-hosted git repository.
remm pushed a commit to branch 10.1.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/10.1.x by this push:
new 437b57f30e Simplify
437b57f30e is described below
commit 437b57f30e999c813e09268d3435543c06afd361
Author: remm <re...@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-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org