use of com.yahoo.athenz.zms.RoleMember in project athenz by yahoo.
the class InstanceProviderManagerTest method createSignedDomain.
private SignedDomain createSignedDomain(String domainName, String serviceName, boolean includeService, boolean includeEndPoint, String endPoint) {
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.adminuser"));
role.setRoleMembers(members);
roles.add(role);
List<ServiceIdentity> services = new ArrayList<>();
ServiceIdentity service = new ServiceIdentity();
service.setName(domainName + "." + serviceName);
if (includeEndPoint) {
service.setProviderEndpoint(endPoint);
}
services.add(service);
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(domainName + ":instance");
assertion.setAction("read");
assertion.setRole(domainName + ":role.admin");
List<com.yahoo.athenz.zms.Assertion> assertions = new ArrayList<>();
assertions.add(assertion);
policy.setAssertions(assertions);
policy.setName(domainName + ":policy.test");
policies.add(policy);
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), privateKey));
signedPolicies.setKeyId("0");
DomainData domain = new DomainData();
domain.setName(domainName);
domain.setRoles(roles);
if (includeService) {
domain.setServices(services);
}
domain.setPolicies(signedPolicies);
domain.setModified(Timestamp.fromCurrentTime());
signedDomain.setDomain(domain);
signedDomain.setSignature(Crypto.sign(SignUtils.asCanonicalString(domain), privateKey));
signedDomain.setKeyId("0");
return signedDomain;
}
use of com.yahoo.athenz.zms.RoleMember in project athenz by yahoo.
the class FileConnectionTest method testInsertRoleMember.
@Test
public void testInsertRoleMember() {
File fileDir = new File("/home/athenz/zms_store");
File quotaDir = new File("/home/athenz/zms_quota");
try (FileConnection fileconnection = new FileConnection(fileDir, quotaDir)) {
try {
fileconnection.insertRoleMember("DummyDomain1", "Role1", new RoleMember().setMemberName("principal1"), "audit1", "zmsjcltest");
} catch (Exception ex) {
assertTrue(true);
}
}
}
use of com.yahoo.athenz.zms.RoleMember in project athenz by yahoo.
the class JDBCConnection method listRoleMembers.
@Override
public List<RoleMember> listRoleMembers(String domainName, String roleName) {
final String caller = "listRoleMembers";
int domainId = getDomainId(domainName);
if (domainId == 0) {
throw notFoundError(caller, ZMSConsts.OBJECT_DOMAIN, domainName);
}
int roleId = getRoleId(domainId, roleName);
if (roleId == 0) {
throw notFoundError(caller, ZMSConsts.OBJECT_ROLE, ZMSUtils.roleResourceName(domainName, roleName));
}
List<RoleMember> members = new ArrayList<>();
try (PreparedStatement ps = con.prepareStatement(SQL_LIST_ROLE_MEMBERS)) {
ps.setInt(1, roleId);
try (ResultSet rs = executeQuery(ps, caller)) {
while (rs.next()) {
RoleMember roleMember = new RoleMember();
roleMember.setMemberName(rs.getString(1));
java.sql.Timestamp expiration = rs.getTimestamp(2);
if (expiration != null) {
roleMember.setExpiration(Timestamp.fromMillis(expiration.getTime()));
}
members.add(roleMember);
}
}
} catch (SQLException ex) {
throw sqlError(ex, caller);
}
Collections.sort(members, RoleMemberComparator);
return members;
}
use of com.yahoo.athenz.zms.RoleMember in project athenz by yahoo.
the class JDBCConnection method getAthenzDomainRoles.
void getAthenzDomainRoles(String domainName, int domainId, AthenzDomain athenzDomain, String caller) {
Map<String, Role> roleMap = new HashMap<>();
try (PreparedStatement ps = con.prepareStatement(SQL_GET_DOMAIN_ROLES)) {
ps.setInt(1, domainId);
try (ResultSet rs = executeQuery(ps, caller)) {
while (rs.next()) {
String roleName = rs.getString(ZMSConsts.DB_COLUMN_NAME);
Role role = new Role().setName(ZMSUtils.roleResourceName(domainName, roleName)).setModified(Timestamp.fromMillis(rs.getTimestamp(ZMSConsts.DB_COLUMN_MODIFIED).getTime())).setTrust(saveValue(rs.getString(ZMSConsts.DB_COLUMN_TRUST)));
roleMap.put(roleName, role);
}
}
} catch (SQLException ex) {
throw sqlError(ex, caller);
}
try (PreparedStatement ps = con.prepareStatement(SQL_GET_DOMAIN_ROLE_MEMBERS)) {
ps.setInt(1, domainId);
try (ResultSet rs = executeQuery(ps, caller)) {
while (rs.next()) {
String roleName = rs.getString(1);
Role role = roleMap.get(roleName);
if (role == null) {
continue;
}
List<RoleMember> members = role.getRoleMembers();
if (members == null) {
members = new ArrayList<>();
role.setRoleMembers(members);
}
RoleMember roleMember = new RoleMember();
roleMember.setMemberName(rs.getString(2));
java.sql.Timestamp expiration = rs.getTimestamp(3);
if (expiration != null) {
roleMember.setExpiration(Timestamp.fromMillis(expiration.getTime()));
}
members.add(roleMember);
}
}
} catch (SQLException ex) {
throw sqlError(ex, caller);
}
athenzDomain.getRoles().addAll(roleMap.values());
}
use of com.yahoo.athenz.zms.RoleMember in project athenz by yahoo.
the class ZMSUtils method makeAdminRole.
public static Role makeAdminRole(String domainName, List<String> adminUsers) {
List<RoleMember> roleMembers = new ArrayList<>();
for (String admin : adminUsers) {
RoleMember roleMember = new RoleMember();
roleMember.setMemberName(admin);
roleMembers.add(roleMember);
}
Role role = new Role().setName(roleResourceName(domainName, ZMSConsts.ADMIN_ROLE_NAME)).setRoleMembers(roleMembers);
return role;
}
Aggregations