Search in sources :

Example 21 with DomainData

use of com.yahoo.athenz.zms.DomainData 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 22 with DomainData

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

the class DataStoreTest method testProcessDomainServiceIdentitiesNullPolicies.

@Test
public void testProcessDomainServiceIdentitiesNullPolicies() {
    ChangeLogStore clogStore = new MockZMSFileChangeLogStore("/tmp/zts_server_unit_tests/zts_root", pkey, "0");
    DataStore store = new DataStore(clogStore, null);
    DataCache dataCache = new DataCache();
    DomainData domainData = new DomainData();
    domainData.setName("coretech");
    dataCache.setDomainData(domainData);
    store.processDomainServiceIdentities(domainData, dataCache);
    HostServices hostServices = store.getHostServices("host1");
    List<String> hosts = hostServices.getNames();
    assertNull(hosts);
}
Also used : ZMSFileChangeLogStore(com.yahoo.athenz.zts.store.impl.ZMSFileChangeLogStore) MockZMSFileChangeLogStore(com.yahoo.athenz.zts.store.impl.MockZMSFileChangeLogStore) DomainData(com.yahoo.athenz.zms.DomainData) HostServices(com.yahoo.athenz.zts.HostServices) MockZMSFileChangeLogStore(com.yahoo.athenz.zts.store.impl.MockZMSFileChangeLogStore) DataCache(com.yahoo.athenz.zts.cache.DataCache) Test(org.testng.annotations.Test)

Example 23 with DomainData

use of com.yahoo.athenz.zms.DomainData 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 24 with DomainData

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

the class ZTSImplTest method testAccess.

@Test
public void testAccess() {
    DataCache domain = new DataCache();
    DomainData domainData = new DomainData();
    domainData.setName("coretechtrust");
    domain.setDomainData(domainData);
    domainData.setRoles(new ArrayList<Role>());
    Role role1 = createRoleObject("coretechtrust", "role1", null, "user_domain.user1", null);
    Role role2 = createRoleObject("coretechtrust", "role2", null, "user_domain.user2", null);
    domainData.getRoles().add(role1);
    domainData.getRoles().add(role2);
    Policy policy = createPolicyObject("coretechtrust", "access", "coretechtrust:role.role1", false, "update", "coretechtrust:table1", AssertionEffect.ALLOW);
    domainData.setPolicies(new com.yahoo.athenz.zms.SignedPolicies());
    domainData.getPolicies().setContents(new com.yahoo.athenz.zms.DomainPolicies());
    domainData.getPolicies().getContents().setPolicies(new ArrayList<Policy>());
    domainData.getPolicies().getContents().getPolicies().add(policy);
    store.getCacheStore().put("coretechtrust", domain);
    Principal principal1 = SimplePrincipal.create("user_domain", "user1", "v=U1;d=user_domain;n=user1;s=signature", 0, null);
    assertTrue(authorizer.access("update", "coretechtrust:table1", principal1, null));
    assertFalse(authorizer.access("update", "coretechtrust:table2", principal1, null));
    assertFalse(authorizer.access("delete", "coretechtrust:table1", principal1, null));
    Principal principal2 = SimplePrincipal.create("user_domain", "user2", "v=U1;d=user_domain;n=user2;s=signature", 0, null);
    assertFalse(authorizer.access("update", "coretechtrust:table1", principal2, null));
    Principal principal3 = SimplePrincipal.create("user_domain", "user3", "v=U1;d=user_domain;n=user3;s=signature", 0, null);
    assertFalse(authorizer.access("update", "coretechtrust:table1", principal3, null));
    store.getCacheStore().invalidate("coretechtrust");
}
Also used : Role(com.yahoo.athenz.zms.Role) Policy(com.yahoo.athenz.zms.Policy) DomainData(com.yahoo.athenz.zms.DomainData) DataCache(com.yahoo.athenz.zts.cache.DataCache) SimplePrincipal(com.yahoo.athenz.auth.impl.SimplePrincipal) Principal(com.yahoo.athenz.auth.Principal) Test(org.testng.annotations.Test)

Example 25 with DomainData

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

the class ZTSImplTest method signedAuthorizedProviderDomain.

private SignedDomain signedAuthorizedProviderDomain() {
    SignedDomain signedDomain = new SignedDomain();
    List<Role> roles = new ArrayList<>();
    Role role = new Role();
    role.setName(generateRoleName("sys.auth", "providers"));
    List<RoleMember> members = new ArrayList<>();
    members.add(new RoleMember().setMemberName("athenz.provider"));
    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 assertion1 = new com.yahoo.athenz.zms.Assertion();
    assertion1.setResource("sys.auth:instance");
    assertion1.setAction("launch");
    assertion1.setRole("sys.auth:role.providers");
    com.yahoo.athenz.zms.Assertion assertion2 = new com.yahoo.athenz.zms.Assertion();
    assertion2.setResource("sys.auth:dns.ostk.athenz.cloud");
    assertion2.setAction("launch");
    assertion2.setRole("sys.auth:role.providers");
    List<com.yahoo.athenz.zms.Assertion> assertions = new ArrayList<>();
    assertions.add(assertion1);
    assertions.add(assertion2);
    policy.setAssertions(assertions);
    policy.setName("sys.auth:policy.providers");
    policies.add(policy);
    com.yahoo.athenz.zms.DomainPolicies domainPolicies = new com.yahoo.athenz.zms.DomainPolicies();
    domainPolicies.setDomain("sys.auth");
    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("sys.auth");
    domain.setRoles(roles);
    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 : Policy(com.yahoo.athenz.zms.Policy) Policy(com.yahoo.athenz.zms.Policy) ArrayList(java.util.ArrayList) Assertion(com.yahoo.athenz.zms.Assertion) DomainData(com.yahoo.athenz.zms.DomainData) Assertion(com.yahoo.athenz.zms.Assertion) Role(com.yahoo.athenz.zms.Role) SignedDomain(com.yahoo.athenz.zms.SignedDomain) RoleMember(com.yahoo.athenz.zms.RoleMember)

Aggregations

DomainData (com.yahoo.athenz.zms.DomainData)64 ArrayList (java.util.ArrayList)44 Test (org.testng.annotations.Test)43 Role (com.yahoo.athenz.zms.Role)32 DataCache (com.yahoo.athenz.zts.cache.DataCache)32 RoleMember (com.yahoo.athenz.zms.RoleMember)25 SignedDomain (com.yahoo.athenz.zms.SignedDomain)25 ZMSFileChangeLogStore (com.yahoo.athenz.zts.store.impl.ZMSFileChangeLogStore)25 MockZMSFileChangeLogStore (com.yahoo.athenz.zts.store.impl.MockZMSFileChangeLogStore)24 ServiceIdentity (com.yahoo.athenz.zms.ServiceIdentity)21 Policy (com.yahoo.athenz.zms.Policy)18 MemberRole (com.yahoo.athenz.zts.cache.MemberRole)15 Assertion (com.yahoo.athenz.zms.Assertion)11 HostServices (com.yahoo.athenz.zts.HostServices)6 S3Object (com.amazonaws.services.s3.model.S3Object)4 S3ObjectInputStream (com.amazonaws.services.s3.model.S3ObjectInputStream)4 FileInputStream (java.io.FileInputStream)4 InputStream (java.io.InputStream)4 Principal (com.yahoo.athenz.auth.Principal)3 SimplePrincipal (com.yahoo.athenz.auth.impl.SimplePrincipal)3