use of com.yahoo.athenz.zms.ServiceIdentity in project athenz by yahoo.
the class FileConnection method listPublicKeys.
@Override
public List<PublicKeyEntry> listPublicKeys(String domainName, String serviceName) {
DomainStruct domainStruct = getDomainStruct(domainName);
if (domainStruct == null) {
throw ZMSUtils.error(ResourceException.NOT_FOUND, "domain not found", "listPublicKeys");
}
ServiceIdentity service = getServiceObject(domainStruct, serviceName);
if (service == null) {
throw ZMSUtils.error(ResourceException.NOT_FOUND, "service not found", "deletePublicKeyEntry");
}
return service.getPublicKeys();
}
use of com.yahoo.athenz.zms.ServiceIdentity in project athenz by yahoo.
the class JDBCConnectionTest method testGetServiceIdentity.
@Test
public void testGetServiceIdentity() throws Exception {
Mockito.when(mockResultSet.next()).thenReturn(true);
Mockito.doReturn("test description").when(mockResultSet).getString(ZMSConsts.DB_COLUMN_DESCRIPTION);
Mockito.doReturn(new java.sql.Timestamp(1454358916)).when(mockResultSet).getTimestamp(ZMSConsts.DB_COLUMN_MODIFIED);
Mockito.doReturn("").when(mockResultSet).getString(ZMSConsts.DB_COLUMN_EXECTUABLE);
Mockito.doReturn("").when(mockResultSet).getString(ZMSConsts.DB_COLUMN_SVC_GROUP);
Mockito.doReturn("").when(mockResultSet).getString(ZMSConsts.DB_COLUMN_SVC_USER);
Mockito.doReturn("").when(mockResultSet).getString(ZMSConsts.DB_COLUMN_PROVIDER_ENDPOINT);
JDBCConnection jdbcConn = new JDBCConnection(mockConn, true);
ServiceIdentity service = jdbcConn.getServiceIdentity("my-domain", "service1");
assertNotNull(service);
assertEquals("my-domain.service1", service.getName());
assertNull(service.getExecutable());
assertNull(service.getGroup());
assertNull(service.getUser());
assertNull(service.getProviderEndpoint());
Mockito.verify(mockPrepStmt, times(1)).setString(1, "my-domain");
Mockito.verify(mockPrepStmt, times(1)).setString(2, "service1");
jdbcConn.close();
}
use of com.yahoo.athenz.zms.ServiceIdentity in project athenz by yahoo.
the class JDBCConnectionTest method testUpdateServiceIdentityAllFields.
@Test
public void testUpdateServiceIdentityAllFields() throws Exception {
JDBCConnection jdbcConn = new JDBCConnection(mockConn, true);
ServiceIdentity service = new ServiceIdentity().setName("my-domain.service1").setDescription("test service").setExecutable("/usr/bin64/test.sh").setGroup("users").setUser("root").setProviderEndpoint("http://server.athenzcompany.com");
Mockito.doReturn(1).when(mockPrepStmt).executeUpdate();
Mockito.when(mockResultSet.next()).thenReturn(true);
// return domain id
Mockito.when(mockResultSet.getInt(1)).thenReturn(5).thenReturn(// service id
4);
boolean requestSuccess = jdbcConn.updateServiceIdentity("my-domain", service);
assertTrue(requestSuccess);
// get domain id
Mockito.verify(mockPrepStmt, times(1)).setString(1, "my-domain");
// get service id
Mockito.verify(mockPrepStmt, times(1)).setInt(1, 5);
Mockito.verify(mockPrepStmt, times(1)).setString(2, "service1");
// update service
Mockito.verify(mockPrepStmt, times(1)).setString(1, "test service");
Mockito.verify(mockPrepStmt, times(1)).setString(2, "http://server.athenzcompany.com");
Mockito.verify(mockPrepStmt, times(1)).setString(3, "/usr/bin64/test.sh");
Mockito.verify(mockPrepStmt, times(1)).setString(4, "root");
Mockito.verify(mockPrepStmt, times(1)).setString(5, "users");
Mockito.verify(mockPrepStmt, times(1)).setInt(6, 4);
jdbcConn.close();
}
use of com.yahoo.athenz.zms.ServiceIdentity in project athenz by yahoo.
the class JDBCConnectionTest method testUpdateServiceIdentityInvalidName.
@Test
public void testUpdateServiceIdentityInvalidName() throws Exception {
JDBCConnection jdbcConn = new JDBCConnection(mockConn, true);
ServiceIdentity service = new ServiceIdentity().setName("service1");
Mockito.doReturn(1).when(mockPrepStmt).executeUpdate();
Mockito.when(mockResultSet.next()).thenReturn(true);
// return domain id
Mockito.when(mockResultSet.getInt(1)).thenReturn(5).thenReturn(// service id
4);
try {
jdbcConn.updateServiceIdentity("my-domain", service);
fail();
} catch (ResourceException ex) {
assertEquals(400, ex.getCode());
}
jdbcConn.close();
}
use of com.yahoo.athenz.zms.ServiceIdentity in project athenz by yahoo.
the class DataStoreTest method createTenantSignedDomain.
private SignedDomain createTenantSignedDomain(String domainName, String providerDomain) {
SignedDomain signedDomain = new SignedDomain();
List<Role> roles = new ArrayList<>();
Role role = new Role();
role.setName(domainName + ":role.admin");
List<RoleMember> members = new ArrayList<>();
members.add(new RoleMember().setMemberName("user_domain.user"));
role.setRoleMembers(members);
roles.add(role);
role = new Role();
role.setName(domainName + ":role.readers");
members = new ArrayList<>();
members.add(new RoleMember().setMemberName("user_domain.user100"));
members.add(new RoleMember().setMemberName("user_domain.user101"));
role.setRoleMembers(members);
roles.add(role);
List<com.yahoo.athenz.zms.Policy> policies = new ArrayList<>();
com.yahoo.athenz.zms.Policy policy = new com.yahoo.athenz.zms.Policy();
com.yahoo.athenz.zms.Assertion assertion = new com.yahoo.athenz.zms.Assertion();
assertion.setResource(providerDomain + ":role.tenant.readers");
assertion.setAction("assume_role");
assertion.setRole(domainName + ":role.readers");
List<com.yahoo.athenz.zms.Assertion> assertions = new ArrayList<>();
assertions.add(assertion);
policy.setAssertions(assertions);
policy.setName(domainName + ":policy.tenancy.readers");
policies.add(policy);
ServiceIdentity service = new ServiceIdentity();
service.setName(domainName + ".storage");
setServicePublicKey(service, "0", "abcdefgh");
List<String> hosts = new ArrayList<>();
hosts.add("host1");
service.setHosts(hosts);
List<ServiceIdentity> services = new ArrayList<>();
services.add(service);
com.yahoo.athenz.zms.DomainPolicies domainPolicies = new com.yahoo.athenz.zms.DomainPolicies();
domainPolicies.setDomain(domainName);
domainPolicies.setPolicies(policies);
com.yahoo.athenz.zms.SignedPolicies signedPolicies = new com.yahoo.athenz.zms.SignedPolicies();
signedPolicies.setContents(domainPolicies);
signedPolicies.setSignature(Crypto.sign(SignUtils.asCanonicalString(domainPolicies), pkey));
signedPolicies.setKeyId("0");
DomainData domain = new DomainData();
domain.setName(domainName);
domain.setRoles(roles);
domain.setServices(services);
domain.setPolicies(signedPolicies);
signedDomain.setDomain(domain);
signedDomain.setSignature(Crypto.sign(SignUtils.asCanonicalString(domain), pkey));
signedDomain.setKeyId("0");
return signedDomain;
}
Aggregations