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:12 UTC
[14/24] [KARAF-2833] Make jaas/config,
jaas/jasypt and jaas/modules independent of blueprint
http://git-wip-us.apache.org/repos/asf/karaf/blob/5e2f19c4/jaas/config/src/main/java/org/apache/karaf/jaas/config/impl/NamespaceHandler.java
----------------------------------------------------------------------
diff --git a/jaas/config/src/main/java/org/apache/karaf/jaas/config/impl/NamespaceHandler.java b/jaas/config/src/main/java/org/apache/karaf/jaas/config/impl/NamespaceHandler.java
deleted file mode 100644
index a6ed36c..0000000
--- a/jaas/config/src/main/java/org/apache/karaf/jaas/config/impl/NamespaceHandler.java
+++ /dev/null
@@ -1,165 +0,0 @@
-/*
- * 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.aries.blueprint.ParserContext;
-import org.apache.aries.blueprint.mutable.*;
-import org.apache.karaf.jaas.boot.ProxyLoginModule;
-import org.apache.karaf.jaas.config.JaasRealm;
-import org.apache.karaf.jaas.config.KeystoreInstance;
-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.*;
-
-import java.net.URL;
-import java.util.Arrays;
-import java.util.HashSet;
-import java.util.Set;
-
-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/config/karaf-jaas-1.0.0.xsd");
- } else {
- return getClass().getResource("/org/apache/karaf/jaas/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/config/src/main/resources/OSGI-INF/blueprint/karaf-jaas.xml
----------------------------------------------------------------------
diff --git a/jaas/config/src/main/resources/OSGI-INF/blueprint/karaf-jaas.xml b/jaas/config/src/main/resources/OSGI-INF/blueprint/karaf-jaas.xml
deleted file mode 100644
index 897671e..0000000
--- a/jaas/config/src/main/resources/OSGI-INF/blueprint/karaf-jaas.xml
+++ /dev/null
@@ -1,61 +0,0 @@
-<?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="config"
- class="org.apache.karaf.jaas.config.impl.OsgiConfiguration"
- init-method="init"
- destroy-method="close"/>
-
- <reference-list id="realms"
- interface="org.apache.karaf.jaas.config.JaasRealm"
- availability="optional">
- <reference-listener ref="config" bind-method="register" unbind-method="unregister" />
- </reference-list>
-
- <bean id="proxyLoginModuleInitializer" class="org.apache.karaf.jaas.config.impl.ProxyLoginModuleInitializer" init-method="init">
- <property name="bundleContext" ref="blueprintBundleContext"/>
- </bean>
-
- <!-- Register the Straight-Through flow -->
- <bean id="keystoreManager" class="org.apache.karaf.jaas.config.impl.OsgiKeystoreManager" />
- <service ref="keystoreManager" interface="org.apache.karaf.jaas.config.KeystoreManager" />
-
- <reference-list id="keystores"
- interface="org.apache.karaf.jaas.config.KeystoreInstance"
- availability="optional">
- <reference-listener ref="keystoreManager" bind-method="register" unbind-method="unregister" />
- </reference-list>
-
- <bean id="namespaceHandler" class="org.apache.karaf.jaas.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/config/src/main/resources/org/apache/karaf/jaas/config/karaf-jaas-1.0.0.xsd
----------------------------------------------------------------------
diff --git a/jaas/config/src/main/resources/org/apache/karaf/jaas/config/karaf-jaas-1.0.0.xsd b/jaas/config/src/main/resources/org/apache/karaf/jaas/config/karaf-jaas-1.0.0.xsd
deleted file mode 100644
index 225665c..0000000
--- a/jaas/config/src/main/resources/org/apache/karaf/jaas/config/karaf-jaas-1.0.0.xsd
+++ /dev/null
@@ -1,62 +0,0 @@
-<?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/config/src/main/resources/org/apache/karaf/jaas/config/karaf-jaas-1.1.0.xsd
----------------------------------------------------------------------
diff --git a/jaas/config/src/main/resources/org/apache/karaf/jaas/config/karaf-jaas-1.1.0.xsd b/jaas/config/src/main/resources/org/apache/karaf/jaas/config/karaf-jaas-1.1.0.xsd
deleted file mode 100644
index f56b206..0000000
--- a/jaas/config/src/main/resources/org/apache/karaf/jaas/config/karaf-jaas-1.1.0.xsd
+++ /dev/null
@@ -1,63 +0,0 @@
-<?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/jasypt/pom.xml
----------------------------------------------------------------------
diff --git a/jaas/jasypt/pom.xml b/jaas/jasypt/pom.xml
index 0cc9b35..dc7882b 100644
--- a/jaas/jasypt/pom.xml
+++ b/jaas/jasypt/pom.xml
@@ -38,7 +38,12 @@
</properties>
<dependencies>
-
+
+ <dependency>
+ <groupId>org.osgi</groupId>
+ <artifactId>org.osgi.core</artifactId>
+ </dependency>
+
<dependency>
<groupId>org.apache.karaf.jaas</groupId>
<artifactId>org.apache.karaf.jaas.modules</artifactId>
@@ -71,14 +76,6 @@
<scope>provided</scope>
</dependency>
- <!-- 4.2.0 is needed in order to have aries util work correctly within pojosr -->
- <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>
@@ -153,12 +150,14 @@
<configuration>
<instructions>
<Import-Package>
- org.apache.aries.blueprint,
- org.osgi.service.blueprint.container,
- org.osgi.service.blueprint.reflect,
*
</Import-Package>
- <Private-Package>org.apache.karaf.jaas.jasypt.impl</Private-Package>
+ <Private-Package>
+ org.apache.karaf.jaas.jasypt.impl
+ </Private-Package>
+ <Bundle-Activator>
+ org.apache.karaf.jaas.jasypt.impl.Activator
+ </Bundle-Activator>
</instructions>
</configuration>
</plugin>
http://git-wip-us.apache.org/repos/asf/karaf/blob/5e2f19c4/jaas/jasypt/src/main/java/org/apache/karaf/jaas/jasypt/handler/EncryptablePropertyPlaceholder.java
----------------------------------------------------------------------
diff --git a/jaas/jasypt/src/main/java/org/apache/karaf/jaas/jasypt/handler/EncryptablePropertyPlaceholder.java b/jaas/jasypt/src/main/java/org/apache/karaf/jaas/jasypt/handler/EncryptablePropertyPlaceholder.java
deleted file mode 100644
index c6fed48..0000000
--- a/jaas/jasypt/src/main/java/org/apache/karaf/jaas/jasypt/handler/EncryptablePropertyPlaceholder.java
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * 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.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/jasypt/src/main/java/org/apache/karaf/jaas/jasypt/handler/NamespaceHandler.java
----------------------------------------------------------------------
diff --git a/jaas/jasypt/src/main/java/org/apache/karaf/jaas/jasypt/handler/NamespaceHandler.java b/jaas/jasypt/src/main/java/org/apache/karaf/jaas/jasypt/handler/NamespaceHandler.java
deleted file mode 100644
index 4a196c0..0000000
--- a/jaas/jasypt/src/main/java/org/apache/karaf/jaas/jasypt/handler/NamespaceHandler.java
+++ /dev/null
@@ -1,173 +0,0 @@
-/*
- * 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.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/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/jasypt/src/main/java/org/apache/karaf/jaas/jasypt/impl/Activator.java
----------------------------------------------------------------------
diff --git a/jaas/jasypt/src/main/java/org/apache/karaf/jaas/jasypt/impl/Activator.java b/jaas/jasypt/src/main/java/org/apache/karaf/jaas/jasypt/impl/Activator.java
new file mode 100644
index 0000000..bbb3eac
--- /dev/null
+++ b/jaas/jasypt/src/main/java/org/apache/karaf/jaas/jasypt/impl/Activator.java
@@ -0,0 +1,45 @@
+/*
+ * 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.jasypt.impl;
+
+import java.util.Hashtable;
+
+import org.apache.karaf.jaas.modules.EncryptionService;
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceRegistration;
+
+public class Activator implements BundleActivator {
+
+ private ServiceRegistration<EncryptionService> registration;
+
+ @Override
+ public void start(BundleContext context) throws Exception {
+ Hashtable<String, Object> props = new Hashtable<String, Object>();
+ props.put("name", "jasypt");
+ registration = context.registerService(
+ EncryptionService.class,
+ new JasyptEncryptionService(),
+ props);
+
+ }
+
+ @Override
+ public void stop(BundleContext context) throws Exception {
+ registration.unregister();
+ }
+}
http://git-wip-us.apache.org/repos/asf/karaf/blob/5e2f19c4/jaas/jasypt/src/main/resources/OSGI-INF/blueprint/karaf-jaas-jasypt.xml
----------------------------------------------------------------------
diff --git a/jaas/jasypt/src/main/resources/OSGI-INF/blueprint/karaf-jaas-jasypt.xml b/jaas/jasypt/src/main/resources/OSGI-INF/blueprint/karaf-jaas-jasypt.xml
deleted file mode 100644
index a20482a..0000000
--- a/jaas/jasypt/src/main/resources/OSGI-INF/blueprint/karaf-jaas-jasypt.xml
+++ /dev/null
@@ -1,37 +0,0 @@
-<?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">
-
- <service interface="org.apache.karaf.jaas.modules.EncryptionService">
- <service-properties>
- <entry key="name" value="jasypt" />
- </service-properties>
- <bean class="org.apache.karaf.jaas.jasypt.impl.JasyptEncryptionService"/>
- </service>
-
- <bean id="namespaceHandler" class="org.apache.karaf.jaas.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/jasypt/src/main/resources/org/apache/karaf/jaas/jasypt/handler/karaf-jasypt-1.0.0.xsd
----------------------------------------------------------------------
diff --git a/jaas/jasypt/src/main/resources/org/apache/karaf/jaas/jasypt/handler/karaf-jasypt-1.0.0.xsd b/jaas/jasypt/src/main/resources/org/apache/karaf/jaas/jasypt/handler/karaf-jasypt-1.0.0.xsd
deleted file mode 100644
index f5e6921..0000000
--- a/jaas/jasypt/src/main/resources/org/apache/karaf/jaas/jasypt/handler/karaf-jasypt-1.0.0.xsd
+++ /dev/null
@@ -1,43 +0,0 @@
-<?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/jasypt/src/test/java/org/apache/karaf/jaas/jasypt/handler/EncryptablePropertyPlaceholderTest.java
----------------------------------------------------------------------
diff --git a/jaas/jasypt/src/test/java/org/apache/karaf/jaas/jasypt/handler/EncryptablePropertyPlaceholderTest.java b/jaas/jasypt/src/test/java/org/apache/karaf/jaas/jasypt/handler/EncryptablePropertyPlaceholderTest.java
deleted file mode 100644
index 5c80048..0000000
--- a/jaas/jasypt/src/test/java/org/apache/karaf/jaas/jasypt/handler/EncryptablePropertyPlaceholderTest.java
+++ /dev/null
@@ -1,228 +0,0 @@
-/*
- * 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.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/jasypt/src/test/resources/org/apache/karaf/jaas/jasypt/handler/test.xml
----------------------------------------------------------------------
diff --git a/jaas/jasypt/src/test/resources/org/apache/karaf/jaas/jasypt/handler/test.xml b/jaas/jasypt/src/test/resources/org/apache/karaf/jaas/jasypt/handler/test.xml
deleted file mode 100644
index c3a2aff..0000000
--- a/jaas/jasypt/src/test/resources/org/apache/karaf/jaas/jasypt/handler/test.xml
+++ /dev/null
@@ -1,45 +0,0 @@
-<?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/modules/pom.xml
----------------------------------------------------------------------
diff --git a/jaas/modules/pom.xml b/jaas/modules/pom.xml
index a74adc2..1ed86a4 100644
--- a/jaas/modules/pom.xml
+++ b/jaas/modules/pom.xml
@@ -114,15 +114,16 @@
<instructions>
<Import-Package>
javax.net,
- org.apache.aries.blueprint,
- org.osgi.service.blueprint.container,
- org.osgi.service.blueprint.reflect,
org.apache.karaf.jaas.config,
*
</Import-Package>
<Private-Package>
+ org.apache.karaf.jaas.modules.impl,
org.apache.felix.utils.properties
</Private-Package>
+ <Bundle-Activator>
+ org.apache.karaf.jaas.modules.impl.Activator
+ </Bundle-Activator>
</instructions>
</configuration>
</plugin>
http://git-wip-us.apache.org/repos/asf/karaf/blob/5e2f19c4/jaas/modules/src/main/java/org/apache/karaf/jaas/modules/impl/Activator.java
----------------------------------------------------------------------
diff --git a/jaas/modules/src/main/java/org/apache/karaf/jaas/modules/impl/Activator.java b/jaas/modules/src/main/java/org/apache/karaf/jaas/modules/impl/Activator.java
new file mode 100644
index 0000000..b065822
--- /dev/null
+++ b/jaas/modules/src/main/java/org/apache/karaf/jaas/modules/impl/Activator.java
@@ -0,0 +1,48 @@
+package org.apache.karaf.jaas.modules.impl;
+
+import java.util.Hashtable;
+
+import org.apache.karaf.jaas.config.JaasRealm;
+import org.apache.karaf.jaas.modules.BackingEngineFactory;
+import org.apache.karaf.jaas.modules.EncryptionService;
+import org.apache.karaf.jaas.modules.encryption.BasicEncryptionService;
+import org.apache.karaf.jaas.modules.properties.PropertiesBackingEngineFactory;
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.Constants;
+import org.osgi.framework.ServiceRegistration;
+import org.osgi.service.cm.ManagedService;
+
+public class Activator implements BundleActivator {
+
+ private ServiceRegistration<BackingEngineFactory> propertiesBackingEngineFactoryServiceRegistration;
+ private ServiceRegistration<EncryptionService> basicEncryptionServiceServiceRegistration;
+ private ServiceRegistration karafRealmServiceRegistration;
+
+ @Override
+ public void start(BundleContext context) throws Exception {
+ propertiesBackingEngineFactoryServiceRegistration =
+ context.registerService(BackingEngineFactory.class, new PropertiesBackingEngineFactory(), null);
+
+ Hashtable<String, Object> props = new Hashtable<String, Object>();
+ props.put(Constants.SERVICE_RANKING, -1);
+ props.put("name", "basic");
+ basicEncryptionServiceServiceRegistration =
+ context.registerService(EncryptionService.class, new BasicEncryptionService(), props);
+
+ props = new Hashtable<String, Object>();
+ props.put(Constants.SERVICE_PID, "org.apache.karaf.jaas");
+ karafRealmServiceRegistration =
+ context.registerService(new String[] {
+ JaasRealm.class.getName(),
+ ManagedService.class.getName()
+ }, new KarafRealm(context), props);
+ }
+
+ @Override
+ public void stop(BundleContext context) throws Exception {
+ karafRealmServiceRegistration.unregister();
+ basicEncryptionServiceServiceRegistration.unregister();
+ propertiesBackingEngineFactoryServiceRegistration.unregister();
+ }
+}
http://git-wip-us.apache.org/repos/asf/karaf/blob/5e2f19c4/jaas/modules/src/main/java/org/apache/karaf/jaas/modules/impl/KarafRealm.java
----------------------------------------------------------------------
diff --git a/jaas/modules/src/main/java/org/apache/karaf/jaas/modules/impl/KarafRealm.java b/jaas/modules/src/main/java/org/apache/karaf/jaas/modules/impl/KarafRealm.java
new file mode 100644
index 0000000..ecbcc1e
--- /dev/null
+++ b/jaas/modules/src/main/java/org/apache/karaf/jaas/modules/impl/KarafRealm.java
@@ -0,0 +1,109 @@
+/*
+ * 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.modules.impl;
+
+import org.apache.karaf.jaas.boot.ProxyLoginModule;
+import org.apache.karaf.jaas.config.JaasRealm;
+import org.osgi.framework.BundleContext;
+import org.osgi.service.cm.ConfigurationException;
+import org.osgi.service.cm.ManagedService;
+
+import javax.security.auth.login.AppConfigurationEntry;
+import java.io.File;
+import java.util.ArrayList;
+import java.util.Dictionary;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+public class KarafRealm implements JaasRealm, ManagedService {
+
+ private static final String KARAF_ETC = System.getProperty("karaf.base") + File.separatorChar + "etc";
+ private static final String REALM = "karaf";
+ private static final String PROPERTIES_MODULE = "org.apache.karaf.jaas.modules.properties.PropertiesLoginModule";
+ private static final String PUBLIC_KEY_MODULE = "org.apache.karaf.jaas.modules.publickey.PublickeyLoginModule";
+
+ private static final String ENCRYPTION_NAME = "encryption.name";
+ private static final String ENCRYPTION_ENABLED = "encryption.enabled";
+ private static final String ENCRYPTION_PREFIX = "encryption.prefix";
+ private static final String ENCRYPTION_SUFFIX = "encryption.suffix";
+ private static final String ENCRYPTION_ALGORITHM = "encryption.algorithm";
+ private static final String ENCRYPTION_ENCODING = "encryption.encoding";
+ private static final String MODULE = "org.apache.karaf.jaas.module";
+
+ private final BundleContext bundleContext;
+ private volatile Map<String, Object> properties;
+
+ public KarafRealm(BundleContext bundleContext) {
+ this.bundleContext = bundleContext;
+ this.properties = new HashMap<String, Object>();
+ populateDefault(this.properties);
+ }
+
+ private void populateDefault(Map<String, Object> props) {
+ props.put("detailed.login.exception", "false");
+ props.put(ENCRYPTION_NAME, "");
+ props.put(ENCRYPTION_ENABLED, "false");
+ props.put(ENCRYPTION_PREFIX, "{CRYPT}");
+ props.put(ENCRYPTION_SUFFIX, "{CRYPT}");
+ props.put(ENCRYPTION_ALGORITHM, "MD5");
+ props.put(ENCRYPTION_ENCODING, "hexadecimal");
+ }
+
+ @Override
+ public void updated(Dictionary<String, ?> properties) throws ConfigurationException {
+ Map<String, Object> props = new HashMap<String, Object>();
+ populateDefault(props);
+ for (Enumeration<String> keyEnum = properties.keys(); keyEnum.hasMoreElements(); ) {
+ String key = keyEnum.nextElement();
+ props.put(key, properties.get(key));
+ }
+ this.properties = props;
+ }
+
+ @Override
+ public String getName() {
+ return REALM;
+ }
+
+ @Override
+ public int getRank() {
+ return 0;
+ }
+
+ @Override
+ public AppConfigurationEntry[] getEntries() {
+ Map<String, Object> propertiesOptions = new HashMap<String, Object>();
+ propertiesOptions.putAll(properties);
+ propertiesOptions.put(BundleContext.class.getName(), bundleContext);
+ propertiesOptions.put(ProxyLoginModule.PROPERTY_MODULE, PROPERTIES_MODULE);
+ propertiesOptions.put(ProxyLoginModule.PROPERTY_BUNDLE, Long.toString(bundleContext.getBundle().getBundleId()));
+ propertiesOptions.put("users", KARAF_ETC + File.separatorChar + "users.properties");
+
+ Map<String, Object> publicKeyOptions = new HashMap<String, Object>();
+ publicKeyOptions.putAll(properties);
+ publicKeyOptions.put(BundleContext.class.getName(), bundleContext);
+ publicKeyOptions.put(ProxyLoginModule.PROPERTY_MODULE, PUBLIC_KEY_MODULE);
+ publicKeyOptions.put(ProxyLoginModule.PROPERTY_BUNDLE, Long.toString(bundleContext.getBundle().getBundleId()));
+ publicKeyOptions.put("users", KARAF_ETC + File.separatorChar + "keys.properties");
+
+ return new AppConfigurationEntry[] {
+ new AppConfigurationEntry(ProxyLoginModule.class.getName(), AppConfigurationEntry.LoginModuleControlFlag.SUFFICIENT, propertiesOptions),
+ new AppConfigurationEntry(ProxyLoginModule.class.getName(), AppConfigurationEntry.LoginModuleControlFlag.SUFFICIENT, publicKeyOptions)
+ };
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/karaf/blob/5e2f19c4/jaas/modules/src/main/java/org/apache/karaf/jaas/modules/properties/PropertiesConverter.java
----------------------------------------------------------------------
diff --git a/jaas/modules/src/main/java/org/apache/karaf/jaas/modules/properties/PropertiesConverter.java b/jaas/modules/src/main/java/org/apache/karaf/jaas/modules/properties/PropertiesConverter.java
deleted file mode 100644
index 6a833bf..0000000
--- a/jaas/modules/src/main/java/org/apache/karaf/jaas/modules/properties/PropertiesConverter.java
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
- * 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.modules.properties;
-
-import org.osgi.service.blueprint.container.Converter;
-import org.osgi.service.blueprint.container.ReifiedType;
-
-import java.util.Properties;
-
-/**
- * Custom converter to transform a string into a Properties instance.
- * (to avoid removing \ from the values as is done by the default blueprint converter)
- */
-public class PropertiesConverter implements Converter {
-
- public boolean canConvert(Object from, ReifiedType type) {
- return String.class.isAssignableFrom(from.getClass())
- && Properties.class.equals(type.getRawClass());
- }
-
- public Object convert(Object from, ReifiedType type) throws Exception {
- Properties properties = new Properties();
-
- String text = (String) from;
- for (String line : text.split("[\\r\\n]+")) {
- int index = line.indexOf('=');
- if (index > 0) {
- String key = line.substring(0, index).trim();
- String value = line.substring(index + 1).trim();
- properties.put(key, value.replaceAll("\\\\", "/"));
- }
- }
-
- return properties;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/karaf/blob/5e2f19c4/jaas/modules/src/main/resources/OSGI-INF/blueprint/karaf-jaas-module.xml
----------------------------------------------------------------------
diff --git a/jaas/modules/src/main/resources/OSGI-INF/blueprint/karaf-jaas-module.xml b/jaas/modules/src/main/resources/OSGI-INF/blueprint/karaf-jaas-module.xml
deleted file mode 100644
index b079902..0000000
--- a/jaas/modules/src/main/resources/OSGI-INF/blueprint/karaf-jaas-module.xml
+++ /dev/null
@@ -1,75 +0,0 @@
-<?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:jaas="http://karaf.apache.org/xmlns/jaas/v1.0.0"
- xmlns:cm="http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.1.0"
- xmlns:ext="http://aries.apache.org/blueprint/xmlns/blueprint-ext/v1.0.0">
-
- <type-converters>
- <bean class="org.apache.karaf.jaas.modules.properties.PropertiesConverter"/>
- </type-converters>
-
- <!-- Allow usage of System properties, especially the karaf.base property -->
- <ext:property-placeholder placeholder-prefix="$[" placeholder-suffix="]"/>
-
- <!-- AdminConfig property place holder for the org.apache.karaf.jaas -->
- <cm:property-placeholder persistent-id="org.apache.karaf.jaas" update-strategy="reload">
- <cm:default-properties>
- <cm:property name="detailed.login.exception" value="false"/>
- <cm:property name="encryption.name" value=""/>
- <cm:property name="encryption.enabled" value="false"/>
- <cm:property name="encryption.prefix" value="{CRYPT}"/>
- <cm:property name="encryption.suffix" value="{CRYPT}"/>
- <cm:property name="encryption.algorithm" value="MD5"/>
- <cm:property name="encryption.encoding" value="hexadecimal"/>
- </cm:default-properties>
- </cm:property-placeholder>
-
- <jaas:config name="karaf">
- <jaas:module className="org.apache.karaf.jaas.modules.properties.PropertiesLoginModule" flags="sufficient">
- users = $[karaf.etc]/users.properties
- detailed.login.exception = ${detailed.login.exception}
- encryption.name = ${encryption.name}
- encryption.enabled = ${encryption.enabled}
- encryption.prefix = ${encryption.prefix}
- encryption.suffix = ${encryption.suffix}
- encryption.algorithm = ${encryption.algorithm}
- encryption.encoding = ${encryption.encoding}
- </jaas:module>
- <jaas:module className="org.apache.karaf.jaas.modules.publickey.PublickeyLoginModule" flags="sufficient">
- users = $[karaf.etc]/keys.properties
- detailed.login.exception = ${detailed.login.exception}
- </jaas:module>
- </jaas:config>
-
-
- <!-- The Backing Engine Factory Service for the PropertiesLoginModule -->
- <service interface="org.apache.karaf.jaas.modules.BackingEngineFactory">
- <bean class="org.apache.karaf.jaas.modules.properties.PropertiesBackingEngineFactory"/>
- </service>
-
- <service interface="org.apache.karaf.jaas.modules.EncryptionService" ranking="-1">
- <service-properties>
- <entry key="name" value="basic"/>
- </service-properties>
- <bean class="org.apache.karaf.jaas.modules.encryption.BasicEncryptionService"/>
- </service>
-
-</blueprint>
http://git-wip-us.apache.org/repos/asf/karaf/blob/5e2f19c4/jaas/modules/src/test/java/org/apache/karaf/jaas/modules/properties/PropertiesConverterTest.java
----------------------------------------------------------------------
diff --git a/jaas/modules/src/test/java/org/apache/karaf/jaas/modules/properties/PropertiesConverterTest.java b/jaas/modules/src/test/java/org/apache/karaf/jaas/modules/properties/PropertiesConverterTest.java
deleted file mode 100644
index 0156ef8..0000000
--- a/jaas/modules/src/test/java/org/apache/karaf/jaas/modules/properties/PropertiesConverterTest.java
+++ /dev/null
@@ -1,66 +0,0 @@
-/*
- * 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.modules.properties;
-
-import junit.framework.TestCase;
-import org.osgi.service.blueprint.container.ReifiedType;
-
-import java.util.Properties;
-import java.util.List;
-
-/**
- * Test cases for {@link org.apache.karaf.jaas.modules.properties.PropertiesConverter}
- */
-public class PropertiesConverterTest extends TestCase {
-
- private PropertiesConverter converter;
-
- public void setUp() {
- converter = new PropertiesConverter();
- }
-
- /*
- * Test the canConvert method
- */
- public void testCanConvert() {
- assertTrue(converter.canConvert("a string", new ReifiedType(Properties.class)));
- assertFalse(converter.canConvert(new Object(), new ReifiedType(Properties.class)));
- assertFalse(converter.canConvert("a string", new ReifiedType(List.class)));
- }
-
- /*
- * Test the convert method when dealing with unix paths (no \)
- */
- public void testConvertWithUnixPathNames() throws Exception {
- Properties properties =
- (Properties) converter.convert("users = /opt/karaf/etc/users.properties",
- new ReifiedType(Properties.class));
- assertNotNull(properties);
- assertEquals("/opt/karaf/etc/users.properties", properties.get("users"));
- }
-
- /*
- * Test the convert method when dealing with windows paths (avoid escaping \)
- */
- public void testConvertWithWindowsPathNames() throws Exception {
- Properties properties =
- (Properties) converter.convert("users = c:\\opt\\karaf/etc/users.properties",
- new ReifiedType(Properties.class));
- assertNotNull(properties);
- assertEquals("c:/opt/karaf/etc/users.properties", properties.get("users"));
- }
-}
http://git-wip-us.apache.org/repos/asf/karaf/blob/5e2f19c4/jaas/pom.xml
----------------------------------------------------------------------
diff --git a/jaas/pom.xml b/jaas/pom.xml
index 0a96bf8..1709e21 100644
--- a/jaas/pom.xml
+++ b/jaas/pom.xml
@@ -39,6 +39,7 @@
<module>modules</module>
<module>jasypt</module>
<module>command</module>
+ <module>blueprint</module>
</modules>
</project>
http://git-wip-us.apache.org/repos/asf/karaf/blob/5e2f19c4/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index 7e90888..73c068b 100644
--- a/pom.xml
+++ b/pom.xml
@@ -695,6 +695,16 @@
<artifactId>org.apache.karaf.jaas.modules</artifactId>
<version>${project.version}</version>
</dependency>
+ <dependency>
+ <groupId>org.apache.karaf.jaas.blueprint</groupId>
+ <artifactId>org.apache.karaf.jaas.blueprint.config</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.karaf.jaas.blueprint</groupId>
+ <artifactId>org.apache.karaf.jaas.blueprint.jasypt</artifactId>
+ <version>${project.version}</version>
+ </dependency>
<dependency>
<groupId>org.apache.karaf.webconsole</groupId>