pulsar-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mme...@apache.org
Subject [pulsar] branch master updated: Add System Property Option for Athenz (#2707)
Date Thu, 04 Oct 2018 16:59:12 GMT
This is an automated email from the ASF dual-hosted git repository.

mmerli pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/pulsar.git


The following commit(s) were added to refs/heads/master by this push:
     new bb945d3  Add System Property Option for Athenz (#2707)
bb945d3 is described below

commit bb945d388ebf04fee3583680e5ee86988b131e26
Author: Yuta Mochizuki <41100271+yumochiz@users.noreply.github.com>
AuthorDate: Fri Oct 5 01:59:08 2018 +0900

    Add System Property Option for Athenz (#2707)
---
 .../authentication/AuthenticationProviderAthenz.java      | 12 ++++++++++--
 .../authentication/AuthenticationProviderAthenzTest.java  | 15 +++++++++++++++
 2 files changed, 25 insertions(+), 2 deletions(-)

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 3a00c20..c2cf45d 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 java.security.PublicKey;
 
 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 @@ public class AuthenticationProviderAthenz implements AuthenticationProvider
{
 
     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 75934b1..1946a01 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 @@ package org.apache.pulsar.broker.authentication;
 
 import static org.testng.Assert.assertEquals;
 import static org.testng.Assert.fail;
+
 import org.testng.annotations.Test;
 import org.testng.annotations.BeforeClass;
 
@@ -64,6 +65,20 @@ public class AuthenticationProviderAthenzTest {
     }
 
     @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 {
 
         List<String> roles = new ArrayList<String>() {


Mime
View raw message