Repository: deltaspike
Updated Branches:
  refs/heads/master 0208611fb -> 3d7c3804b


DELTASPIKE-842 pickup ConfigFilters via ServiceLoader

in addition to manually adding it via ConfigResolver


Project: http://git-wip-us.apache.org/repos/asf/deltaspike/repo
Commit: http://git-wip-us.apache.org/repos/asf/deltaspike/commit/3d7c3804
Tree: http://git-wip-us.apache.org/repos/asf/deltaspike/tree/3d7c3804
Diff: http://git-wip-us.apache.org/repos/asf/deltaspike/diff/3d7c3804

Branch: refs/heads/master
Commit: 3d7c3804b96f6b63c139568bf3c6a497429090b3
Parents: 0208611
Author: Mark Struberg <[email protected]>
Authored: Fri Feb 27 15:44:04 2015 +0100
Committer: Mark Struberg <[email protected]>
Committed: Fri Feb 27 15:44:59 2015 +0100

----------------------------------------------------------------------
 .../core/api/config/ConfigResolver.java         |  6 +++
 .../core/spi/config/ConfigFilter.java           |  8 +++-
 .../test/api/config/ConfigResolverTest.java     |  1 -
 .../config/DefaultConfigSourceProvider.java     |  5 +++
 .../test/core/api/config/ConfigSourceTest.java  |  8 ++++
 .../core/api/config/SecretTestConfigFilter.java | 45 ++++++++++++++++++++
 .../META-INF/apache-deltaspike.properties       |  3 ++
 ...ache.deltaspike.core.spi.config.ConfigFilter | 20 +++++++++
 8 files changed, 93 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/deltaspike/blob/3d7c3804/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/config/ConfigResolver.java
----------------------------------------------------------------------
diff --git 
a/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/config/ConfigResolver.java
 
b/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/config/ConfigResolver.java
index 2449004..836932d 100644
--- 
a/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/config/ConfigResolver.java
+++ 
b/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/config/ConfigResolver.java
@@ -421,6 +421,12 @@ public final class ConfigResolver
             appConfigSources.addAll(configSourceProvider.getConfigSources());
         }
 
+        List<? extends ConfigFilter> configFilters = 
ServiceUtils.loadServiceImplementations(ConfigFilter.class);
+        for (ConfigFilter configFilter : configFilters)
+        {
+            addConfigFilter(configFilter);
+        }
+
         return appConfigSources;
     }
 

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/3d7c3804/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/spi/config/ConfigFilter.java
----------------------------------------------------------------------
diff --git 
a/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/spi/config/ConfigFilter.java
 
