The secret provider is configured in the OpenCms configuration file WEB-INF/config/opencms-system.xml
Use the <secret-store> element below <subscription-manager>:
The OpenCms Secret Provider is used to securely store sensitive configuration data such as API keys, passwords, or access tokens. These secrets can be accessed by templates, Java code, or OpenCms internals (e.g., integrations with external systems).
Secrets are stored as key-value pairs in a file on the server’s real file system. Optionally, all values can be encrypted using a password with strong AES encryption.
The secret provider is configured in the OpenCms configuration file WEB-INF/config/opencms-system.xml
Use the <secret-store> element below <subscription-manager>:
<secret-store class="org.opencms.security.CmsRfsSecretStore">
<param name="path">/etc/secrets.properties</param>
<param name="password">...</param>
</secret-store>org.opencms.security.CmsRfsSecretStore is supported/etc/secrets.properties)Secrets can be accessed via the OpenCms singleton:
String value = OpenCms.getSecretProvider().getSecret("secret-key");
If the key does not exist, null is returned.
The helper class org.opencms.util.CmsSecretUtil provides convenient access:
CmsSecretUtil.getSecret("secret-key"); CmsSecretUtil.getSecretForUri("secret-key", CmsObject); CmsSecretUtil.getSecretForUri("secret-key", CmsObject, "/vfs/root/path/");You can access the secrets via the standard context bean:
${cms.getSecretForUri("secret-key")}
The method getSecretForUri allows resolving secrets dynamically based on the current request URI. This is useful when different subsites or sections require different credentials (e.g., API keys per site).
Given a secret-key, OpenCms resolves the secret as follows:
<secret-key>.<vfs-root-path><secret-key>nullmyapikey=test-secret-global
myapikey./sites/default=test-secret-default
myapikey./sites/default/mercury-demo-de=test-secret-de