You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by GitBox <gi...@apache.org> on 2018/10/04 16:59:10 UTC

[GitHub] merlimat closed pull request #2707: Add System Property Option for Athenz

merlimat closed pull request #2707: Add System Property Option for Athenz
URL: https://github.com/apache/pulsar/pull/2707
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/pulsar-broker-auth-athenz/src/main/java/org/apache/pulsar/broker/authentication/AuthenticationProviderAthenz.java b/pulsar-broker-auth-athenz/src/main/java/org/apache/pulsar/broker/authentication/AuthenticationProviderAthenz.java
index 3a00c2022a..c2cf45da15 100644
--- a/pulsar-broker-auth-athenz/src/main/java/org/apache/pulsar/broker/authentication/AuthenticationProviderAthenz.java
+++ b/pulsar-broker-auth-athenz/src/main/java/org/apache/pulsar/broker/authentication/AuthenticationProviderAthenz.java
@@ -25,6 +25,7 @@
 
 import javax.naming.AuthenticationException;
 
+import org.apache.commons.lang3.StringUtils;
 import org.apache.pulsar.broker.authentication.AuthenticationDataSource;
 import org.apache.pulsar.broker.authentication.AuthenticationProvider;
 import org.slf4j.Logger;
@@ -39,14 +40,21 @@
 
     private static final String DOMAIN_NAME_LIST = "athenzDomainNames";
 
+    private static final String SYS_PROP_DOMAIN_NAME_LIST = "pulsar.athenz.domain.names";
+
     private List<String> domainNameList = null;
 
     @Override
     public void initialize(ServiceConfiguration config) throws IOException {
-        if (config.getProperty(DOMAIN_NAME_LIST) == null) {
+        String domainNames;
+        if (config.getProperty(DOMAIN_NAME_LIST) != null) {
+            domainNames = (String) config.getProperty(DOMAIN_NAME_LIST);
+        } else if (!StringUtils.isEmpty(System.getProperty(SYS_PROP_DOMAIN_NAME_LIST))) {
+            domainNames = System.getProperty(SYS_PROP_DOMAIN_NAME_LIST);
+        } else {
             throw new IOException("No athenz domain name specified");
         }
-        String domainNames = (String) config.getProperty(DOMAIN_NAME_LIST);
+
         domainNameList = Lists.newArrayList(domainNames.split(","));
         log.info("Supported domain names for athenz: {}", domainNameList);
     }
diff --git a/pulsar-broker-auth-athenz/src/test/java/org/apache/pulsar/broker/authentication/AuthenticationProviderAthenzTest.java b/pulsar-broker-auth-athenz/src/test/java/org/apache/pulsar/broker/authentication/AuthenticationProviderAthenzTest.java
index 75934b1e98..1946a014e7 100644
--- a/pulsar-broker-auth-athenz/src/test/java/org/apache/pulsar/broker/authentication/AuthenticationProviderAthenzTest.java
+++ b/pulsar-broker-auth-athenz/src/test/java/org/apache/pulsar/broker/authentication/AuthenticationProviderAthenzTest.java
@@ -20,6 +20,7 @@
 
 import static org.testng.Assert.assertEquals;
 import static org.testng.Assert.fail;
+
 import org.testng.annotations.Test;
 import org.testng.annotations.BeforeClass;
 
@@ -63,6 +64,20 @@ public void setup() throws Exception {
         System.setProperty(ZpeConsts.ZPE_PROP_ATHENZ_CONF, "./src/test/resources/athenz.conf.test");
     }
 
+    @Test
+    public void testInitilizeFromSystemPropeties() {
+        System.setProperty("pulsar.athenz.domain.names", "test_provider");
+        ServiceConfiguration emptyConf = new ServiceConfiguration();
+        Properties emptyProp = new Properties();
+        emptyConf.setProperties(emptyProp);
+        AuthenticationProviderAthenz sysPropProvider = new AuthenticationProviderAthenz();
+        try {
+            sysPropProvider.initialize(emptyConf);
+        } catch (Exception e) {
+            fail("Fail to Read pulsar.athenz.domain.names from System Properties");
+        }
+    }
+
     @Test
     public void testAuthenticateSignedToken() throws Exception {
 


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services