This is an automated email from the ASF dual-hosted git repository.
kwin pushed a commit to branch master
in repository
https://gitbox.apache.org/repos/asf/sling-org-apache-sling-commons-crypto.git
The following commit(s) were added to refs/heads/master by this push:
new 4c99735 SLING-13344 Provider PasswordProvider based on OSGi
configuration values (#13)
4c99735 is described below
commit 4c99735f4af827d5d13ad2f3038a7e9bc0be7486
Author: Konrad Windszus <[email protected]>
AuthorDate: Mon Sep 28 14:53:09 2026 +0200
SLING-13344 Provider PasswordProvider based on OSGi configuration values
(#13)
This allows to leverage interpolation
(https://github.com/apache/felix-dev/blob/master/configadmin-plugins/interpolation/README.md)
for referencing passwords provided as secrets.
---
.../OsgiConfigurationPasswordProvider.java | 52 ++++++++++++++++++++++
...ConfigurationPasswordProviderConfiguration.java | 47 +++++++++++++++++++
2 files changed, 99 insertions(+)
diff --git
a/src/main/java/org/apache/sling/commons/crypto/internal/OsgiConfigurationPasswordProvider.java
b/src/main/java/org/apache/sling/commons/crypto/internal/OsgiConfigurationPasswordProvider.java
new file mode 100644
index 0000000..5492598
--- /dev/null
+++
b/src/main/java/org/apache/sling/commons/crypto/internal/OsgiConfigurationPasswordProvider.java
@@ -0,0 +1,52 @@
+/*
+ * 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.sling.commons.crypto.internal;
+
+import org.apache.sling.commons.crypto.PasswordProvider;
+import org.jetbrains.annotations.NotNull;
+import org.osgi.framework.Constants;
+import org.osgi.service.component.annotations.Activate;
+import org.osgi.service.component.annotations.Component;
+import org.osgi.service.metatype.annotations.Designate;
+
+@Component(
+ property = {
+ Constants.SERVICE_DESCRIPTION + "=Apache Sling Commons Crypto – OSGi
Configuration Password Provider",
+ Constants.SERVICE_VENDOR + "=The Apache Software Foundation"
+ }
+)
+@Designate(
+ ocd = OsgiConfigurationPasswordProviderConfiguration.class,
+ factory = true
+)
+public class OsgiConfigurationPasswordProvider implements PasswordProvider {
+
+ private final OsgiConfigurationPasswordProviderConfiguration configuration;
+
+ @Activate
+ public OsgiConfigurationPasswordProvider(final
OsgiConfigurationPasswordProviderConfiguration configuration) {
+ this.configuration = configuration;
+ }
+
+ @Override
+ public char @NotNull [] getPassword() {
+ return configuration._password().toCharArray();
+ }
+
+}
diff --git
a/src/main/java/org/apache/sling/commons/crypto/internal/OsgiConfigurationPasswordProviderConfiguration.java
b/src/main/java/org/apache/sling/commons/crypto/internal/OsgiConfigurationPasswordProviderConfiguration.java
new file mode 100644
index 0000000..d0188d8
--- /dev/null
+++
b/src/main/java/org/apache/sling/commons/crypto/internal/OsgiConfigurationPasswordProviderConfiguration.java
@@ -0,0 +1,47 @@
+/*
+ * 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.sling.commons.crypto.internal;
+
+import org.osgi.service.metatype.annotations.AttributeDefinition;
+import org.osgi.service.metatype.annotations.AttributeType;
+import org.osgi.service.metatype.annotations.ObjectClassDefinition;
+
+@ObjectClassDefinition(
+ name = "Apache Sling Commons Crypto OSGi Configuration Password Provider",
+ description = "Provides passwords from OSGi configurations."
+)
+@interface OsgiConfigurationPasswordProviderConfiguration {
+
+ @AttributeDefinition(
+ name = "Names",
+ description = "Names of this service",
+ required = false
+ )
+ String[] names() default {};
+
+ @AttributeDefinition(
+ type = AttributeType.PASSWORD,
+ name = "Password",
+ description = "The actual password. For security reasons only use with
interpolation to reference external values via pattern \"$[secret:...]\" as
outlined in
https://github.com/apache/felix-dev/blob/master/configadmin-plugins/interpolation/README.md,
e.g. \"$[secret:sling.crypto.password]\"."
+ )
+ String _password();
+
+ String webconsole_configurationFactory_nameHint() default "{names}";
+
+}