Search in sources :

Example 26 with RoleMember

use of com.yahoo.athenz.zms.RoleMember in project athenz by yahoo.

the class DataStoreTest method testAddDomainToCacheNewDomain.

@Test
public void testAddDomainToCacheNewDomain() {
    ChangeLogStore clogStore = new MockZMSFileChangeLogStore("/tmp/zts_server_unit_tests/zts_root", pkey, "0");
    DataStore store = new DataStore(clogStore, null);
    DataCache dataCache = new DataCache();
    Role role = new Role();
    role.setName("coretech:role.admin");
    List<RoleMember> members = new ArrayList<>();
    members.add(new RoleMember().setMemberName("user_domain.user"));
    role.setRoleMembers(members);
    List<Role> roles = new ArrayList<>();
    roles.add(role);
    DomainData domainData = new DomainData();
    domainData.setRoles(roles);
    dataCache.setDomainData(domainData);
    store.addDomainToCache("coretech", dataCache);
    DomainData domain = store.getDomainData("coretech");
    assertNotNull(domain);
    assertEquals(domain.getRoles().size(), 1);
    assertEquals(domain.getRoles().get(0).getName(), "coretech:role.admin");
    assertEquals(domain.getRoles().get(0).getRoleMembers().size(), 1);
    assertEquals(domain.getRoles().get(0).getRoleMembers().get(0).getMemberName(), "user_domain.user");
}
Also used : Role(com.yahoo.athenz.zms.Role) MemberRole(com.yahoo.athenz.zts.cache.MemberRole) ZMSFileChangeLogStore(com.yahoo.athenz.zts.store.impl.ZMSFileChangeLogStore) MockZMSFileChangeLogStore(com.yahoo.athenz.zts.store.impl.MockZMSFileChangeLogStore) ArrayList(java.util.ArrayList) DomainData(com.yahoo.athenz.zms.DomainData) MockZMSFileChangeLogStore(com.yahoo.athenz.zts.store.impl.MockZMSFileChangeLogStore) DataCache(com.yahoo.athenz.zts.cache.DataCache) RoleMember(com.yahoo.athenz.zms.RoleMember) Test(org.testng.annotations.Test)

Example 27 with RoleMember

use of com.yahoo.athenz.zms.RoleMember in project athenz by yahoo.

the class DataStoreTest method testAddDomainToCacheUpdatedDomain.

@Test
public void testAddDomainToCacheUpdatedDomain() {
    ChangeLogStore clogStore = new MockZMSFileChangeLogStore("/tmp/zts_server_unit_tests/zts_root", pkey, "0");
    DataStore store = new DataStore(clogStore, null);
    DataCache dataCache = new DataCache();
    Role role = new Role();
    role.setName("coretech:role.admin");
    List<RoleMember> members = new ArrayList<>();
    members.add(new RoleMember().setMemberName("user_domain.user"));
    role.setRoleMembers(members);
    List<Role> roles = new ArrayList<>();
    roles.add(role);
    DomainData domainData = new DomainData();
    domainData.setRoles(roles);
    dataCache.setDomainData(domainData);
    store.addDomainToCache("coretech", dataCache);
    /* update member list */
    role = new Role();
    role.setName("coretech:role.admin");
    members = new ArrayList<>();
    members.add(new RoleMember().setMemberName("user_domain.user1"));
    members.add(new RoleMember().setMemberName("user_domain.user2"));
    role.setRoleMembers(members);
    roles = new ArrayList<>();
    roles.add(role);
    dataCache = new DataCache();
    domainData = new DomainData();
    domainData.setRoles(roles);
    dataCache.setDomainData(domainData);
    store.addDomainToCache("coretech", dataCache);
    DomainData domain = store.getDomainData("coretech");
    assertNotNull(domain);
    assertEquals(domain.getRoles().size(), 1);
    assertEquals(domain.getRoles().get(0).getName(), "coretech:role.admin");
    assertEquals(domain.getRoles().get(0).getRoleMembers().size(), 2);
    boolean user1 = false;
    boolean user2 = false;
    for (RoleMember member : domain.getRoles().get(0).getRoleMembers()) {
        switch(member.getMemberName()) {
            case "user_domain.user1":
                user1 = true;
                break;
            case "user_domain.user2":
                user2 = true;
                break;
        }
    }
    assertTrue(user1);
    assertTrue(user2);
}
Also used : Role(com.yahoo.athenz.zms.Role) MemberRole(com.yahoo.athenz.zts.cache.MemberRole) ZMSFileChangeLogStore(com.yahoo.athenz.zts.store.impl.ZMSFileChangeLogStore) MockZMSFileChangeLogStore(com.yahoo.athenz.zts.store.impl.MockZMSFileChangeLogStore) ArrayList(java.util.ArrayList) DomainData(com.yahoo.athenz.zms.DomainData) MockZMSFileChangeLogStore(com.yahoo.athenz.zts.store.impl.MockZMSFileChangeLogStore) DataCache(com.yahoo.athenz.zts.cache.DataCache) RoleMember(com.yahoo.athenz.zms.RoleMember) Test(org.testng.annotations.Test)