b/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/spi/config/ConfigFilter.java
index 5f851e2..d3f171b 100644
--- 
a/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/spi/config/ConfigFilter.java
+++ 
b/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/spi/config/ConfigFilter.java
@@ -19,10 +19,14 @@
 package org.apache.deltaspike.core.spi.config;
 
 /**
- * A filter which can be added to the
+ * <p>A filter which can be added to the
  * {@link org.apache.deltaspike.core.api.config.ConfigResolver}.
  * The filter can be used to decrypt config values or prepare
- * values for logging.
+ * values for logging.</p>
+ *
+ * <p>Registering a {@code ConfigFilter} can either be done via the
+ * {@code java.util.ServiceLoader} pattern or by manually adding it via
+ * {@link 
org.apache.deltaspike.core.api.config.ConfigResolver#addConfigFilter(ConfigFilter)}.</p>
  */
 public interface ConfigFilter
 {

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/3d7c3804/deltaspike/core/api/src/test/java/org/apache/deltaspike/test/api/config/ConfigResolverTest.java
----------------------------------------------------------------------
diff --git 
a/deltaspike/core/api/src/test/java/org/apache/deltaspike/test/api/config/ConfigResolverTest.java
 
b/deltaspike/core/api/src/test/java/org/apache/deltaspike/test/api/config/ConfigResolverTest.java
index 1f23a21..f8b4313 100644
--- 
a/deltaspike/core/api/src/test/java/org/apache/deltaspike/test/api/config/ConfigResolverTest.java
+++ 
b/deltaspike/core/api/src/test/java/org/apache/deltaspike/test/api/config/ConfigResolverTest.java
@@ -114,7 +114,6 @@ public class ConfigResolverTest
     @Test
     public void testConfigFilter()
     {
-
         ConfigFilter configFilter = new TestConfigFilter();
 
         Assert.assertEquals("shouldGetDecrypted: value", 
configFilter.filterValue("somekey.encrypted", "value"));

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/3d7c3804/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/config/DefaultConfigSourceProvider.java
----------------------------------------------------------------------
diff --git 
a/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/config/DefaultConfigSourceProvider.java
 
b/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/config/DefaultConfigSourceProvider.java
index e813019..500839d 100644
--- 
a/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/config/DefaultConfigSourceProvider.java
+++ 
b/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/config/DefaultConfigSourceProvider.java
@@ -57,6 +57,11 @@ public class DefaultConfigSourceProvider implements 
ConfigSourceProvider
         registerPropertyFileConfigs();
     }
 
+
+    /**
+     * Load all {@link PropertyFileConfig}s which are registered via
+     * {@code java.util.ServiceLoader}.
+     */
     private void registerPropertyFileConfigs()
     {
         List<? extends PropertyFileConfig> propertyFileConfigs =

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/3d7c3804/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/api/config/ConfigSourceTest.java
----------------------------------------------------------------------
diff --git 
a/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/api/config/ConfigSourceTest.java
 
b/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/api/config/ConfigSourceTest.java
index 79aa6ba..c3f62a7 100644
--- 
a/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/api/config/ConfigSourceTest.java
+++ 
b/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/api/config/ConfigSourceTest.java
@@ -86,5 +86,13 @@ public class ConfigSourceTest
         Assert.assertEquals(value, configuredValue);
     }
 
+    @Test
+    public void testConfigFilter()
+    {
+        String secretVal = ConfigResolver.getPropertyValue("my.very.secret");
+        Assert.assertNotNull(secretVal);
+        Assert.assertEquals("a secret value: onlyIDoKnowIt", secretVal);
+    }
+
 
 }

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/3d7c3804/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/api/config/SecretTestConfigFilter.java
----------------------------------------------------------------------
diff --git 
a/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/api/config/SecretTestConfigFilter.java
 
b/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/api/config/SecretTestConfigFilter.java
new file mode 100644
index 0000000..3c85746
--- /dev/null
+++ 
b/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/api/config/SecretTestConfigFilter.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.deltaspike.test.core.api.config;
+
+import org.apache.deltaspike.core.spi.config.ConfigFilter;
+
+/**
+ * a test ConfigFilter which decrypts the secret message
+ */
+public class SecretTestConfigFilter implements ConfigFilter
+{
+    @Override
+    public String filterValue(String key, String value)
+    {
+        if (key.contains("secret"))
+        {
+            return "a secret value: " + value;
+        }
+        return value;
+    }
+
+    @Override
+    public String filterValueForLog(String key, String value)
+    {
+        if (key.contains("secret"))
+        {
+            return "**********";
+        }
+        return null;
+    }
+}

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/3d7c3804/deltaspike/core/impl/src/test/resources/META-INF/apache-deltaspike.properties
----------------------------------------------------------------------
diff --git 
a/deltaspike/core/impl/src/test/resources/META-INF/apache-deltaspike.properties 
b/deltaspike/core/impl/src/test/resources/META-INF/apache-deltaspike.properties
index ba29086..e79bc48 100644
--- 
a/deltaspike/core/impl/src/test/resources/META-INF/apache-deltaspike.properties
+++ 
b/deltaspike/core/impl/src/test/resources/META-INF/apache-deltaspike.properties
@@ -39,3 +39,6 @@ configPropertyTrue8=1
 
 # NumberConfig
 propertyFloat=123.45
+
+
+my.very.secret=onlyIDoKnowIt
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/3d7c3804/deltaspike/core/impl/src/test/resources/META-INF/services/org.apache.deltaspike.core.spi.config.ConfigFilter
----------------------------------------------------------------------
diff --git 
a/deltaspike/core/impl/src/test/resources/META-INF/services/org.apache.deltaspike.core.spi.config.ConfigFilter
 
b/deltaspike/core/impl/src/test/resources/META-INF/services/org.apache.deltaspike.core.spi.config.ConfigFilter
new file mode 100644
index 0000000..411d3fc
--- /dev/null
+++ 
b/deltaspike/core/impl/src/test/resources/META-INF/services/org.apache.deltaspike.core.spi.config.ConfigFilter
@@ -0,0 +1,20 @@
+#####################################################################################
+# 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.
+#####################################################################################
+
+org.apache.deltaspike.test.core.api.config.SecretTestConfigFilter
\ No newline at end of file

Reply via email to