From d0849dcdf78ff1d0615e6844e4b002c4a4a9ee47 Mon Sep 17 00:00:00 2001
From: Gareth Evans Usage example: Property replacement from the specified property source on the JVM
system properties can also be done using the
+ * $SERVICE_BINDING_ROOT/
+ * /custom-certificate/
+ * /keyFile
+ * /file
+ * /chainFile
+ *
+ *
+ * {@code
+ *
+ *
+ * How to configure:
+ *
+ * {@code
+ * echo "org.apache.tomcat.util.digester.PROPERTY_SOURCE=org.apache.tomcat.util.digester.ServiceBindingPropertySource" >> conf/catalina.properties}
+ *
+ * or add this to {@code CATALINA_OPTS}
+ *
+ *
+ * {@code
+ * -Dorg.apache.tomcat.util.digester.PROPERTY_SOURCE=org.apache.tomcat.util.digester.ServiceBindingPropertySource}
+ *
+ *
+ * NOTE: When configured the PropertySource for resolving expressions
+ * from system properties is still active.
+ *
+ * @see Digester
+ *
+ * @see Tomcat Configuration Reference System Properties
+ */
+public class ServiceBindingPropertySource implements IntrospectionUtils.SecurePropertySource {
+
+ private static final String SERVICE_BINDING_ROOT_ENV_VAR = "SERVICE_BINDING_ROOT";
+
+ @Override
+ public String getProperty(String key) {
+ return null;
+ }
+
+ @Override
+ public String getProperty(String key, ClassLoader classLoader) {
+ // can we determine the service binding root
+ if (classLoader instanceof PermissionCheck) {
+ Permission p = new RuntimePermission("getenv." + SERVICE_BINDING_ROOT_ENV_VAR, null);
+ if (!((PermissionCheck) classLoader).check(p)) {
+ return null;
+ }
+ }
+
+ // get the root to search from
+ String serviceBindingRoot = System.getenv(SERVICE_BINDING_ROOT_ENV_VAR);
+ if (serviceBindingRoot == null) {
+ return null;
+ }
+
+ // we expect the keys to be in the format $SERVICE_BINDING_ROOT/REPLACE_SYSTEM_PROPERTIES system property.org.apache.tomcat.util.digester.ServiceBindingPropertySource
+ can be used to replace parameters from any Kubernetes service bindings
+ that follows the servicebinding.io specorg.apache.tomcat.util.digester.EnvironmentPropertySource
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.org.apache.tomcat.util.digester.SystemPropertySource
does replacement with system properties. It is always enabled,
- but can also be spefied as part of the property value.
Set this boolean system property to true to cause