Example 28 with RoleMember

use of com.yahoo.athenz.zms.RoleMember in project athenz by yahoo.

the class FileConnection method updateRole.

@Override
public boolean updateRole(String domainName, Role role) {
    DomainStruct domainStruct = getDomainStruct(domainName);
    if (domainStruct == null) {
        throw ZMSUtils.error(ResourceException.NOT_FOUND, "domain not found", "updateRole");
    }
    if (domainStruct.getRoles() == null) {
        domainStruct.setRoles(new HashMap<String, Role>());
    }
    HashMap<String, Role> roles = domainStruct.getRoles();
    String roleName = extractRoleName(domainName, role.getName());
    if (roleName == null) {
        throw ZMSUtils.error(ResourceException.BAD_REQUEST, "invalid role name", "updateRole");
    }
    // here we only need to update the main attrs and not
    // the members
    Role originalRole = getRoleObject(domainStruct, roleName);
    List<RoleMember> members = role.getRoleMembers();
    if (originalRole != null) {
        role.setRoleMembers(originalRole.getRoleMembers());
    } else {
        role.setRoleMembers(null);
    }
    role.setModified(Timestamp.fromCurrentTime());
    roles.put(roleName, role);
    putDomainStruct(domainName, domainStruct);
    role.setRoleMembers(members);
    return true;
}
Also used : Role(com.yahoo.athenz.zms.Role) PrincipalRole(com.yahoo.athenz.zms.PrincipalRole) RoleMember(com.yahoo.athenz.zms.RoleMember)

Example 29 with RoleMember

use of com.yahoo.athenz.zms.RoleMember in project athenz by yahoo.

the class FileConnection method deleteRoleMember.

@Override
public boolean deleteRoleMember(String domainName, String roleName, String principal, String admin, String auditRef) {
    DomainStruct domainStruct = getDomainStruct(domainName);
    if (domainStruct == null) {
        throw ZMSUtils.error(ResourceException.NOT_FOUND, "domain not found", "deleteRoleMember");
    }
    Role role = getRoleObject(domainStruct, roleName);
    if (role == null) {
        throw ZMSUtils.error(ResourceException.NOT_FOUND, "role not found", "deleteRoleMember");
    }
    List<RoleMember> roleMembers = role.getRoleMembers();
    if (roleMembers != null) {
        for (int idx = 0; idx < roleMembers.size(); idx++) {
            if (roleMembers.get(idx).getMemberName().equalsIgnoreCase(principal)) {
                roleMembers.remove(idx);
                break;
            }
        }
    }
    putDomainStruct(domainName, domainStruct);
    return true;
}
Also used : Role(com.yahoo.athenz.zms.Role) PrincipalRole(com.yahoo.athenz.zms.PrincipalRole) RoleMember(com.yahoo.athenz.zms.RoleMember)

Example 30 with RoleMember

use of com.yahoo.athenz.zms.RoleMember in project athenz by yahoo.

the class FileConnection method getRoleMember.

@Override
public Membership getRoleMember(String domainName, String roleName, String principal) {
    DomainStruct domainStruct = getDomainStruct(domainName);
    if (domainStruct == null) {
        throw ZMSUtils.error(ResourceException.NOT_FOUND, "domain not found", "getRoleMember");
    }
    Role role = getRoleObject(domainStruct, roleName);
    if (role == null) {
        throw ZMSUtils.error(ResourceException.NOT_FOUND, "role not found", "getRoleMember");
    }
    Membership membership = new Membership().setMemberName(principal).setRoleName(ZMSUtils.roleResourceName(domainName, roleName)).setIsMember(false);
    if (role.getRoleMembers() != null) {
        Set<RoleMember> members = new HashSet<>(role.getRoleMembers());
        for (RoleMember member : members) {
            if (member.getMemberName().equalsIgnoreCase(principal)) {
                membership.setIsMember(true);
                membership.setExpiration(member.getExpiration());
                break;
            }
        }
    }
    return membership;
}
Also used : Role(com.yahoo.athenz.zms.Role) PrincipalRole(com.yahoo.athenz.zms.PrincipalRole) Membership(com.yahoo.athenz.zms.Membership) RoleMember(com.yahoo.athenz.zms.RoleMember) HashSet(java.util.HashSet)

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