Skip to content

Commit

Permalink
Add System Property Option for Athenz (apache#2707)
Browse files Browse the repository at this point in the history
  • Loading branch information
yumochiz authored and merlimat committed Oct 4, 2018
1 parent 24749e1 commit bb945d3
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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 {

Expand Down

0 comments on commit bb945d3

Please sign in to comment.