Search in sources :

Example 51 with RoleMember

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

the class DataStoreTest method testProcessDomainRoles.

@Test
public void testProcessDomainRoles() {
    ChangeLogStore clogStore = new MockZMSFileChangeLogStore("/tmp/zts_server_unit_tests/zts_root", pkey, "0");
    DataStore store = new DataStore(clogStore, null);
    List<Role> roles = new ArrayList<>();
    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);
    roles.add(role);
    role = new Role();
    role.setName("coretech:role.readers");
    members = new ArrayList<>();
    members.add(new RoleMember().setMemberName("user_domain.user"));
    role.setRoleMembers(members);
    roles.add(role);
    DomainData domainData = new DomainData();
    domainData.setName("coretech");
    domainData.setRoles(roles);
    DataCache dataCache = new DataCache();
    dataCache.setDomainData(domainData);
    store.processDomainRoles(domainData, dataCache);
    assertEquals(dataCache.getMemberRoleSet("user_domain.user").size(), 2);
    assertTrue(dataCache.getMemberRoleSet("user_domain.user").contains(new MemberRole("coretech:role.admin", 0)));
    assertTrue(dataCache.getMemberRoleSet("user_domain.user").contains(new MemberRole("coretech:role.readers", 0)));
}
Also used : Role(com.yahoo.athenz.zms.Role) MemberRole(com.yahoo.athenz.zts.cache.MemberRole) 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) RoleMember(com.yahoo.athenz.zms.RoleMember) DataCache(com.yahoo.athenz.zts.cache.DataCache) Test(org.testng.annotations.Test)

Example 52 with RoleMember

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

the class DataStoreTest method testStoreInitLocalDomainUpdated.

@Test
public void testStoreInitLocalDomainUpdated() {
    ChangeLogStore clogStore = new MockZMSFileChangeLogStore("/tmp/zts_server_unit_tests/zts_root", pkey, "0");
    DataStore setupStore = new DataStore(clogStore, null);
    setupStore.loadZMSPublicKeys();
    SignedDomain signedDomain = createSignedDomain("coretech", "weather");
    setupStore.processDomain(signedDomain, true);
    /* create a new store instance */
    DataStore store = new DataStore(clogStore, null);
    ((MockZMSFileChangeLogStore) store.changeLogStore).setTagHeader("2014-01-01T12:00:00");
    List<SignedDomain> domains = new ArrayList<>();
    /* we're going to create a new domain */
    signedDomain = createSignedDomain("sports", "weather");
    domains.add(signedDomain);
    /* we're going to update the coretech domain and set new roles */
    signedDomain = createSignedDomain("coretech", "weather");
    Role role = new Role();
    role.setName("coretech:role.admin");
    List<RoleMember> members = new ArrayList<>();
    members.add(new RoleMember().setMemberName("user_domain.user8"));
    role.setRoleMembers(members);
    List<Role> roles = new ArrayList<>();
    roles.add(role);
    signedDomain.getDomain().setRoles(roles);
    signedDomain.setSignature(Crypto.sign(SignUtils.asCanonicalString(signedDomain.getDomain()), pkey));
    domains.add(signedDomain);
    SignedDomains signedDomains = new SignedDomains();
    signedDomains.setDomains(domains);
    ((MockZMSFileChangeLogStore) store.changeLogStore).setSignedDomains(signedDomains);
    List<String> domainNames = new ArrayList<>();
    domainNames.add("coretech");
    domainNames.add("sports");
    ((MockZMSFileChangeLogStore) store.changeLogStore).setDomainList(domainNames);
    boolean result = store.init();
    assertTrue(result);
    Set<String> accessibleRoles = new HashSet<>();
    DataCache data = store.getDataCache("coretech");
    store.getAccessibleRoles(data, "coretech", "user_domain.user1", null, accessibleRoles, false);
    assertEquals(accessibleRoles.size(), 0);
    accessibleRoles = new HashSet<>();
    store.getAccessibleRoles(data, "coretech", "user_domain.user8", null, accessibleRoles, false);
    assertEquals(accessibleRoles.size(), 1);
    assertTrue(accessibleRoles.contains("admin"));
    accessibleRoles = new HashSet<>();
    data = store.getDataCache("sports");
    store.getAccessibleRoles(data, "sports", "user_domain.user", null, accessibleRoles, false);
    assertEquals(accessibleRoles.size(), 2);
    assertTrue(accessibleRoles.contains("admin"));
    assertTrue(accessibleRoles.contains("writers"));
}
Also used : ArrayList(java.util.ArrayList) SignedDomains(com.yahoo.athenz.zms.SignedDomains) DataCache(com.yahoo.athenz.zts.cache.DataCache) 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) SignedDomain(com.yahoo.athenz.zms.SignedDomain) MockZMSFileChangeLogStore(com.yahoo.athenz.zts.store.impl.MockZMSFileChangeLogStore) RoleMember(com.yahoo.athenz.zms.RoleMember) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Example 53 with RoleMember

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

