You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by ma...@apache.org on 2020/02/28 11:21:36 UTC

[tomcat] branch 9.0.x updated: The '$' in the class name of Digester$EnvironmentPropertySource is no… (#244)

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

markt 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 34bc98b  The '$' in the class name of Digester$EnvironmentPropertySource is no… (#244)
34bc98b is described below

commit 34bc98b0516b3209d78ff91f2a4b4eebd822cb05
Author: Bernd Bohmann <bo...@apache.org>
AuthorDate: Fri Feb 28 12:09:04 2020 +0100

    The '$' in the class name of Digester$EnvironmentPropertySource is no… (#244)
    
    The '$' in the class name of Digester$EnvironmentPropertySource is not really shell friendly for unix environments. The class should not a inner class.
---
 java/org/apache/tomcat/util/digester/Digester.java | 28 +++-----
 .../util/digester/EnvironmentPropertySource.java   | 78 ++++++++++++++++++++++
 webapps/docs/changelog.xml                         |  7 ++
 webapps/docs/config/systemprops.xml                |  2 +-
 4 files changed, 96 insertions(+), 19 deletions(-)

diff --git a/java/org/apache/tomcat/util/digester/Digester.java b/java/org/apache/tomcat/util/digester/Digester.java
index a7c1740..fcf32c7 100644
--- a/java/org/apache/tomcat/util/digester/Digester.java
+++ b/java/org/apache/tomcat/util/digester/Digester.java
@@ -145,24 +145,16 @@ public class Digester extends DefaultHandler2 {
         }
     }
 
-
-    public static class EnvironmentPropertySource implements IntrospectionUtils.SecurePropertySource {
-
-        @Override
-        public String getProperty(String key) {
-            return null;
-        }
-
-        @Override
-        public String getProperty(String key, ClassLoader classLoader) {
-            if (classLoader instanceof PermissionCheck) {
-                Permission p = new RuntimePermission("getenv." + key, null);
-                if (!((PermissionCheck) classLoader).check(p)) {
-                    return null;
-                }
-            }
-            return System.getenv(key);
-        }
+    /**
+     * A {@link org.apache.tomcat.util.IntrospectionUtils.SecurePropertySource}
+     * that uses environment variables to resolve expressions. Still available
+     * for backwards compatibility.
+     *
+     * @deprecated Use {@link org.apache.tomcat.util.digester.EnvironmentPropertySource}
+     *             This will be removed in Tomcat 10 onwards.
+     */
+    @Deprecated
+    public static class EnvironmentPropertySource extends org.apache.tomcat.util.digester.EnvironmentPropertySource {
     }
 
 
diff --git a/java/org/apache/tomcat/util/digester/EnvironmentPropertySource.java b/java/org/apache/tomcat/util/digester/EnvironmentPropertySource.java
new file mode 100644
index 0000000..6b4138c
--- /dev/null
+++ b/java/org/apache/tomcat/util/digester/EnvironmentPropertySource.java
@@ -0,0 +1,78 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.tomcat.util.digester;
+
+import java.security.Permission;
+
+import org.apache.tomcat.util.IntrospectionUtils;
+import org.apache.tomcat.util.security.PermissionCheck;
+
+/**
+ * A {@link org.apache.tomcat.util.IntrospectionUtils.SecurePropertySource}
+ * that uses environment variables to resolve expressions.
+ *
+ * <p><strong>Usage example:</strong></p>
+ *
+ * Configure the certificate with environment variables.
+ *
+ * <pre>
+ *   {@code
+ *     <SSLHostConfig>
+ *           <Certificate certificateKeyFile="${CERTIFICATE_KEY_FILE}"
+ *                        certificateFile="${CERTIFICATE_FILE}"
+ *                        certificateChainFile="${CERTIFICATE_CHAIN_FILE}"
+ *                        type="RSA" />
+ *     </SSLHostConfig> }
+ * </pre>
+ *
+ * How to configure:
+ * <pre>
+ * {@code
+ *   echo "org.apache.tomcat.util.digester.PROPERTY_SOURCE=org.apache.tomcat.util.digester.EnvironmentPropertySource" >> conf/catalina.properties}
+ * </pre>
+ * or add this to {@code CATALINA_OPTS}
+ *
+ * <pre>
+ * {@code
+ *   -Dorg.apache.tomcat.util.digester.PROPERTY_SOURCE=org.apache.tomcat.util.digester.EnvironmentPropertySource}
+ * </pre>
+ *
+ * <b>NOTE</b>: When configured the PropertySource for resolving expressions
+ *              from system properties is still active.
+ *
+ * @see Digester
+ *
+ * @see <a href="https://tomcat.apache.org/tomcat-9.0-doc/config/systemprops.html#Property_replacements">Tomcat Configuration Reference System Properties</a>
+ */
+public class EnvironmentPropertySource implements IntrospectionUtils.SecurePropertySource {
+
+    @Override
+    public String getProperty(String key) {
+        return null;
+    }
+
+    @Override
+    public String getProperty(String key, ClassLoader classLoader) {
+        if (classLoader instanceof PermissionCheck) {
+            Permission p = new RuntimePermission("getenv." + key, null);
+            if (!((PermissionCheck) classLoader).check(p)) {
+                return null;
+            }
+        }
+        return System.getenv(key);
+    }
+}
diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml
index 85be0e1..c195bec 100644
--- a/webapps/docs/changelog.xml
+++ b/webapps/docs/changelog.xml
@@ -72,6 +72,13 @@
         <bug>64166</bug>: Ensure that the names returned by
         <code>HttpServletResponse.getHeaderNames()</code> are unique. (markt)
       </fix>
+      <scode>
+        Rename <code>org.apache.tomcat.util.digester.Digester$EnvironmentPropertySource</code>
+        to
+        <code>org.apache.tomcat.util.digester.EnvironmentPropertySource</code>.
+        The old class is still available but deprecated. Patch provided by Bernd
+        Bohmann. (markt)
+      </scode>
     </changelog>
   </subsection>
   <subsection name="Coyote">
diff --git a/webapps/docs/config/systemprops.xml b/webapps/docs/config/systemprops.xml
index d49a67d..b4b57be 100644
--- a/webapps/docs/config/systemprops.xml
+++ b/webapps/docs/config/systemprops.xml
@@ -49,7 +49,7 @@
       <p>Property replacement from the specified property source on the JVM
          system properties can also be done using the
          <code>REPLACE_SYSTEM_PROPERTIES</code> system property.</p>
-      <p><code>org.apache.tomcat.util.digester.Digester$EnvironmentPropertySource</code>
+      <p><code>org.apache.tomcat.util.digester.EnvironmentPropertySource</code>
          can be used to replace parameters from the process' environment
          variables, e.g. injected ConfigMaps or Secret objects in container
          based systems like OpenShift or Kubernetes.</p>


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org