You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@karaf.apache.org by gn...@apache.org on 2014/03/24 17:32:13 UTC
[15/24] git commit: [KARAF-2833] Make jaas/config,
jaas/jasypt and jaas/modules independent of blueprint
[KARAF-2833] Make jaas/config, jaas/jasypt and jaas/modules independent of blueprint
Project: http://git-wip-us.apache.org/repos/asf/karaf/repo
Commit: http://git-wip-us.apache.org/repos/asf/karaf/commit/5e2f19c4
Tree: http://git-wip-us.apache.org/repos/asf/karaf/tree/5e2f19c4
Diff: http://git-wip-us.apache.org/repos/asf/karaf/diff/5e2f19c4
Branch: refs/heads/master
Commit: 5e2f19c48efcf6dc8bca2b71485d36f1e47c84bc
Parents: 64e7310
Author: Guillaume Nodet <gn...@gmail.com>
Authored: Fri Mar 21 18:27:00 2014 +0100
Committer: Guillaume Nodet <gn...@gmail.com>
Committed: Mon Mar 24 17:30:13 2014 +0100
----------------------------------------------------------------------
.../standard/src/main/feature/feature.xml | 9 +-
jaas/blueprint/config/pom.xml | 82 ++++++
.../blueprint/config/impl/NamespaceHandler.java | 177 +++++++++++++
.../resources/OSGI-INF/blueprint/karaf-jaas.xml | 36 +++
.../src/main/resources/OSGI-INF/bundle.info | 14 +
.../jaas/blueprint/config/karaf-jaas-1.0.0.xsd | 62 +++++
.../jaas/blueprint/config/karaf-jaas-1.1.0.xsd | 63 +++++
jaas/blueprint/jasypt/pom.xml | 146 +++++++++++
.../handler/EncryptablePropertyPlaceholder.java | 41 +++
.../jasypt/handler/NamespaceHandler.java | 173 +++++++++++++
.../OSGI-INF/blueprint/karaf-jaas-jasypt.xml | 30 +++
.../src/main/resources/OSGI-INF/bundle.info | 14 +
.../jasypt/handler/karaf-jasypt-1.0.0.xsd | 43 ++++
...tableConfigAdminPropertyPlaceholderTest.java | 257 +++++++++++++++++++
.../EncryptablePropertyPlaceholderTest.java | 228 ++++++++++++++++
.../jasypt/src/test/resources/log4j.properties | 34 +++
.../jasypt/handler/configadmin-test.xml | 41 +++
.../jaas/blueprint/jasypt/handler/test.xml | 45 ++++
jaas/blueprint/pom.xml | 41 +++
jaas/config/pom.xml | 14 +-
.../karaf/jaas/config/impl/Activator.java | 93 +++++++
.../jaas/config/impl/NamespaceHandler.java | 165 ------------
.../resources/OSGI-INF/blueprint/karaf-jaas.xml | 61 -----
.../karaf/jaas/config/karaf-jaas-1.0.0.xsd | 62 -----
.../karaf/jaas/config/karaf-jaas-1.1.0.xsd | 63 -----
jaas/jasypt/pom.xml | 25 +-
.../handler/EncryptablePropertyPlaceholder.java | 41 ---
.../jaas/jasypt/handler/NamespaceHandler.java | 173 -------------
.../karaf/jaas/jasypt/impl/Activator.java | 45 ++++
.../OSGI-INF/blueprint/karaf-jaas-jasypt.xml | 37 ---
.../jaas/jasypt/handler/karaf-jasypt-1.0.0.xsd | 43 ----
.../EncryptablePropertyPlaceholderTest.java | 228 ----------------
.../apache/karaf/jaas/jasypt/handler/test.xml | 45 ----
jaas/modules/pom.xml | 7 +-
.../karaf/jaas/modules/impl/Activator.java | 48 ++++
.../karaf/jaas/modules/impl/KarafRealm.java | 109 ++++++++
.../modules/properties/PropertiesConverter.java | 51 ----
.../OSGI-INF/blueprint/karaf-jaas-module.xml | 75 ------
.../properties/PropertiesConverterTest.java | 66 -----
jaas/pom.xml | 1 +
pom.xml | 10 +
41 files changed, 1865 insertions(+), 1133 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/karaf/blob/5e2f19c4/assemblies/features/standard/src/main/feature/feature.xml
----------------------------------------------------------------------
diff --git a/assemblies/features/standard/src/main/feature/feature.xml b/assemblies/features/standard/src/main/feature/feature.xml
index fc42bbd..6a71520 100644
--- a/assemblies/features/standard/src/main/feature/feature.xml
+++ b/assemblies/features/standard/src/main/feature/feature.xml
@@ -146,10 +146,13 @@
</feature>
<feature name="jaas" description="Provide JAAS support" version="${project.version}">
- <feature version="${project.version}">aries-blueprint</feature>
<bundle start-level="30" start="true">mvn:org.apache.karaf.jaas/org.apache.karaf.jaas.config/${project.version}</bundle>
<bundle start-level="30" start="true">mvn:org.apache.karaf.jaas/org.apache.karaf.jaas.modules/${project.version}</bundle>
<bundle start-level="30" start="true">mvn:org.apache.karaf.jaas/org.apache.karaf.jaas.command/${project.version}</bundle>
+ <conditional>
+ <condition>aries-blueprint</condition>
+ <bundle start-level="30" start="true">mvn:org.apache.karaf.jaas.blueprint/org.apache.karaf.jaas.blueprint.config/${project.version}</bundle>
+ </conditional>
</feature>
<feature name="log" description="Provide Log support" version="${project.version}">
@@ -282,6 +285,10 @@
<bundle dependency="true" start-level="30">mvn:commons-lang/commons-lang/${commons-lang.version}</bundle>
<bundle dependency="true" start-level="30">mvn:org.apache.servicemix.bundles/org.apache.servicemix.bundles.jasypt/${jasypt.bundle.version}</bundle>
<bundle start-level="30">mvn:org.apache.karaf.jaas/org.apache.karaf.jaas.jasypt/${project.version}</bundle>
+ <conditional>
+ <condition>aries-blueprint</condition>
+ <bundle start-level="30" start="true">mvn:org.apache.karaf.jaas.blueprint/org.apache.karaf.jaas.blueprint.jasypt/${project.version}</bundle>
+ </conditional>
</feature>
<feature name="scr" description="Declarative Service support" version="${project.version}" resolver="(obr)">
http://git-wip-us.apache.org/repos/asf/karaf/blob/5e2f19c4/jaas/blueprint/config/pom.xml
----------------------------------------------------------------------
diff --git a/jaas/blueprint/config/pom.xml b/jaas/blueprint/config/pom.xml
new file mode 100644
index 0000000..efb7664
--- /dev/null
+++ b/jaas/blueprint/config/pom.xml
@@ -0,0 +1,82 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+
+ <!--
+
+ 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.
+ -->
+
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.apache.karaf.jaas.blueprint</groupId>
+ <artifactId>blueprint</artifactId>
+ <version>3.1.0-SNAPSHOT</version>
+ <relativePath>../pom.xml</relativePath>
+ </parent>
+
+ <artifactId>org.apache.karaf.jaas.blueprint.config</artifactId>
+ <packaging>bundle</packaging>
+ <name>Apache Karaf :: JAAS :: Blueprint :: Config</name>
+ <description>This bundle provides a blueprint namespace handler for configuring JAAS</description>
+
+ <properties>
+ <appendedResourcesDirectory>${basedir}/../../etc/appended-resources</appendedResourcesDirectory>
+ </properties>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.osgi</groupId>
+ <artifactId>org.osgi.core</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.karaf.jaas</groupId>
+ <artifactId>org.apache.karaf.jaas.boot</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.karaf.jaas</groupId>
+ <artifactId>org.apache.karaf.jaas.config</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.aries.blueprint</groupId>
+ <artifactId>org.apache.aries.blueprint.core</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+ <configuration>
+ <instructions>
+ <Export-Package>
+ ${project.artifactId};version=${project.version}
+ </Export-Package>
+ <Import-Package>
+ !${project.artifactId},
+ *
+ </Import-Package>
+ </instructions>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+</project>
http://git-wip-us.apache.org/repos/asf/karaf/blob/5e2f19c4/jaas/blueprint/config/src/main/java/org/apache/karaf/jaas/blueprint/config/impl/NamespaceHandler.java
----------------------------------------------------------------------
diff --git a/jaas/blueprint/config/src/main/java/org/apache/karaf/jaas/blueprint/config/impl/NamespaceHandler.java b/jaas/blueprint/config/src/main/java/org/apache/karaf/jaas/blueprint/config/impl/NamespaceHandler.java
new file mode 100644
index 0000000..0da83ae
--- /dev/null
+++ b/jaas/blueprint/config/src/main/java/org/apache/karaf/jaas/blueprint/config/impl/NamespaceHandler.java
@@ -0,0 +1,177 @@
+/*
+ * 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.karaf.jaas.blueprint.config.impl;
+
+import java.net.URL;
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.Set;
+
+import org.apache.aries.blueprint.ParserContext;
+import org.apache.aries.blueprint.mutable.MutableBeanMetadata;
+import org.apache.aries.blueprint.mutable.MutableCollectionMetadata;
+import org.apache.aries.blueprint.mutable.MutableRefMetadata;
+import org.apache.aries.blueprint.mutable.MutableServiceMetadata;
+import org.apache.aries.blueprint.mutable.MutableValueMetadata;
+import org.apache.karaf.jaas.boot.ProxyLoginModule;
+import org.apache.karaf.jaas.config.JaasRealm;
+import org.apache.karaf.jaas.config.KeystoreInstance;
+import org.apache.karaf.jaas.config.impl.Config;
+import org.apache.karaf.jaas.config.impl.Module;
+import org.apache.karaf.jaas.config.impl.ResourceKeystoreInstance;
+import org.osgi.service.blueprint.container.ComponentDefinitionException;
+import org.osgi.service.blueprint.reflect.ComponentMetadata;
+import org.osgi.service.blueprint.reflect.Metadata;
+import org.osgi.service.blueprint.reflect.RefMetadata;
+import org.osgi.service.blueprint.reflect.ValueMetadata;
+import org.w3c.dom.CharacterData;
+import org.w3c.dom.Comment;
+import org.w3c.dom.Element;
+import org.w3c.dom.EntityReference;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+
+public class NamespaceHandler implements org.apache.aries.blueprint.NamespaceHandler {
+
+ public URL getSchemaLocation(String namespace) {
+ if ("http://karaf.apache.org/xmlns/jaas/v1.0.0".equals(namespace)) {
+ return getClass().getResource("/org/apache/karaf/jaas/blueprint/config/karaf-jaas-1.0.0.xsd");
+ } else {
+ return getClass().getResource("/org/apache/karaf/jaas/blueprint/config/karaf-jaas-1.1.0.xsd");
+ }
+ }
+
+ public Set<Class> getManagedClasses() {
+ return new HashSet<Class>(Arrays.asList(
+ Config.class,
+ ResourceKeystoreInstance.class
+ ));
+ }
+
+ public Metadata parse(Element element, ParserContext context) {
+ String name = element.getLocalName() != null ? element.getLocalName() : element.getNodeName();
+ if ("config".equals(name)) {
+ return parseConfig(element, context);
+ } else if ("keystore".equals(name)) {
+ return parseKeystore(element, context);
+ }
+ throw new ComponentDefinitionException("Bad xml syntax: unknown element '" + name + "'");
+ }
+
+ public ComponentMetadata decorate(Node node, ComponentMetadata component, ParserContext context) {
+ throw new ComponentDefinitionException("Bad xml syntax: node decoration is not supported");
+ }
+
+ public ComponentMetadata parseConfig(Element element, ParserContext context) {
+ MutableBeanMetadata bean = context.createMetadata(MutableBeanMetadata.class);
+ bean.setRuntimeClass(Config.class);
+ String name = element.getAttribute("name");
+ bean.addProperty("bundleContext", createRef(context, "blueprintBundleContext"));
+ bean.addProperty("name", createValue(context, name));
+ String rank = element.getAttribute("rank");
+ if (rank != null && rank.length() > 0) {
+ bean.addProperty("rank", createValue(context, rank));
+ }
+ NodeList childElements = element.getElementsByTagNameNS(element.getNamespaceURI(), "module");
+ if (childElements != null && childElements.getLength() > 0) {
+ MutableCollectionMetadata children = context.createMetadata(MutableCollectionMetadata.class);
+ for (int i = 0; i < childElements.getLength(); ++i) {
+ Element childElement = (Element) childElements.item(i);
+ MutableBeanMetadata md = context.createMetadata(MutableBeanMetadata.class);
+ md.setRuntimeClass(Module.class);
+ md.addProperty("className", createValue(context, childElement.getAttribute("className")));
+ if (childElement.getAttribute("name") != null) {
+ md.addProperty("name", createValue(context, childElement.getAttribute("name")));
+ }
+ if (childElement.getAttribute("flags") != null) {
+ md.addProperty("flags", createValue(context, childElement.getAttribute("flags")));
+ }
+ String options = getTextValue(childElement);
+ if (options != null && options.length() > 0) {
+ md.addProperty("options", createValue(context, options));
+ }
+ children.addValue(md);
+ }
+ bean.addProperty("modules", children);
+ }
+ // Publish Config
+ MutableServiceMetadata service = context.createMetadata(MutableServiceMetadata.class);
+ service.setId(name);
+ service.setServiceComponent(bean);
+ service.addInterface(JaasRealm.class.getName());
+ service.addServiceProperty(createValue(context, ProxyLoginModule.PROPERTY_MODULE), createValue(context, name));
+ return service;
+ }
+
+ public ComponentMetadata parseKeystore(Element element, ParserContext context) {
+ MutableBeanMetadata bean = context.createMetadata(MutableBeanMetadata.class);
+ bean.setRuntimeClass(ResourceKeystoreInstance.class);
+ // Parse name
+ String name = element.getAttribute("name");
+ bean.addProperty("name", createValue(context, name));
+ // Parse rank
+ String rank = element.getAttribute("rank");
+ if (rank != null && rank.length() > 0) {
+ bean.addProperty("rank", createValue(context, rank));
+ }
+ // Parse path
+ String path = element.getAttribute("path");
+ if (path != null && path.length() > 0) {
+ bean.addProperty("path", createValue(context, path));
+ }
+ // Parse keystorePassword
+ String keystorePassword = element.getAttribute("keystorePassword");
+ if (keystorePassword != null && keystorePassword.length() > 0) {
+ bean.addProperty("keystorePassword", createValue(context, keystorePassword));
+ }
+ // Parse keyPasswords
+ String keyPasswords = element.getAttribute("keyPasswords");
+ if (keyPasswords != null && keyPasswords.length() > 0) {
+ bean.addProperty("keyPasswords", createValue(context, keyPasswords));
+ }
+ // Publish Config
+ MutableServiceMetadata service = context.createMetadata(MutableServiceMetadata.class);
+ service.setId(name);
+ service.setServiceComponent(bean);
+ service.addInterface(KeystoreInstance.class.getName());
+ return service;
+ }
+
+ private ValueMetadata createValue(ParserContext context, String value) {
+ MutableValueMetadata v = context.createMetadata(MutableValueMetadata.class);
+ v.setStringValue(value);
+ return v;
+ }
+
+ private RefMetadata createRef(ParserContext context, String value) {
+ MutableRefMetadata r = context.createMetadata(MutableRefMetadata.class);
+ r.setComponentId(value);
+ return r;
+ }
+
+ private static String getTextValue(Element element) {
+ StringBuffer value = new StringBuffer();
+ NodeList nl = element.getChildNodes();
+ for (int i = 0; i < nl.getLength(); i++) {
+ Node item = nl.item(i);
+ if ((item instanceof CharacterData && !(item instanceof Comment)) || item instanceof EntityReference) {
+ value.append(item.getNodeValue());
+ }
+ }
+ return value.toString();
+ }
+}
http://git-wip-us.apache.org/repos/asf/karaf/blob/5e2f19c4/jaas/blueprint/config/src/main/resources/OSGI-INF/blueprint/karaf-jaas.xml
----------------------------------------------------------------------
diff --git a/jaas/blueprint/config/src/main/resources/OSGI-INF/blueprint/karaf-jaas.xml b/jaas/blueprint/config/src/main/resources/OSGI-INF/blueprint/karaf-jaas.xml
new file mode 100644
index 0000000..b605006
--- /dev/null
+++ b/jaas/blueprint/config/src/main/resources/OSGI-INF/blueprint/karaf-jaas.xml
@@ -0,0 +1,36 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ 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.
+
+-->
+<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0">
+
+ <bean id="namespaceHandler" class="org.apache.karaf.jaas.blueprint.config.impl.NamespaceHandler"/>
+
+ <service ref="namespaceHandler" interface="org.apache.aries.blueprint.NamespaceHandler">
+ <service-properties>
+ <entry key="osgi.service.blueprint.namespace" value="http://karaf.apache.org/xmlns/jaas/v1.0.0" />
+ </service-properties>
+ </service>
+
+ <service ref="namespaceHandler" interface="org.apache.aries.blueprint.NamespaceHandler">
+ <service-properties>
+ <entry key="osgi.service.blueprint.namespace" value="http://karaf.apache.org/xmlns/jaas/v1.1.0" />
+ </service-properties>
+ </service>
+
+</blueprint>
http://git-wip-us.apache.org/repos/asf/karaf/blob/5e2f19c4/jaas/blueprint/config/src/main/resources/OSGI-INF/bundle.info
----------------------------------------------------------------------
diff --git a/jaas/blueprint/config/src/main/resources/OSGI-INF/bundle.info b/jaas/blueprint/config/src/main/resources/OSGI-INF/bundle.info
new file mode 100644
index 0000000..6f57671
--- /dev/null
+++ b/jaas/blueprint/config/src/main/resources/OSGI-INF/bundle.info
@@ -0,0 +1,14 @@
+\u001B[1mSYNOPSIS\u001B[0m
+ ${project.name}
+
+ ${project.description}
+
+ Maven URL:
+ \u001B[33mmvn:${project.groupId}/${project.artifactId}/${project.version}\u001B[0m
+
+\u001B[1mDESCRIPTION\u001B[0m
+ A JAAS Namespace Handler for Blueprint
+
+\u001B[1mSEE ALSO\u001B[0m
+ \u001B[36mSecurity Framework\u001B[0m section of the Karaf Developer Guide.
+ \u001B[36mhttp://www.jasypt.org/\u001B[0m
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/karaf/blob/5e2f19c4/jaas/blueprint/config/src/main/resources/org/apache/karaf/jaas/blueprint/config/karaf-jaas-1.0.0.xsd
----------------------------------------------------------------------
diff --git a/jaas/blueprint/config/src/main/resources/org/apache/karaf/jaas/blueprint/config/karaf-jaas-1.0.0.xsd b/jaas/blueprint/config/src/main/resources/org/apache/karaf/jaas/blueprint/config/karaf-jaas-1.0.0.xsd
new file mode 100644
index 0000000..225665c
--- /dev/null
+++ b/jaas/blueprint/config/src/main/resources/org/apache/karaf/jaas/blueprint/config/karaf-jaas-1.0.0.xsd
@@ -0,0 +1,62 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ 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.
+
+-->
+<xs:schema elementFormDefault='qualified'
+ targetNamespace='http://karaf.apache.org/xmlns/jaas/v1.0.0'
+ xmlns:xs='http://www.w3.org/2001/XMLSchema'
+ xmlns:bp="http://www.osgi.org/xmlns/blueprint/v1.0.0"
+ xmlns:tns='http://karaf.apache.org/xmlns/jaas/v1.0.0'>
+
+ <xs:import namespace="http://www.osgi.org/xmlns/blueprint/v1.0.0"/>
+
+ <xs:element name="config">
+ <xs:complexType>
+ <xs:sequence>
+ <xs:element name="module" minOccurs="0" maxOccurs="unbounded">
+ <xs:complexType mixed="true">
+ <xs:attribute name="className" use="required" type="xs:string"/>
+ <xs:attribute name="flags" default="required">
+ <xs:simpleType>
+ <xs:restriction base="xs:NMTOKEN">
+ <xs:enumeration value="required"/>
+ <xs:enumeration value="requisite"/>
+ <xs:enumeration value="sufficient"/>
+ <xs:enumeration value="optional"/>
+ </xs:restriction>
+ </xs:simpleType>
+ </xs:attribute>
+ </xs:complexType>
+ </xs:element>
+ </xs:sequence>
+ <xs:attribute name="name" use="required" type="xs:string"/>
+ <xs:attribute name="rank" use="optional" default="0" type="xs:int"/>
+ </xs:complexType>
+ </xs:element>
+
+ <xs:element name="keystore">
+ <xs:complexType>
+ <xs:attribute name="name" use="required" type="xs:string"/>
+ <xs:attribute name="rank" use="optional" default="0" type="xs:int"/>
+ <xs:attribute name="path" use="required" type="xs:string"/>
+ <xs:attribute name="keystorePassword" use="optional" type="xs:string"/>
+ <xs:attribute name="keyPasswords" use="optional" type="xs:string"/>
+ </xs:complexType>
+ </xs:element>
+
+</xs:schema>
http://git-wip-us.apache.org/repos/asf/karaf/blob/5e2f19c4/jaas/blueprint/config/src/main/resources/org/apache/karaf/jaas/blueprint/config/karaf-jaas-1.1.0.xsd
----------------------------------------------------------------------
diff --git a/jaas/blueprint/config/src/main/resources/org/apache/karaf/jaas/blueprint/config/karaf-jaas-1.1.0.xsd b/jaas/blueprint/config/src/main/resources/org/apache/karaf/jaas/blueprint/config/karaf-jaas-1.1.0.xsd
new file mode 100644
index 0000000..f56b206
--- /dev/null
+++ b/jaas/blueprint/config/src/main/resources/org/apache/karaf/jaas/blueprint/config/karaf-jaas-1.1.0.xsd
@@ -0,0 +1,63 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ 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.
+
+-->
+<xs:schema elementFormDefault='qualified'
+ targetNamespace='http://karaf.apache.org/xmlns/jaas/v1.1.0'
+ xmlns:xs='http://www.w3.org/2001/XMLSchema'
+ xmlns:bp="http://www.osgi.org/xmlns/blueprint/v1.0.0"
+ xmlns:tns='http://karaf.apache.org/xmlns/jaas/v1.1.0'>
+
+ <xs:import namespace="http://www.osgi.org/xmlns/blueprint/v1.0.0"/>
+
+ <xs:element name="config">
+ <xs:complexType>
+ <xs:sequence>
+ <xs:element name="module" minOccurs="0" maxOccurs="unbounded">
+ <xs:complexType mixed="true">
+ <xs:attribute name="name" use="optional" type="xs:string"/>
+ <xs:attribute name="className" use="required" type="xs:string"/>
+ <xs:attribute name="flags" default="required">
+ <xs:simpleType>
+ <xs:restriction base="xs:NMTOKEN">
+ <xs:enumeration value="required"/>
+ <xs:enumeration value="requisite"/>
+ <xs:enumeration value="sufficient"/>
+ <xs:enumeration value="optional"/>
+ </xs:restriction>
+ </xs:simpleType>
+ </xs:attribute>
+ </xs:complexType>
+ </xs:element>
+ </xs:sequence>
+ <xs:attribute name="name" use="required" type="xs:string"/>
+ <xs:attribute name="rank" use="optional" default="0" type="xs:int"/>
+ </xs:complexType>
+ </xs:element>
+
+ <xs:element name="keystore">
+ <xs:complexType>
+ <xs:attribute name="name" use="required" type="xs:string"/>
+ <xs:attribute name="rank" use="optional" default="0" type="xs:int"/>
+ <xs:attribute name="path" use="required" type="xs:string"/>
+ <xs:attribute name="keystorePassword" use="optional" type="xs:string"/>
+ <xs:attribute name="keyPasswords" use="optional" type="xs:string"/>
+ </xs:complexType>
+ </xs:element>
+
+</xs:schema>
http://git-wip-us.apache.org/repos/asf/karaf/blob/5e2f19c4/jaas/blueprint/jasypt/pom.xml
----------------------------------------------------------------------
diff --git a/jaas/blueprint/jasypt/pom.xml b/jaas/blueprint/jasypt/pom.xml
new file mode 100644
index 0000000..e886fa1
--- /dev/null
+++ b/jaas/blueprint/jasypt/pom.xml
@@ -0,0 +1,146 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+
+ <!--
+
+ 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.
+ -->
+
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.apache.karaf.jaas.blueprint</groupId>
+ <artifactId>blueprint</artifactId>
+ <version>3.1.0-SNAPSHOT</version>
+ <relativePath>../pom.xml</relativePath>
+ </parent>
+
+ <artifactId>org.apache.karaf.jaas.blueprint.jasypt</artifactId>
+ <packaging>bundle</packaging>
+ <name>Apache Karaf :: JAAS :: Blueprint :: Jasypt</name>
+ <description>This bundle provides a blueprint namespace handler for configuring Jasypt</description>
+
+ <properties>
+ <appendedResourcesDirectory>${basedir}/../../etc/appended-resources</appendedResourcesDirectory>
+ </properties>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.karaf.jaas</groupId>
+ <artifactId>org.apache.karaf.jaas.modules</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.servicemix.bundles</groupId>
+ <artifactId>org.apache.servicemix.bundles.jasypt</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.aries.blueprint</groupId>
+ <artifactId>org.apache.aries.blueprint.core</artifactId>
+ <scope>provided</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.aries.blueprint</groupId>
+ <artifactId>org.apache.aries.blueprint.cm</artifactId>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>org.apache.felix.configadmin</artifactId>
+ <scope>test</scope>
+ </dependency>
+
+ <!-- Force osgi 4.2 so that blueprint bundle tracker works correctly -->
+ <dependency>
+ <groupId>org.osgi</groupId>
+ <artifactId>org.osgi.core</artifactId>
+ <version>4.2.0</version>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.osgi</groupId>
+ <artifactId>org.osgi.compendium</artifactId>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>com.googlecode.pojosr</groupId>
+ <artifactId>de.kalpatec.pojosr.framework</artifactId>
+ <version>0.1.6</version>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.ops4j.pax.tinybundles</groupId>
+ <artifactId>tinybundles</artifactId>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.aries.proxy</groupId>
+ <artifactId>org.apache.aries.proxy.impl</artifactId>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-log4j12</artifactId>
+ <version>${slf4j.version}</version>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>jcl-over-slf4j</artifactId>
+ <version>${slf4j.version}</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <resources>
+ <resource>
+ <directory>${project.basedir}/src/main/resources</directory>
+ <includes>
+ <include>**/*</include>
+ </includes>
+ </resource>
+ <resource>
+ <directory>${project.basedir}/src/main/resources</directory>
+ <filtering>true</filtering>
+ <includes>
+ <include>**/*.info</include>
+ </includes>
+ </resource>
+ </resources>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+ <configuration>
+ <instructions>
+ <Export-Package></Export-Package>
+ <Import-Package>*</Import-Package>
+ </instructions>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+</project>
http://git-wip-us.apache.org/repos/asf/karaf/blob/5e2f19c4/jaas/blueprint/jasypt/src/main/java/org/apache/karaf/jaas/blueprint/jasypt/handler/EncryptablePropertyPlaceholder.java
----------------------------------------------------------------------
diff --git a/jaas/blueprint/jasypt/src/main/java/org/apache/karaf/jaas/blueprint/jasypt/handler/EncryptablePropertyPlaceholder.java b/jaas/blueprint/jasypt/src/main/java/org/apache/karaf/jaas/blueprint/jasypt/handler/EncryptablePropertyPlaceholder.java
new file mode 100644
index 0000000..095678a
--- /dev/null
+++ b/jaas/blueprint/jasypt/src/main/java/org/apache/karaf/jaas/blueprint/jasypt/handler/EncryptablePropertyPlaceholder.java
@@ -0,0 +1,41 @@
+/*
+ * Licensed 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.
+ * under the License.
+ */
+package org.apache.karaf.jaas.blueprint.jasypt.handler;
+
+import org.jasypt.encryption.StringEncryptor;
+import org.apache.aries.blueprint.ext.AbstractPropertyPlaceholder;
+
+public class EncryptablePropertyPlaceholder extends AbstractPropertyPlaceholder {
+
+ private StringEncryptor encryptor;
+
+ public StringEncryptor getEncryptor() {
+ return encryptor;
+ }
+
+ public void setEncryptor(StringEncryptor encryptor) {
+ this.encryptor = encryptor;
+ }
+
+ public void init() {
+
+ }
+
+ @Override
+ protected String getProperty(String val) {
+ return encryptor.decrypt(val);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/karaf/blob/5e2f19c4/jaas/blueprint/jasypt/src/main/java/org/apache/karaf/jaas/blueprint/jasypt/handler/NamespaceHandler.java
----------------------------------------------------------------------
diff --git a/jaas/blueprint/jasypt/src/main/java/org/apache/karaf/jaas/blueprint/jasypt/handler/NamespaceHandler.java b/jaas/blueprint/jasypt/src/main/java/org/apache/karaf/jaas/blueprint/jasypt/handler/NamespaceHandler.java
new file mode 100644
index 0000000..1251ac9
--- /dev/null
+++ b/jaas/blueprint/jasypt/src/main/java/org/apache/karaf/jaas/blueprint/jasypt/handler/NamespaceHandler.java
@@ -0,0 +1,173 @@
+/*
+ * Licensed 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.
+ * under the License.
+ */
+package org.apache.karaf.jaas.blueprint.jasypt.handler;
+
+import java.net.URL;
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import org.apache.aries.blueprint.ParserContext;
+import org.apache.aries.blueprint.ext.PlaceholdersUtils;
+import org.apache.aries.blueprint.mutable.MutableBeanMetadata;
+import org.apache.aries.blueprint.mutable.MutableCollectionMetadata;
+import org.apache.aries.blueprint.mutable.MutableRefMetadata;
+import org.apache.aries.blueprint.mutable.MutableValueMetadata;
+import org.osgi.service.blueprint.container.ComponentDefinitionException;
+import org.osgi.service.blueprint.reflect.BeanMetadata;
+import org.osgi.service.blueprint.reflect.CollectionMetadata;
+import org.osgi.service.blueprint.reflect.ComponentMetadata;
+import org.osgi.service.blueprint.reflect.Metadata;
+import org.osgi.service.blueprint.reflect.RefMetadata;
+import org.osgi.service.blueprint.reflect.ValueMetadata;
+import org.w3c.dom.CharacterData;
+import org.w3c.dom.Comment;
+import org.w3c.dom.Element;
+import org.w3c.dom.EntityReference;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+
+public class NamespaceHandler implements org.apache.aries.blueprint.NamespaceHandler {
+
+ public static final String ID_ATTRIBUTE = "id";
+ public static final String PLACEHOLDER_PREFIX_ATTRIBUTE = "placeholder-prefix";
+ public static final String PLACEHOLDER_SUFFIX_ATTRIBUTE = "placeholder-suffix";
+ public static final String PROPERTY_PLACEHOLDER_ELEMENT = "property-placeholder";
+ public static final String ENCRYPTOR_REF_ATTRIBUTE = "encryptor-ref";
+ public static final String ENCRYPTOR_ELEMENT = "encryptor";
+ public static final String JASYPT_NAMESPACE_1_0 = "http://karaf.apache.org/xmlns/jasypt/v1.0.0";
+
+ private int idCounter;
+
+ public URL getSchemaLocation(String s) {
+ return getClass().getResource("/org/apache/karaf/jaas/blueprint/jasypt/handler/karaf-jasypt-1.0.0.xsd");
+ }
+
+ public Set<Class> getManagedClasses() {
+ return new HashSet<Class>(Arrays.asList(
+ EncryptablePropertyPlaceholder.class
+ ));
+ }
+
+ public Metadata parse(Element element, ParserContext context) {
+ String name = element.getLocalName() != null ? element.getLocalName() : element.getNodeName();
+ if (PROPERTY_PLACEHOLDER_ELEMENT.equals(name)) {
+ return parsePropertyPlaceholder(element, context);
+ }
+ throw new ComponentDefinitionException("Bad xml syntax: unknown element '" + name + "'");
+ }
+
+ public ComponentMetadata decorate(Node node, ComponentMetadata componentMetadata, ParserContext parserContext) {
+ throw new ComponentDefinitionException("Bad xml syntax: node decoration is not supported");
+ }
+
+ public ComponentMetadata parsePropertyPlaceholder(Element element, ParserContext context) {
+ MutableBeanMetadata metadata = context.createMetadata(MutableBeanMetadata.class);
+ metadata.setProcessor(true);
+ metadata.setId(getId(context, element));
+ metadata.setScope(BeanMetadata.SCOPE_SINGLETON);
+ metadata.setRuntimeClass(EncryptablePropertyPlaceholder.class);
+ metadata.setInitMethod("init");
+ String prefix = element.hasAttribute(PLACEHOLDER_PREFIX_ATTRIBUTE)
+ ? element.getAttribute(PLACEHOLDER_PREFIX_ATTRIBUTE)
+ : "ENC(";
+ metadata.addProperty("placeholderPrefix", createValue(context, prefix));
+ String suffix = element.hasAttribute(PLACEHOLDER_SUFFIX_ATTRIBUTE)
+ ? element.getAttribute(PLACEHOLDER_SUFFIX_ATTRIBUTE)
+ : ")";
+ metadata.addProperty("placeholderSuffix", createValue(context, suffix));
+ String encryptorRef = element.hasAttribute("encryptor-ref")
+ ? element.getAttribute("encryptor-ref")
+ : null;
+ if (encryptorRef != null) {
+ metadata.addProperty("encryptor", createRef(context, encryptorRef));
+ }
+ NodeList nl = element.getChildNodes();
+ for (int i = 0; i < nl.getLength(); i++) {
+ Node node = nl.item(i);
+ if (node instanceof Element) {
+ Element e = (Element) node;
+ if (JASYPT_NAMESPACE_1_0.equals(e.getNamespaceURI())) {
+ String name = e.getLocalName() != null ? e.getLocalName() : e.getNodeName();
+ if (ENCRYPTOR_ELEMENT.equals(name)) {
+ if (encryptorRef != null) {
+ throw new ComponentDefinitionException("Only one of " + ENCRYPTOR_REF_ATTRIBUTE + " attribute or " + ENCRYPTOR_ELEMENT + " element is allowed");
+ }
+ BeanMetadata encryptor = context.parseElement(BeanMetadata.class, metadata, e);
+ metadata.addProperty("encryptor", encryptor);
+ }
+ }
+ }
+ }
+ PlaceholdersUtils.validatePlaceholder(metadata, context.getComponentDefinitionRegistry());
+ return metadata;
+ }
+
+ public String getId(ParserContext context, Element element) {
+ if (element.hasAttribute(ID_ATTRIBUTE)) {
+ return element.getAttribute(ID_ATTRIBUTE);
+ } else {
+ return generateId(context);
+ }
+ }
+
+ private String generateId(ParserContext context) {
+ String id;
+ do {
+ id = ".jaas-" + ++idCounter;
+ } while (context.getComponentDefinitionRegistry().containsComponentDefinition(id));
+ return id;
+ }
+
+ private static ValueMetadata createValue(ParserContext context, String value) {
+ return createValue(context, value, null);
+ }
+
+ private static ValueMetadata createValue(ParserContext context, String value, String type) {
+ MutableValueMetadata m = context.createMetadata(MutableValueMetadata.class);
+ m.setStringValue(value);
+ m.setType(type);
+ return m;
+ }
+
+ private static CollectionMetadata createList(ParserContext context, List<String> list) {
+ MutableCollectionMetadata m = context.createMetadata(MutableCollectionMetadata.class);
+ m.setCollectionClass(List.class);
+ m.setValueType(String.class.getName());
+ for (String v : list) {
+ m.addValue(createValue(context, v, String.class.getName()));
+ }
+ return m;
+ }
+
+ private RefMetadata createRef(ParserContext context, String value) {
+ MutableRefMetadata r = context.createMetadata(MutableRefMetadata.class);
+ r.setComponentId(value);
+ return r;
+ }
+
+ private static String getTextValue(Element element) {
+ StringBuffer value = new StringBuffer();
+ NodeList nl = element.getChildNodes();
+ for (int i = 0; i < nl.getLength(); i++) {
+ Node item = nl.item(i);
+ if ((item instanceof CharacterData && !(item instanceof Comment)) || item instanceof EntityReference) {
+ value.append(item.getNodeValue());
+ }
+ }
+ return value.toString();
+ }
+}
http://git-wip-us.apache.org/repos/asf/karaf/blob/5e2f19c4/jaas/blueprint/jasypt/src/main/resources/OSGI-INF/blueprint/karaf-jaas-jasypt.xml
----------------------------------------------------------------------
diff --git a/jaas/blueprint/jasypt/src/main/resources/OSGI-INF/blueprint/karaf-jaas-jasypt.xml b/jaas/blueprint/jasypt/src/main/resources/OSGI-INF/blueprint/karaf-jaas-jasypt.xml
new file mode 100644
index 0000000..6ce6a2f
--- /dev/null
+++ b/jaas/blueprint/jasypt/src/main/resources/OSGI-INF/blueprint/karaf-jaas-jasypt.xml
@@ -0,0 +1,30 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ 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.
+
+-->
+<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0">
+
+ <bean id="namespaceHandler" class="org.apache.karaf.jaas.blueprint.jasypt.handler.NamespaceHandler"/>
+
+ <service ref="namespaceHandler" interface="org.apache.aries.blueprint.NamespaceHandler">
+ <service-properties>
+ <entry key="osgi.service.blueprint.namespace" value="http://karaf.apache.org/xmlns/jasypt/v1.0.0" />
+ </service-properties>
+ </service>
+
+</blueprint>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/karaf/blob/5e2f19c4/jaas/blueprint/jasypt/src/main/resources/OSGI-INF/bundle.info
----------------------------------------------------------------------
diff --git a/jaas/blueprint/jasypt/src/main/resources/OSGI-INF/bundle.info b/jaas/blueprint/jasypt/src/main/resources/OSGI-INF/bundle.info
new file mode 100644
index 0000000..b95de28
--- /dev/null
+++ b/jaas/blueprint/jasypt/src/main/resources/OSGI-INF/bundle.info
@@ -0,0 +1,14 @@
+\u001B[1mSYNOPSIS\u001B[0m
+ ${project.name}
+
+ ${project.description}
+
+ Maven URL:
+ \u001B[33mmvn:${project.groupId}/${project.artifactId}/${project.version}\u001B[0m
+
+\u001B[1mDESCRIPTION\u001B[0m
+ A Jasypt Namespace Handler for Blueprint
+
+\u001B[1mSEE ALSO\u001B[0m
+ \u001B[36mSecurity Framework\u001B[0m section of the Karaf Developer Guide.
+ \u001B[36mhttp://www.jasypt.org/\u001B[0m
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/karaf/blob/5e2f19c4/jaas/blueprint/jasypt/src/main/resources/org/apache/karaf/jaas/blueprint/jasypt/handler/karaf-jasypt-1.0.0.xsd
----------------------------------------------------------------------
diff --git a/jaas/blueprint/jasypt/src/main/resources/org/apache/karaf/jaas/blueprint/jasypt/handler/karaf-jasypt-1.0.0.xsd b/jaas/blueprint/jasypt/src/main/resources/org/apache/karaf/jaas/blueprint/jasypt/handler/karaf-jasypt-1.0.0.xsd
new file mode 100644
index 0000000..f5e6921
--- /dev/null
+++ b/jaas/blueprint/jasypt/src/main/resources/org/apache/karaf/jaas/blueprint/jasypt/handler/karaf-jasypt-1.0.0.xsd
@@ -0,0 +1,43 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ 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.
+
+-->
+<xs:schema elementFormDefault='qualified'
+ targetNamespace='http://karaf.apache.org/xmlns/jasypt/v1.0.0'
+ xmlns:xs='http://www.w3.org/2001/XMLSchema'
+ xmlns:bp="http://www.osgi.org/xmlns/blueprint/v1.0.0"
+ xmlns:tns='http://karaf.apache.org/xmlns/jasypt/v1.0.0'>
+
+ <xs:import namespace="http://www.osgi.org/xmlns/blueprint/v1.0.0"/>
+
+ <xs:element name="property-placeholder">
+ <xs:complexType>
+ <xs:complexContent>
+ <xs:extension base="bp:Tcomponent">
+ <xs:sequence>
+ <xs:element maxOccurs="1" minOccurs="0" name="encryptor" type="bp:Tbean"/>
+ </xs:sequence>
+ <xs:attribute name="placeholder-prefix" type="xs:string" use="optional" default="ENC("/>
+ <xs:attribute name="placeholder-suffix" type="xs:string" use="optional" default=")"/>
+ <xs:attribute name="encryptor-ref" type="bp:Tidref" use="optional"/>
+ </xs:extension>
+ </xs:complexContent>
+ </xs:complexType>
+ </xs:element>
+
+</xs:schema>
http://git-wip-us.apache.org/repos/asf/karaf/blob/5e2f19c4/jaas/blueprint/jasypt/src/test/java/org/apache/karaf/jaas/blueprint/jasypt/handler/EncryptableConfigAdminPropertyPlaceholderTest.java
----------------------------------------------------------------------
diff --git a/jaas/blueprint/jasypt/src/test/java/org/apache/karaf/jaas/blueprint/jasypt/handler/EncryptableConfigAdminPropertyPlaceholderTest.java b/jaas/blueprint/jasypt/src/test/java/org/apache/karaf/jaas/blueprint/jasypt/handler/EncryptableConfigAdminPropertyPlaceholderTest.java
new file mode 100644
index 0000000..db1283f
--- /dev/null
+++ b/jaas/blueprint/jasypt/src/test/java/org/apache/karaf/jaas/blueprint/jasypt/handler/EncryptableConfigAdminPropertyPlaceholderTest.java
@@ -0,0 +1,257 @@
+/*
+ * Licensed 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.
+ * under the License.
+ */
+package org.apache.karaf.jaas.blueprint.jasypt.handler;
+
+import de.kalpatec.pojosr.framework.PojoServiceRegistryFactoryImpl;
+import de.kalpatec.pojosr.framework.launch.BundleDescriptor;
+import de.kalpatec.pojosr.framework.launch.ClasspathScanner;
+import de.kalpatec.pojosr.framework.launch.PojoServiceRegistry;
+import de.kalpatec.pojosr.framework.launch.PojoServiceRegistryFactory;
+import junit.framework.TestCase;
+import org.jasypt.encryption.pbe.StandardPBEStringEncryptor;
+import org.jasypt.encryption.pbe.config.EnvironmentStringPBEConfig;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.ops4j.pax.tinybundles.core.TinyBundle;
+import org.osgi.framework.*;
+import org.osgi.service.cm.Configuration;
+import org.osgi.service.cm.ConfigurationAdmin;
+import org.osgi.util.tracker.ServiceTracker;
+
+import java.io.*;
+import java.net.URL;
+import java.util.*;
+import java.util.jar.JarInputStream;
+
+import static org.ops4j.pax.tinybundles.core.TinyBundles.bundle;
+
+public class EncryptableConfigAdminPropertyPlaceholderTest extends TestCase {
+
+ public static final long DEFAULT_TIMEOUT = 30000;
+
+ private BundleContext bundleContext;
+ private ConfigurationAdmin configAdmin;
+ private EnvironmentStringPBEConfig env;
+ private StandardPBEStringEncryptor enc;
+ private String encryptedValue;
+
+ @Before
+ public void setUp() throws Exception {
+
+ // Configure Jasypt
+ enc = new StandardPBEStringEncryptor();
+ env = new EnvironmentStringPBEConfig();
+ env.setAlgorithm("PBEWithMD5AndDES");
+ env.setPassword("password");
+ enc.setConfig(env);
+
+ System.setProperty("org.osgi.framework.storage", "target/osgi/" + System.currentTimeMillis());
+ System.setProperty("karaf.name", "root");
+
+ List<BundleDescriptor> bundles = new ClasspathScanner().scanForBundles("(Bundle-SymbolicName=*)");
+ bundles.add(getBundleDescriptor(
+ "target/jasypt2.jar",
+ bundle().add("OSGI-INF/blueprint/karaf-jaas-jasypt.xml", getClass().getResource("/OSGI-INF/blueprint/karaf-jaas-jasypt.xml"))
+ .set("Manifest-Version", "2")
+ .set("Bundle-ManifestVersion", "2")
+ .set("Bundle-SymbolicName", "jasypt")
+ .set("Bundle-Version", "0.0.0")));
+ bundles.add(getBundleDescriptor(
+ "target/test2.jar",
+ bundle().add("OSGI-INF/blueprint/config-adminTest.xml", getClass().getResource("config-adminTest.xml"))
+ .set("Manifest-Version", "2")
+ .set("Bundle-ManifestVersion", "2")
+ .set("Bundle-SymbolicName", "configtest")
+ .set("Bundle-Version", "0.0.0")));
+
+ Map config = new HashMap();
+ config.put(PojoServiceRegistryFactory.BUNDLE_DESCRIPTORS, bundles);
+ PojoServiceRegistry reg = new PojoServiceRegistryFactoryImpl().newPojoServiceRegistry(config);
+ bundleContext = reg.getBundleContext();
+ }
+
+ private BundleDescriptor getBundleDescriptor(String path, TinyBundle bundle) throws Exception {
+ File file = new File(path);
+ FileOutputStream fos = new FileOutputStream(file);
+ copy(bundle.build(), fos);
+ fos.close();
+ JarInputStream jis = new JarInputStream(new FileInputStream(file));
+ Map<String, String> headers = new HashMap<String, String>();
+ for (Map.Entry entry : jis.getManifest().getMainAttributes().entrySet()) {
+ headers.put(entry.getKey().toString(), entry.getValue().toString());
+ }
+ return new BundleDescriptor(
+ getClass().getClassLoader(),
+ new URL("jar:" + file.toURI().toString() + "!/"),
+ headers);
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ bundleContext.getBundle().stop();
+ }
+
+ @Test
+ public void testEncryptConfigProperty() throws Exception {
+
+ for (Bundle bundle : bundleContext.getBundles()) {
+ System.out.println(bundle.getSymbolicName() + " / " + bundle.getVersion());
+ }
+
+ configAdmin = getOsgiService(ConfigurationAdmin.class);
+ assertNotNull(configAdmin);
+
+ Configuration config = configAdmin.createFactoryConfiguration("encrypt.config");
+ Dictionary props = new Properties();
+
+ // Encrypt a key/value
+ // bar is encrypted and link to foo key
+ encryptedValue = enc.encrypt("bar");
+ props.put("foo", encryptedValue);
+ config.setBundleLocation(null);
+ config.update(props);
+
+ Configuration[] configs = configAdmin.listConfigurations(null);
+
+ for (Configuration conf : configs) {
+ String pid = conf.getPid();
+
+ // System.out.println(">> ConfigImpl pid : " + pid);
+
+ Dictionary<String, ?> dict = conf.getProperties();
+ for (Enumeration e = dict.keys(); e.hasMoreElements(); ) {
+ String key = (String) e.nextElement();
+ Object value = dict.get(key);
+
+ // System.out.println(">> Key : " + key + ", value : " + value);
+
+ if (key.equals("foo")) {
+ String val = (String) value;
+ // Verify encrypted value
+ assertEquals(encryptedValue, val);
+ // Decrypt and check value
+ String decrypt = enc.decrypt(val);
+ assertEquals("bar",decrypt);
+ }
+ }
+
+ }
+
+ }
+
+
+ protected <T> T getOsgiService(Class<T> type, long timeout) {
+ return getOsgiService(type, null, timeout);
+ }
+
+ protected <T> T getOsgiService(Class<T> type) {
+ return getOsgiService(type, null, DEFAULT_TIMEOUT);
+ }
+
+ protected <T> T getOsgiService(Class<T> type, String filter) {
+ return getOsgiService(type, filter, DEFAULT_TIMEOUT);
+ }
+
+ protected <T> T getOsgiService(Class<T> type, String filter, long timeout) {
+ ServiceTracker tracker = null;
+ try {
+ String flt;
+ if (filter != null) {
+ if (filter.startsWith("(")) {
+ flt = "(&(" + Constants.OBJECTCLASS + "=" + type.getName() + ")" + filter + ")";
+ } else {
+ flt = "(&(" + Constants.OBJECTCLASS + "=" + type.getName() + ")(" + filter + "))";
+ }
+ } else {
+ flt = "(" + Constants.OBJECTCLASS + "=" + type.getName() + ")";
+ }
+ Filter osgiFilter = FrameworkUtil.createFilter(flt);
+ tracker = new ServiceTracker(bundleContext, osgiFilter, null);
+ tracker.open(true);
+ // Note that the tracker is not closed to keep the reference
+ // This is buggy, as the service reference may change i think
+ Object svc = type.cast(tracker.waitForService(timeout));
+ if (svc == null) {
+ Dictionary dic = bundleContext.getBundle().getHeaders();
+ System.err.println("Test bundle headers: " + explode(dic));
+
+ for (ServiceReference ref : asCollection(bundleContext.getAllServiceReferences(null, null))) {
+ System.err.println("ServiceReference: " + ref);
+ }
+
+ for (ServiceReference ref : asCollection(bundleContext.getAllServiceReferences(null, flt))) {
+ System.err.println("Filtered ServiceReference: " + ref);
+ }
+
+ throw new RuntimeException("Gave up waiting for service " + flt);
+ }
+ return type.cast(svc);
+ } catch (InvalidSyntaxException e) {
+ throw new IllegalArgumentException("Invalid filter", e);
+ } catch (InterruptedException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ /*
+ * Explode the dictionary into a ,-delimited list of key=value pairs
+ */
+ private static String explode(Dictionary dictionary) {
+ Enumeration keys = dictionary.keys();
+ StringBuffer result = new StringBuffer();
+ while (keys.hasMoreElements()) {
+ Object key = keys.nextElement();
+ result.append(String.format("%s=%s", key, dictionary.get(key)));
+ if (keys.hasMoreElements()) {
+ result.append(", ");
+ }
+ }
+ return result.toString();
+ }
+
+ /*
+ * Provides an iterable collection of references, even if the original array is null
+ */
+ private static final Collection<ServiceReference> asCollection(ServiceReference[] references) {
+ List<ServiceReference> result = new LinkedList<ServiceReference>();
+ if (references != null) {
+ for (ServiceReference reference : references) {
+ result.add(reference);
+ }
+ }
+ return result;
+ }
+
+ public static long copy(final InputStream input, final OutputStream output) throws IOException {
+ return copy(input, output, 8024);
+ }
+
+ public static long copy(final InputStream input, final OutputStream output, int buffersize) throws IOException {
+ final byte[] buffer = new byte[buffersize];
+ int n;
+ long count = 0;
+ while (-1 != (n = input.read(buffer))) {
+ output.write(buffer, 0, n);
+ count += n;
+ }
+ return count;
+ }
+
+ /*
+ public void setConfigAdmin(ConfigurationAdmin configAdmin) {
+ this.configAdmin = configAdmin;
+ }*/
+}
http://git-wip-us.apache.org/repos/asf/karaf/blob/5e2f19c4/jaas/blueprint/jasypt/src/test/java/org/apache/karaf/jaas/blueprint/jasypt/handler/EncryptablePropertyPlaceholderTest.java
----------------------------------------------------------------------
diff --git a/jaas/blueprint/jasypt/src/test/java/org/apache/karaf/jaas/blueprint/jasypt/handler/EncryptablePropertyPlaceholderTest.java b/jaas/blueprint/jasypt/src/test/java/org/apache/karaf/jaas/blueprint/jasypt/handler/EncryptablePropertyPlaceholderTest.java
new file mode 100644
index 0000000..d3e0f7b
--- /dev/null
+++ b/jaas/blueprint/jasypt/src/test/java/org/apache/karaf/jaas/blueprint/jasypt/handler/EncryptablePropertyPlaceholderTest.java
@@ -0,0 +1,228 @@
+/*
+ * Licensed 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.
+ * under the License.
+ */
+package org.apache.karaf.jaas.blueprint.jasypt.handler;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.net.URL;
+import java.util.Collection;
+import java.util.Dictionary;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.jar.JarInputStream;
+
+import de.kalpatec.pojosr.framework.PojoServiceRegistryFactoryImpl;
+import de.kalpatec.pojosr.framework.launch.BundleDescriptor;
+import de.kalpatec.pojosr.framework.launch.ClasspathScanner;
+import de.kalpatec.pojosr.framework.launch.PojoServiceRegistry;
+import de.kalpatec.pojosr.framework.launch.PojoServiceRegistryFactory;
+import junit.framework.TestCase;
+import org.jasypt.encryption.pbe.StandardPBEStringEncryptor;
+import org.jasypt.encryption.pbe.config.EnvironmentStringPBEConfig;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.ops4j.pax.tinybundles.core.TinyBundle;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.Constants;
+import org.osgi.framework.Filter;
+import org.osgi.framework.FrameworkUtil;
+import org.osgi.framework.InvalidSyntaxException;
+import org.osgi.framework.ServiceReference;
+import org.osgi.util.tracker.ServiceTracker;
+
+import static org.ops4j.pax.tinybundles.core.TinyBundles.bundle;
+
+public class EncryptablePropertyPlaceholderTest extends TestCase {
+
+ public static final long DEFAULT_TIMEOUT = 30000;
+
+ private BundleContext bundleContext;
+
+ @Before
+ public void setUp() throws Exception {
+
+ StandardPBEStringEncryptor enc = new StandardPBEStringEncryptor();
+ EnvironmentStringPBEConfig env = new EnvironmentStringPBEConfig();
+ env.setAlgorithm("PBEWithMD5AndDES");
+ env.setPassword("password");
+ enc.setConfig(env);
+ String val = enc.encrypt("bar");
+ System.setProperty("foo", val);
+
+ System.setProperty("org.bundles.framework.storage", "target/bundles/" + System.currentTimeMillis());
+ System.setProperty("karaf.name", "root");
+
+ List<BundleDescriptor> bundles = new ClasspathScanner().scanForBundles("(Bundle-SymbolicName=*)");
+ bundles.add(getBundleDescriptor(
+ "target/jasypt.jar",
+ bundle().add("OSGI-INF/blueprint/karaf-jaas-jasypt.xml", getClass().getResource("/OSGI-INF/blueprint/karaf-jaas-jasypt.xml"))
+ .set("Manifest-Version", "2")
+ .set("Bundle-ManifestVersion", "2")
+ .set("Bundle-SymbolicName", "jasypt")
+ .set("Bundle-Version", "0.0.0")));
+ bundles.add(getBundleDescriptor(
+ "target/test.jar",
+ bundle().add("OSGI-INF/blueprint/test.xml", getClass().getResource("test.xml"))
+ .set("Manifest-Version", "2")
+ .set("Bundle-ManifestVersion", "2")
+ .set("Bundle-SymbolicName", "test")
+ .set("Bundle-Version", "0.0.0")));
+
+ Map config = new HashMap();
+ config.put(PojoServiceRegistryFactory.BUNDLE_DESCRIPTORS, bundles);
+ PojoServiceRegistry reg = new PojoServiceRegistryFactoryImpl().newPojoServiceRegistry(config);
+ bundleContext = reg.getBundleContext();
+ }
+
+ private BundleDescriptor getBundleDescriptor(String path, TinyBundle bundle) throws Exception {
+ File file = new File(path);
+ FileOutputStream fos = new FileOutputStream(file);
+ copy(bundle.build(), fos);
+ fos.close();
+ JarInputStream jis = new JarInputStream(new FileInputStream(file));
+ Map<String, String> headers = new HashMap<String, String>();
+ for (Map.Entry entry : jis.getManifest().getMainAttributes().entrySet()) {
+ headers.put(entry.getKey().toString(), entry.getValue().toString());
+ }
+ return new BundleDescriptor(
+ getClass().getClassLoader(),
+ new URL("jar:" + file.toURI().toString() + "!/"),
+ headers);
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ bundleContext.getBundle().stop();
+ }
+
+ @Test
+ public void testPlaceholder() throws Exception {
+
+ for (Bundle bundle: bundleContext.getBundles()) {
+ System.out.println(bundle.getSymbolicName() + " / " + bundle.getVersion());
+ }
+
+ String encoded = getOsgiService(String.class, "(encoded=*)");
+ assertEquals("bar", encoded);
+ }
+
+
+ protected <T> T getOsgiService(Class<T> type, long timeout) {
+ return getOsgiService(type, null, timeout);
+ }
+
+ protected <T> T getOsgiService(Class<T> type) {
+ return getOsgiService(type, null, DEFAULT_TIMEOUT);
+ }
+
+ protected <T> T getOsgiService(Class<T> type, String filter) {
+ return getOsgiService(type, filter, DEFAULT_TIMEOUT);
+ }
+
+ protected <T> T getOsgiService(Class<T> type, String filter, long timeout) {
+ ServiceTracker tracker = null;
+ try {
+ String flt;
+ if (filter != null) {
+ if (filter.startsWith("(")) {
+ flt = "(&(" + Constants.OBJECTCLASS + "=" + type.getName() + ")" + filter + ")";
+ } else {
+ flt = "(&(" + Constants.OBJECTCLASS + "=" + type.getName() + ")(" + filter + "))";
+ }
+ } else {
+ flt = "(" + Constants.OBJECTCLASS + "=" + type.getName() + ")";
+ }
+ Filter osgiFilter = FrameworkUtil.createFilter(flt);
+ tracker = new ServiceTracker(bundleContext, osgiFilter, null);
+ tracker.open(true);
+ // Note that the tracker is not closed to keep the reference
+ // This is buggy, as the service reference may change i think
+ Object svc = type.cast(tracker.waitForService(timeout));
+ if (svc == null) {
+ Dictionary dic = bundleContext.getBundle().getHeaders();
+ System.err.println("Test bundle headers: " + explode(dic));
+
+ for (ServiceReference ref : asCollection(bundleContext.getAllServiceReferences(null, null))) {
+ System.err.println("ServiceReference: " + ref);
+ }
+
+ for (ServiceReference ref : asCollection(bundleContext.getAllServiceReferences(null, flt))) {
+ System.err.println("Filtered ServiceReference: " + ref);
+ }
+
+ throw new RuntimeException("Gave up waiting for service " + flt);
+ }
+ return type.cast(svc);
+ } catch (InvalidSyntaxException e) {
+ throw new IllegalArgumentException("Invalid filter", e);
+ } catch (InterruptedException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ /*
+ * Explode the dictionary into a ,-delimited list of key=value pairs
+ */
+ private static String explode(Dictionary dictionary) {
+ Enumeration keys = dictionary.keys();
+ StringBuffer result = new StringBuffer();
+ while (keys.hasMoreElements()) {
+ Object key = keys.nextElement();
+ result.append(String.format("%s=%s", key, dictionary.get(key)));
+ if (keys.hasMoreElements()) {
+ result.append(", ");
+ }
+ }
+ return result.toString();
+ }
+
+ /*
+ * Provides an iterable collection of references, even if the original array is null
+ */
+ private static final Collection<ServiceReference> asCollection(ServiceReference[] references) {
+ List<ServiceReference> result = new LinkedList<ServiceReference>();
+ if (references != null) {
+ for (ServiceReference reference : references) {
+ result.add(reference);
+ }
+ }
+ return result;
+ }
+
+ public static long copy(final InputStream input, final OutputStream output) throws IOException {
+ return copy(input, output, 8024);
+ }
+
+ public static long copy(final InputStream input, final OutputStream output, int buffersize) throws IOException {
+ final byte[] buffer = new byte[buffersize];
+ int n;
+ long count=0;
+ while (-1 != (n = input.read(buffer))) {
+ output.write(buffer, 0, n);
+ count += n;
+ }
+ return count;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/karaf/blob/5e2f19c4/jaas/blueprint/jasypt/src/test/resources/log4j.properties
----------------------------------------------------------------------
diff --git a/jaas/blueprint/jasypt/src/test/resources/log4j.properties b/jaas/blueprint/jasypt/src/test/resources/log4j.properties
new file mode 100644
index 0000000..e1cbdd1
--- /dev/null
+++ b/jaas/blueprint/jasypt/src/test/resources/log4j.properties
@@ -0,0 +1,34 @@
+## ---------------------------------------------------------------------------
+## 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.
+## ---------------------------------------------------------------------------
+
+#
+# The logging properties used during tests..
+#
+log4j.rootLogger=DEBUG, console, file
+
+# Console will only display warnnings
+log4j.appender.console=org.apache.log4j.ConsoleAppender
+log4j.appender.console.layout=org.apache.log4j.PatternLayout
+log4j.appender.console.layout.ConversionPattern=%d{ISO8601} | %-5.5p | %-16.16t | %-32.32c{1} | %-32.32C %4L | %m%n
+#log4j.appender.console.threshold=WARN
+
+# File appender will contain all info messages
+log4j.appender.file=org.apache.log4j.FileAppender
+log4j.appender.file.layout=org.apache.log4j.PatternLayout
+log4j.appender.file.layout.ConversionPattern=%d | %-5p | %m | %c | %t%n
+log4j.appender.file.file=target/test.log
+log4j.appender.file.append=true
http://git-wip-us.apache.org/repos/asf/karaf/blob/5e2f19c4/jaas/blueprint/jasypt/src/test/resources/org/apache/karaf/jaas/blueprint/jasypt/handler/configadmin-test.xml
----------------------------------------------------------------------
diff --git a/jaas/blueprint/jasypt/src/test/resources/org/apache/karaf/jaas/blueprint/jasypt/handler/configadmin-test.xml b/jaas/blueprint/jasypt/src/test/resources/org/apache/karaf/jaas/blueprint/jasypt/handler/configadmin-test.xml
new file mode 100644
index 0000000..ccb2cca
--- /dev/null
+++ b/jaas/blueprint/jasypt/src/test/resources/org/apache/karaf/jaas/blueprint/jasypt/handler/configadmin-test.xml
@@ -0,0 +1,41 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ 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.
+-->
+<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
+ xmlns:ext="http://aries.apache.org/blueprint/xmlns/blueprint-ext/v1.0.0"
+ xmlns:enc="http://karaf.apache.org/xmlns/jasypt/v1.0.0"
+ xmlns:cm="http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.1.0">
+
+ <cm:property-placeholder persistent-id="encrypt.config" update-strategy="reload" >
+ <cm:default-properties>
+ <cm:property name="encoded" value="ENC(${foo})"/>
+ </cm:default-properties>
+ </cm:property-placeholder>
+
+ <enc:property-placeholder>
+ <enc:encryptor class="org.jasypt.encryption.pbe.StandardPBEStringEncryptor">
+ <property name="config">
+ <bean class="org.jasypt.encryption.pbe.config.EnvironmentStringPBEConfig">
+ <property name="algorithm" value="PBEWithMD5AndDES" />
+ <property name="password" value="password" />
+ </bean>
+ </property>
+ </enc:encryptor>
+ </enc:property-placeholder>
+
+</blueprint>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/karaf/blob/5e2f19c4/jaas/blueprint/jasypt/src/test/resources/org/apache/karaf/jaas/blueprint/jasypt/handler/test.xml
----------------------------------------------------------------------
diff --git a/jaas/blueprint/jasypt/src/test/resources/org/apache/karaf/jaas/blueprint/jasypt/handler/test.xml b/jaas/blueprint/jasypt/src/test/resources/org/apache/karaf/jaas/blueprint/jasypt/handler/test.xml
new file mode 100644
index 0000000..c3a2aff
--- /dev/null
+++ b/jaas/blueprint/jasypt/src/test/resources/org/apache/karaf/jaas/blueprint/jasypt/handler/test.xml
@@ -0,0 +1,45 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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.
+-->
+<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
+ xmlns:ext="http://aries.apache.org/blueprint/xmlns/blueprint-ext/v1.0.0"
+ xmlns:enc="http://karaf.apache.org/xmlns/jasypt/v1.0.0">
+
+
+ <ext:property-placeholder />
+
+ <enc:property-placeholder>
+ <enc:encryptor class="org.jasypt.encryption.pbe.StandardPBEStringEncryptor">
+ <property name="config">
+ <bean class="org.jasypt.encryption.pbe.config.EnvironmentStringPBEConfig">
+ <property name="algorithm" value="PBEWithMD5AndDES" />
+ <property name="password" value="password" />
+ </bean>
+ </property>
+ </enc:encryptor>
+ </enc:property-placeholder>
+
+ <service auto-export="all-classes">
+ <service-properties>
+ <entry key="encoded" value="ENC(${foo})" />
+ </service-properties>
+ <bean class="java.lang.String">
+ <argument value="ENC(${foo})" />
+ </bean>
+ </service>
+
+</blueprint>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/karaf/blob/5e2f19c4/jaas/blueprint/pom.xml
----------------------------------------------------------------------
diff --git a/jaas/blueprint/pom.xml b/jaas/blueprint/pom.xml
new file mode 100644
index 0000000..40b5419
--- /dev/null
+++ b/jaas/blueprint/pom.xml
@@ -0,0 +1,41 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+
+ <!--
+
+ 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.
+ -->
+
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.apache.karaf.jaas</groupId>
+ <artifactId>jaas</artifactId>
+ <version>3.1.0-SNAPSHOT</version>
+ <relativePath>../pom.xml</relativePath>
+ </parent>
+
+ <groupId>org.apache.karaf.jaas.blueprint</groupId>
+ <artifactId>blueprint</artifactId>
+ <packaging>pom</packaging>
+ <name>Apache Karaf :: JAAS :: Blueprint</name>
+
+ <modules>
+ <module>config</module>
+ <module>jasypt</module>
+ </modules>
+
+</project>
http://git-wip-us.apache.org/repos/asf/karaf/blob/5e2f19c4/jaas/config/pom.xml
----------------------------------------------------------------------
diff --git a/jaas/config/pom.xml b/jaas/config/pom.xml
index 55b070e..75ca172 100644
--- a/jaas/config/pom.xml
+++ b/jaas/config/pom.xml
@@ -97,18 +97,20 @@
<artifactId>maven-bundle-plugin</artifactId>
<configuration>
<instructions>
- <Export-Package>${project.artifactId};version=${project.version}</Export-Package>
+ <Export-Package>
+ ${project.artifactId};version=${project.version},
+ ${project.artifactId}.impl;version=${project.version}
+ </Export-Package>
<Import-Package>
- !${project.artifactId},
- org.apache.aries.blueprint,
- org.osgi.service.blueprint.container,
- org.osgi.service.blueprint.reflect,
+ !${project.artifactId}.*,
*
</Import-Package>
<Private-Package>
- ${project.artifactId}.impl,
org.apache.karaf.util.collections
</Private-Package>
+ <Bundle-Activator>
+ org.apache.karaf.jaas.config.impl.Activator
+ </Bundle-Activator>
</instructions>
</configuration>
</plugin>
http://git-wip-us.apache.org/repos/asf/karaf/blob/5e2f19c4/jaas/config/src/main/java/org/apache/karaf/jaas/config/impl/Activator.java
----------------------------------------------------------------------
diff --git a/jaas/config/src/main/java/org/apache/karaf/jaas/config/impl/Activator.java b/jaas/config/src/main/java/org/apache/karaf/jaas/config/impl/Activator.java
new file mode 100644
index 0000000..9fc6e53
--- /dev/null
+++ b/jaas/config/src/main/java/org/apache/karaf/jaas/config/impl/Activator.java
@@ -0,0 +1,93 @@
+/*
+ * 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.karaf.jaas.config.impl;
+
+import org.apache.karaf.jaas.boot.ProxyLoginModule;
+import org.apache.karaf.jaas.config.JaasRealm;
+import org.apache.karaf.jaas.config.KeystoreInstance;
+import org.apache.karaf.jaas.config.KeystoreManager;
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceReference;
+import org.osgi.framework.ServiceRegistration;
+import org.osgi.util.tracker.ServiceTracker;
+import org.osgi.util.tracker.ServiceTrackerCustomizer;
+
+public class Activator implements BundleActivator {
+
+ private OsgiConfiguration osgiConfiguration;
+ private ServiceRegistration<KeystoreManager> registration;
+ private ServiceTracker<KeystoreInstance, KeystoreInstance> keystoreInstanceServiceTracker;
+ private ServiceTracker<JaasRealm, JaasRealm> jaasRealmServiceTracker;
+
+ @Override
+ public void start(final BundleContext context) throws Exception {
+ ProxyLoginModule.init(context.getBundle(0).getBundleContext());
+
+ final OsgiKeystoreManager keystoreManager = new OsgiKeystoreManager();
+
+ keystoreInstanceServiceTracker = new ServiceTracker<KeystoreInstance, KeystoreInstance>(
+ context, KeystoreInstance.class, new ServiceTrackerCustomizer<KeystoreInstance, KeystoreInstance>() {
+ @Override
+ public KeystoreInstance addingService(ServiceReference<KeystoreInstance> reference) {
+ KeystoreInstance service = context.getService(reference);
+ keystoreManager.register(service, null);
+ return service;
+ }
+ @Override
+ public void modifiedService(ServiceReference<KeystoreInstance> reference, KeystoreInstance service) {
+ }
+ @Override
+ public void removedService(ServiceReference<KeystoreInstance> reference, KeystoreInstance service) {
+ keystoreManager.unregister(service, null);
+ context.ungetService(reference);
+ }
+ });
+ keystoreInstanceServiceTracker.open();
+
+ osgiConfiguration = new OsgiConfiguration();
+ osgiConfiguration.init();
+
+ jaasRealmServiceTracker = new ServiceTracker<JaasRealm, JaasRealm>(
+ context, JaasRealm.class, new ServiceTrackerCustomizer<JaasRealm, JaasRealm>() {
+ @Override
+ public JaasRealm addingService(ServiceReference<JaasRealm> reference) {
+ JaasRealm service = context.getService(reference);
+ osgiConfiguration.register(service, null);
+ return service;
+ }
+ @Override
+ public void modifiedService(ServiceReference<JaasRealm> reference, JaasRealm service) {
+ }
+ @Override
+ public void removedService(ServiceReference<JaasRealm> reference, JaasRealm service) {
+ osgiConfiguration.unregister(service, null);
+ }
+ });
+ jaasRealmServiceTracker.open();
+
+ registration = context.registerService(KeystoreManager.class, keystoreManager, null);
+ }
+
+ @Override
+ public void stop(BundleContext context) throws Exception {
+ registration.unregister();
+ keystoreInstanceServiceTracker.close();
+ jaasRealmServiceTracker.close();
+ osgiConfiguration.close();
+ }
+}