FELIX-3533 strip out private . properties when a lifecycle method returns service properties

git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1346209 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/scr/src/main/java/org/apache/felix/scr/impl/manager/ImmediateComponentManager.java b/scr/src/main/java/org/apache/felix/scr/impl/manager/ImmediateComponentManager.java
index 2bc619f..6b8eac7 100644
--- a/scr/src/main/java/org/apache/felix/scr/impl/manager/ImmediateComponentManager.java
+++ b/scr/src/main/java/org/apache/felix/scr/impl/manager/ImmediateComponentManager.java
@@ -370,7 +370,7 @@
         }
         else
         {
-            m_serviceProperties = copyTo(null, serviceProperties);
+            m_serviceProperties = copyTo(null, serviceProperties, false);
             // set component.name and component.id
             m_serviceProperties.put( ComponentConstants.COMPONENT_NAME, getComponentMetadata().getName() );
             m_serviceProperties.put( ComponentConstants.COMPONENT_ID, new Long( getId() ) );
diff --git a/scr/src/test/java/org/apache/felix/scr/integration/MutablePropertiesTest.java b/scr/src/test/java/org/apache/felix/scr/integration/MutablePropertiesTest.java
index b225ed8..05a8b08 100644
--- a/scr/src/test/java/org/apache/felix/scr/integration/MutablePropertiesTest.java
+++ b/scr/src/test/java/org/apache/felix/scr/integration/MutablePropertiesTest.java
@@ -51,11 +51,12 @@
     @Test
     public void test_mutable_properties() throws InvalidSyntaxException
     {
-        final Component component = findComponentByName( "components.mutable.properties" );
+        String componentName = "components.mutable.properties";
+        final Component component = findComponentByName( componentName );
         TestCase.assertNotNull( component );
         TestCase.assertEquals( Component.STATE_REGISTERED, component.getState() );
 
-        ServiceReference[] serviceReferences = bundleContext.getServiceReferences( MutatingService.class.getName(), "(service.pid=components.mutable.properties)" );
+        ServiceReference[] serviceReferences = bundleContext.getServiceReferences( MutatingService.class.getName(), "(service.pid=" + componentName + ")" );
         TestCase.assertEquals( 1, serviceReferences.length );
         ServiceReference serviceReference = serviceReferences[0];
         checkProperties( serviceReference, 8, "otherValue", "p1", "p2" );
@@ -69,7 +70,7 @@
         checkProperties(serviceReference, 5, "anotherValue", "p1", "p2");
 
         //configure with configAdmin
-        configure( "components.mutable.properties" );
+        configure( componentName );
         delay();
         //no change
         checkProperties(serviceReference, 5, "anotherValue", "p1", "p2");
@@ -84,11 +85,12 @@
     @Test
     public void test_mutable_properties_returned() throws InvalidSyntaxException
     {
-        final Component component = findComponentByName( "components.mutable.properties.return" );
+        String componentName = "components.mutable.properties.return";
+        final Component component = findComponentByName( componentName );
         TestCase.assertNotNull( component );
         TestCase.assertEquals( Component.STATE_REGISTERED, component.getState() );
 
-        ServiceReference[] serviceReferences = bundleContext.getServiceReferences( MutatingService.class.getName(), "(service.pid=components.mutable.properties.return)" );
+        ServiceReference[] serviceReferences = bundleContext.getServiceReferences( MutatingService.class.getName(), "(service.pid=" + componentName + ")" );
         TestCase.assertEquals( 1, serviceReferences.length );
         ServiceReference serviceReference = serviceReferences[0];
         checkProperties( serviceReference, 8, "otherValue", "p1", "p2" );
@@ -103,7 +105,7 @@
         checkProperties(serviceReference, 5, "anotherValue", "p1", "p2");
 
         //configure with configAdmin
-        configure( "components.mutable.properties.return" );
+        configure( componentName );
         delay();
         delay();
         //no change
@@ -115,14 +117,52 @@
 
         bundleContext.ungetService(serviceReference);
     }
+
     @Test
-    public void test_mutable_properties_bind_returned() throws InvalidSyntaxException
+    public void test_mutable_properties_returned_public() throws InvalidSyntaxException
     {
-        final Component component = findComponentByName( "components.mutable.properties.bind" );
+        String componentName = "components.mutable.properties.return.public";
+        final Component component = findComponentByName( componentName );
         TestCase.assertNotNull( component );
         TestCase.assertEquals( Component.STATE_REGISTERED, component.getState() );
 
-        ServiceReference[] serviceReferences = bundleContext.getServiceReferences( MutatingService.class.getName(), "(service.pid=components.mutable.properties.bind)" );
+        ServiceReference[] serviceReferences = bundleContext.getServiceReferences( MutatingService.class.getName(), "(service.pid=" + componentName + ")" );
+        TestCase.assertEquals( 1, serviceReferences.length );
+        ServiceReference serviceReference = serviceReferences[0];
+        checkProperties( serviceReference, 8, "otherValue", "p1", "p2" );
+
+        //update theValue
+        MutatingService s = ( MutatingService ) bundleContext.getService( serviceReference );
+        Assert.assertNotNull(s);
+        checkProperties( serviceReference, 8, "anotherValue1", "p1", "p2" );
+        TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
+        Dictionary d = new Hashtable(Collections.singletonMap( PROP_NAME, "anotherValue" ));
+        s.updateProperties(d);
+        checkProperties(serviceReference, 5, "anotherValue", "p1", "p2");
+
+        //configure with configAdmin
+        configure( componentName );
+        delay();
+        delay();
+        //no change
+        checkProperties(serviceReference, 8, "anotherValue2", "p1", "p2");
+
+        //check that removing config switches back to defaults modified by config admin
+        s.updateProperties(null);
+        checkProperties( serviceReference, 8, "theValue", "p1", "p2" );
+
+        bundleContext.ungetService(serviceReference);
+    }
+
+    @Test
+    public void test_mutable_properties_bind_returned() throws InvalidSyntaxException
+    {
+        String componentName = "components.mutable.properties.bind";
+        final Component component = findComponentByName( componentName );
+        TestCase.assertNotNull( component );
+        TestCase.assertEquals( Component.STATE_REGISTERED, component.getState() );
+
+        ServiceReference[] serviceReferences = bundleContext.getServiceReferences( MutatingService.class.getName(), "(service.pid=" + componentName + ")" );
         TestCase.assertEquals( 1, serviceReferences.length );
         ServiceReference serviceReference = serviceReferences[0];
         checkProperties( serviceReference, 8, "otherValue", "p1", "p2" );
diff --git a/scr/src/test/java/org/apache/felix/scr/integration/components/MutatingServiceImpl.java b/scr/src/test/java/org/apache/felix/scr/integration/components/MutatingServiceImpl.java
index 07554c1..dc69800 100644
--- a/scr/src/test/java/org/apache/felix/scr/integration/components/MutatingServiceImpl.java
+++ b/scr/src/test/java/org/apache/felix/scr/integration/components/MutatingServiceImpl.java
@@ -47,6 +47,10 @@
         this.activateContext = activateContext;
         Map result = new Hashtable( (Map )activateContext.getProperties() );
         result.put( "theValue", "anotherValue1" );
+        if (result.containsKey( ".p2" ))
+        {
+            result.put( ".theValue", "privateValue" );
+        }
         return result;
     }
 
diff --git a/scr/src/test/resources/integration_test_mutable_properties.xml b/scr/src/test/resources/integration_test_mutable_properties.xml
index 08214ef..7b224ac 100644
--- a/scr/src/test/resources/integration_test_mutable_properties.xml
+++ b/scr/src/test/resources/integration_test_mutable_properties.xml
@@ -51,6 +51,24 @@
         <property name="p2" value="p2" />
     </scr:component>
 
+    <scr:component name="components.mutable.properties.return.public"
+            xmlns:scr="http://felix.apache.org/xmlns/scr/v1.2.0-felix"
+            enabled="true"
+            configuration-policy="optional"
+            activate="activateMutate"
+            modified="modifiedMutate"
+            deactivate="deactivateMutate">
+        <implementation class="org.apache.felix.scr.integration.components.MutatingServiceImpl" />
+        <service>
+            <provide interface="org.apache.felix.scr.integration.components.MutatingService" />
+        </service>
+        <property name="service.pid" value="components.mutable.properties.return.public" />
+        <property name="theValue" value="otherValue" />
+        <property name="p1" value="p1" />
+        <property name="p2" value="p2" />
+        <property name=".p2" value="p2" />
+    </scr:component>
+
     <scr:component name="components.mutable.properties.bind"
                    xmlns:scr="http://felix.apache.org/xmlns/scr/v1.2.0-felix"
                    enabled="true"