use of com.yahoo.athenz.zms.ZMSClient in project athenz by yahoo.
the class ZMSFileChangeLogStoreTest method getSignedDomainListOneBadDomain.
@Test
public void getSignedDomainListOneBadDomain() {
ZMSFileChangeLogStore fstore = new ZMSFileChangeLogStore(FSTORE_PATH, null, null);
ZMSClient zmsClient = Mockito.mock(ZMSClient.class);
DomainData domData1 = new DomainData().setName("athenz");
SignedDomain domain1 = new SignedDomain().setDomain(domData1);
DomainData domData2 = new DomainData().setName("sports");
SignedDomain domain2 = new SignedDomain().setDomain(domData2);
List<SignedDomain> domains = new ArrayList<>();
domains.add(domain1);
domains.add(domain2);
SignedDomains domainList = new SignedDomains().setDomains(domains);
List<SignedDomain> mockDomains = new ArrayList<>();
mockDomains.add(domain1);
SignedDomains mockDomainList = new SignedDomains().setDomains(mockDomains);
Mockito.when(zmsClient.getSignedDomains("athenz", null, null, null)).thenReturn(mockDomainList);
Mockito.when(zmsClient.getSignedDomains("sports", null, null, null)).thenReturn(null);
List<SignedDomain> returnList = fstore.getSignedDomainList(zmsClient, domainList);
assertEquals(returnList.size(), 1);
assertEquals(returnList.get(0).getDomain().getName(), "athenz");
}
use of com.yahoo.athenz.zms.ZMSClient in project athenz by yahoo.
the class ZMSFileChangeLogStore method getUpdatedSignedDomains.
@Override
public SignedDomains getUpdatedSignedDomains(StringBuilder lastModTimeBuffer) {
try (ZMSClient zmsClient = getZMSClient()) {
// request all the changes from ZMS. In this call we're asking for
// meta data only so we'll only get the list of domains
Map<String, List<String>> responseHeaders = new HashMap<String, List<String>>();
SignedDomains domainList = zmsClient.getSignedDomains(null, VALUE_TRUE, lastModTime, responseHeaders);
// retrieve the tag value for the request
String newLastModTime = retrieveTagHeader(responseHeaders);
if (newLastModTime == null) {
return null;
}
// set the last modification time to be returned to the caller
lastModTimeBuffer.setLength(0);
lastModTimeBuffer.append(newLastModTime);
if (domainList == null || domainList.getDomains() == null) {
return null;
}
if (LOGGER.isInfoEnabled()) {
LOGGER.info("getUpdatedSignedDomains: {} updated domains", domainList.getDomains().size());
}
List<SignedDomain> domains = getSignedDomainList(zmsClient, domainList);
return new SignedDomains().setDomains(domains);
} catch (ZMSClientException ex) {
LOGGER.error("Error when refreshing data from ZMS: {}", ex.getMessage());
return null;
}
}
use of com.yahoo.athenz.zms.ZMSClient in project athenz by yahoo.
the class ZMSTLSClient method main.
public static void main(String[] args) {
// parse our command line to retrieve required input
CommandLine cmd = parseCommandLine(args);
final String resource = cmd.getOptionValue("resource").toLowerCase();
final String action = cmd.getOptionValue("action").toLowerCase();
final String principal = cmd.getOptionValue("principal").toLowerCase();
final String zmsUrl = cmd.getOptionValue("zmsurl");
final String keyPath = cmd.getOptionValue("key");
final String certPath = cmd.getOptionValue("cert");
final String trustStorePath = cmd.getOptionValue("trustStorePath");
final String trustStorePassword = cmd.getOptionValue("trustStorePassword");
try {
KeyRefresher keyRefresher = Utils.generateKeyRefresher(trustStorePath, trustStorePassword, certPath, keyPath);
SSLContext sslContext = Utils.buildSSLContext(keyRefresher.getKeyManagerProxy(), keyRefresher.getTrustManagerProxy());
try (ZMSClient zmsClient = new ZMSClient(zmsUrl, sslContext)) {
try {
Access access = zmsClient.getAccess(action, resource, null, principal);
System.out.println("Access: " + access.getGranted());
} catch (ZMSClientException ex) {
System.out.println("Unable to carry out access check: " + ex.getMessage());
System.exit(2);
}
}
} catch (Exception ex) {
System.out.println("Exception: " + ex.getMessage());
ex.printStackTrace();
System.exit(1);
}
}
use of com.yahoo.athenz.zms.ZMSClient in project athenz by yahoo.
the class ZMSFileChangeLogStore method getZMSClient.
ZMSClient getZMSClient() {
PrincipalToken token = new PrincipalToken.Builder("S1", ZTSConsts.ATHENZ_SYS_DOMAIN, ZTSConsts.ZTS_SERVICE).expirationWindow(24 * 60 * 60L).keyId(privateKeyId).build();
token.sign(privateKey);
Principal principal = SimplePrincipal.create(ZTSConsts.ATHENZ_SYS_DOMAIN, ZTSConsts.ZTS_SERVICE, token.getSignedToken(), authority);
ZMSClient zmsClient = new ZMSClient(zmsUrl);
zmsClient.addCredentials(principal);
return zmsClient;
}
use of com.yahoo.athenz.zms.ZMSClient in project athenz by yahoo.
the class ZMSFileChangeLogStoreTest method getSignedDomainList.
@Test
public void getSignedDomainList() {
ZMSFileChangeLogStore fstore = new ZMSFileChangeLogStore(FSTORE_PATH, null, null);
ZMSClient zmsClient = Mockito.mock(ZMSClient.class);
List<SignedDomain> domains = new ArrayList<>();
DomainData domData = new DomainData().setName("athenz");
SignedDomain domain = new SignedDomain().setDomain(domData);
domains.add(domain);
SignedDomains domainList = new SignedDomains().setDomains(domains);
Mockito.when(zmsClient.getSignedDomains("athenz", null, null, null)).thenReturn(domainList);
List<SignedDomain> returnList = fstore.getSignedDomainList(zmsClient, domainList);
assertEquals(returnList.size(), 1);
assertEquals(returnList.get(0).getDomain().getName(), "athenz");
}
Aggregations