FELIX-1641: Unable to connect to Karaf with ssh on Windows

git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@818650 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/karaf/jaas/modules/pom.xml b/karaf/jaas/modules/pom.xml
index cc5da4a..1fb8992 100644
--- a/karaf/jaas/modules/pom.xml
+++ b/karaf/jaas/modules/pom.xml
@@ -67,6 +67,11 @@
             <groupId>org.springframework.osgi</groupId>
             <artifactId>spring-osgi-core</artifactId>
         </dependency>
+
+        <dependency>
+            <groupId>org.apache.geronimo.blueprint</groupId>
+            <artifactId>geronimo-blueprint</artifactId>
+        </dependency>        
     </dependencies>
 
     <build>
diff --git a/karaf/jaas/modules/src/main/java/org/apache/felix/karaf/jaas/modules/properties/PropertiesConverter.java b/karaf/jaas/modules/src/main/java/org/apache/felix/karaf/jaas/modules/properties/PropertiesConverter.java
new file mode 100644
index 0000000..b8dc6ee
--- /dev/null
+++ b/karaf/jaas/modules/src/main/java/org/apache/felix/karaf/jaas/modules/properties/PropertiesConverter.java
@@ -0,0 +1,50 @@
+/*
+ * 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.felix.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;
+    }
+}
diff --git a/karaf/jaas/modules/src/main/resources/OSGI-INF/blueprint/karaf-jaas-module.xml b/karaf/jaas/modules/src/main/resources/OSGI-INF/blueprint/karaf-jaas-module.xml
index 6c39da0..d7747d9 100644
--- a/karaf/jaas/modules/src/main/resources/OSGI-INF/blueprint/karaf-jaas-module.xml
+++ b/karaf/jaas/modules/src/main/resources/OSGI-INF/blueprint/karaf-jaas-module.xml
@@ -21,6 +21,10 @@
            xmlns:jaas="http://felix.apache.org/karaf/xmlns/jaas/v1.0.0"
            xmlns:ext="http://geronimo.apache.org/blueprint/xmlns/blueprint-ext/v1.0.0">
 
+    <type-converters>
+        <bean class="org.apache.felix.karaf.jaas.modules.properties.PropertiesConverter" />
+    </type-converters>
+
     <!-- Bean to allow the $[karaf.base] property to be correctly resolved -->
     <ext:property-placeholder placeholder-prefix="$[" placeholder-suffix="]"/>
 
diff --git a/karaf/jaas/modules/src/test/java/org/apache/felix/karaf/jaas/modules/properties/PropertiesConverterTest.java b/karaf/jaas/modules/src/test/java/org/apache/felix/karaf/jaas/modules/properties/PropertiesConverterTest.java
new file mode 100644
index 0000000..d3cbed4
--- /dev/null
+++ b/karaf/jaas/modules/src/test/java/org/apache/felix/karaf/jaas/modules/properties/PropertiesConverterTest.java
@@ -0,0 +1,66 @@
+/*
+ * 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.felix.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.felix.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"));
+    }
+}