提交 bb945d38 编写于 作者: Y Yuta Mochizuki 提交者: Matteo Merli

Add System Property Option for Athenz (#2707)

上级 24749e16
......@@ -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);
}
......
......@@ -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;
......@@ -63,6 +64,20 @@ public class AuthenticationProviderAthenzTest {
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 {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册