This is an automated email from the ASF dual-hosted git repository. kwin pushed a commit to branch feature/osgi-configuration-password-provider in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-commons-crypto.git
commit b1f10faeb9cf4ebad02058fa08c59f9d149c92fa Author: Konrad Windszus <[email protected]> AuthorDate: Sun Sep 13 20:49:50 2026 +0200 SLING-13344 Provider PasswordProvider based on OSGi configuration values 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 | 44 ++++++++++++++++++++ ...ConfigurationPasswordProviderConfiguration.java | 47 ++++++++++++++++++++++ 2 files changed, 91 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..aa34f9a --- /dev/null +++ b/src/main/java/org/apache/sling/commons/crypto/internal/OsgiConfigurationPasswordProvider.java @@ -0,0 +1,44 @@ +/* + * 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.service.component.annotations.Activate; +import org.osgi.service.metatype.annotations.Designate; + +@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..b5d8ee2 --- /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}"; + +}
