This is an automated email from the ASF dual-hosted git repository. markt pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/master by this push: new 8f83475 The '$' in the class name of Digester$EnvironmentPropertySource is no… (#244) 8f83475 is described below commit 8f83475ea84e95fab3f6a54235a40f69053a7152 Author: Bernd Bohmann <bom...@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 | 25 ++----- .../util/digester/EnvironmentPropertySource.java | 76 ++++++++++++++++++++++ webapps/docs/changelog.xml | 4 ++ webapps/docs/config/systemprops.xml | 2 +- 4 files changed, 88 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..dc60837 100644 --- a/java/org/apache/tomcat/util/digester/Digester.java +++ b/java/org/apache/tomcat/util/digester/Digester.java @@ -145,24 +145,13 @@ 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. + * @see org.apache.tomcat.util.digester.EnvironmentPropertySource + * + */ + 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..e7948ce --- /dev/null +++ b/java/org/apache/tomcat/util/digester/EnvironmentPropertySource.java @@ -0,0 +1,76 @@ +/* + * 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 ebe4117..7a91894 100644 --- a/webapps/docs/changelog.xml +++ b/webapps/docs/changelog.xml @@ -164,6 +164,10 @@ <fix> Missing store config attributes for Resources elements. (remm) </fix> + <scode> + Rename <code>org.apache.tomcat.util.digester.Digester$EnvironmentPropertySource</code> to + <code>org.apache.tomcat.util.digester.EnvironmentPropertySource</code>. Old class is still available. + </scode> </changelog> </subsection> <subsection name="Coyote"> diff --git a/webapps/docs/config/systemprops.xml b/webapps/docs/config/systemprops.xml index 06623c8..4da50f9 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-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org