Search in sources :

Example 46 with RoleMember

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;
}
Also used : ServiceIdentity(com.yahoo.athenz.zms.ServiceIdentity) ArrayList(java.util.ArrayList) DomainData(com.yahoo.athenz.zms.DomainData) Role(com.yahoo.athenz.zms.Role) SignedDomain(com.yahoo.athenz.zms.SignedDomain) RoleMember(com.yahoo.athenz.zms.RoleMember)

Example 47 with RoleMember

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);
        }
    }
}
Also used : File(java.io.File) RoleMember(com.yahoo.athenz.zms.RoleMember) Test(org.testng.annotations.Test)

Example 48 with RoleMember

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;
}
Also used : SQLException(java.sql.SQLException) ArrayList(java.util.ArrayList) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) RoleMember(com.yahoo.athenz.zms.RoleMember)

Example 49 with RoleMember

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());
}
Also used : Role(com.yahoo.athenz.zms.Role) PrincipalRole(com.yahoo.athenz.zms.PrincipalRole) HashMap(java.util.HashMap) SQLException(java.sql.SQLException) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) RoleMember(com.yahoo.athenz.zms.RoleMember)

Example 50 with RoleMember

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;
}
Also used : Role(com.yahoo.athenz.zms.Role) ArrayList(java.util.ArrayList) RoleMember(com.yahoo.athenz.zms.RoleMember)

Aggregations

RoleMember (com.yahoo.athenz.zms.RoleMember)65 ArrayList (java.util.ArrayList)48 Role (com.yahoo.athenz.zms.Role)47 Test (org.testng.annotations.Test)35 SignedDomain (com.yahoo.athenz.zms.SignedDomain)26 DomainData (com.yahoo.athenz.zms.DomainData)25 DataCache (com.yahoo.athenz.zts.cache.DataCache)23 MemberRole (com.yahoo.athenz.zts.cache.MemberRole)18 Policy (com.yahoo.athenz.zms.Policy)13 MockZMSFileChangeLogStore (com.yahoo.athenz.zts.store.impl.MockZMSFileChangeLogStore)13 Assertion (com.yahoo.athenz.zms.Assertion)12 ZMSFileChangeLogStore (com.yahoo.athenz.zts.store.impl.ZMSFileChangeLogStore)12 PrincipalRole (com.yahoo.athenz.zms.PrincipalRole)9 ServiceIdentity (com.yahoo.athenz.zms.ServiceIdentity)8 HashSet (java.util.HashSet)7 JDBCConnection (com.yahoo.athenz.zms.store.jdbc.JDBCConnection)6 File (java.io.File)6 HashMap (java.util.HashMap)6 Domain (com.yahoo.athenz.zms.Domain)5 Set (java.util.Set)5