the class DataStoreTest method createSignedDomain.

private SignedDomain createSignedDomain(String domainName, String tenantDomain) {
    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.writers");
    members = new ArrayList<>();
    members.add(new RoleMember().setMemberName("user_domain.user"));
    members.add(new RoleMember().setMemberName("user_domain.user1"));
    role.setRoleMembers(members);
    roles.add(role);
    role = new Role();
    role.setName(domainName + ":role.readers");
    members = new ArrayList<>();
    members.add(new RoleMember().setMemberName("user_domain.user3"));
    members.add(new RoleMember().setMemberName("user_domain.user4"));
    role.setRoleMembers(members);
    roles.add(role);
    role = new Role();
    role.setName(domainName + ":role.tenant.readers");
    role.setTrust(tenantDomain);
    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(domainName + ":tenant.weather.*");
    assertion.setAction("read");
    assertion.setRole(domainName + ":role.tenant.readers");
    List<com.yahoo.athenz.zms.Assertion> assertions = new ArrayList<>();
    assertions.add(assertion);
    policy.setAssertions(assertions);
    policy.setName(domainName + ":policy.tenant.reader");
    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;
}
Also used : ArrayList(java.util.ArrayList) DomainData(com.yahoo.athenz.zms.DomainData) SignedDomain(com.yahoo.athenz.zms.SignedDomain) ServiceIdentity(com.yahoo.athenz.zms.ServiceIdentity) Role(com.yahoo.athenz.zms.Role) MemberRole(com.yahoo.athenz.zts.cache.MemberRole) RoleMember(com.yahoo.athenz.zms.RoleMember)

Example 54 with RoleMember

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

the class DataStoreTest method testValidateSignedDomainInvalidVersion.

@Test
public void testValidateSignedDomainInvalidVersion() {
    ChangeLogStore clogStore = new MockZMSFileChangeLogStore("/tmp/zts_server_unit_tests/zts_root", pkey, "0");
    DataStore store = new DataStore(clogStore, null);
    store.loadZMSPublicKeys();
    SignedDomain signedDomain = new SignedDomain();
    List<Role> roles = new ArrayList<>();
    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);
    DomainData domain = new DomainData();
    domain.setRoles(roles);
    signedDomain.setDomain(domain);
    signedDomain.setSignature(Crypto.sign(SignUtils.asCanonicalString(domain), pkey));
    signedDomain.setKeyId("100");
    assertFalse(store.validateSignedDomain(signedDomain));
}
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) SignedDomain(com.yahoo.athenz.zms.SignedDomain) ArrayList(java.util.ArrayList) DomainData(com.yahoo.athenz.zms.DomainData) MockZMSFileChangeLogStore(com.yahoo.athenz.zts.store.impl.MockZMSFileChangeLogStore) RoleMember(com.yahoo.athenz.zms.RoleMember) Test(org.testng.annotations.Test)

Example 55 with RoleMember

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

the class DataStoreTest method testValidateSignedDomainInvalidSignature.

@Test
public void testValidateSignedDomainInvalidSignature() {
    ChangeLogStore clogStore = new MockZMSFileChangeLogStore("/tmp/zts_server_unit_tests/zts_root", pkey, "0");
    DataStore store = new DataStore(clogStore, null);
    store.loadZMSPublicKeys();
    SignedDomain signedDomain = new SignedDomain();
    List<Role> roles = new ArrayList<>();
    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);
    DomainData domain = new DomainData();
    domain.setRoles(roles);
    signedDomain.setDomain(domain);
    signedDomain.setSignature("InvalidSignature");
    signedDomain.setKeyId("0");
    assertFalse(store.validateSignedDomain(signedDomain));
}
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) SignedDomain(com.yahoo.athenz.zms.SignedDomain) ArrayList(java.util.ArrayList) DomainData(com.yahoo.athenz.zms.DomainData) MockZMSFileChangeLogStore(com.yahoo.athenz.zts.store.impl.MockZMSFileChangeLogStore) RoleMember(com.yahoo.athenz.zms.RoleMember) Test(org.testng.annotations.Test)

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