use of com.yahoo.athenz.zms.RoleMember in project athenz by yahoo.
the class DataStoreTest method createDataCache.
private DataCache createDataCache(String domainName) {
DataCache dataCache = new DataCache();
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.user1"));
role.setRoleMembers(members);
roles.add(role);
dataCache.processRole(role);
role = new Role();
role.setName(domainName + ":role.readers");
members = new ArrayList<>();
members.add(new RoleMember().setMemberName("user_domain.user1"));
members.add(new RoleMember().setMemberName("user_domain.user2"));
role.setRoleMembers(members);
roles.add(role);
dataCache.processRole(role);
role = new Role();
role.setName(domainName + ":role.writers");
role.setTrust(domainName + "Trust");
roles.add(role);
dataCache.processRole(role);
DomainData domainData = new DomainData();
domainData.setName(domainName);
domainData.setRoles(roles);
dataCache.setDomainData(domainData);
return dataCache;
}
use of com.yahoo.athenz.zms.RoleMember in project athenz by yahoo.
the class DataStoreTest method testProcessDomainUpdatesFromZMSWithUpdater.
@Test
public void testProcessDomainUpdatesFromZMSWithUpdater() {
ChangeLogStore clogStore = new MockZMSFileChangeLogStore("/tmp/zts_server_unit_tests/zts_root", pkey, "0");
DataStore store = new DataStore(clogStore, null);
((MockZMSFileChangeLogStore) store.changeLogStore).setTagHeader("2014-01-01T12:00:00");
store.loadZMSPublicKeys();
SignedDomain signedDomain = createSignedDomain("coretech", "weather");
store.processDomain(signedDomain, true);
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);
store.lastDeleteRunTime = System.currentTimeMillis() - 24 * 60 * 60;
DataUpdater updater = store.new DataUpdater();
updater.run();
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"));
}
use of com.yahoo.athenz.zms.RoleMember in project athenz by yahoo.
the class ZTSImplTest method signedBootstrapTenantDomain.
private SignedDomain signedBootstrapTenantDomain(String provider, String domainName, String serviceName, String awsAccount) {
SignedDomain signedDomain = new SignedDomain();
List<Role> roles = new ArrayList<>();
Role role = new Role();
role.setName(generateRoleName(domainName, "providers"));
List<RoleMember> members = new ArrayList<>();
members.add(new RoleMember().setMemberName(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 assertion = new com.yahoo.athenz.zms.Assertion();
assertion.setResource(domainName + ":service." + serviceName);
assertion.setAction("launch");
assertion.setRole(generateRoleName(domainName, "providers"));
List<com.yahoo.athenz.zms.Assertion> assertions = new ArrayList<>();
assertions.add(assertion);
policy.setAssertions(assertions);
policy.setName(generatePolicyName(domainName, "providers"));
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);
domain.setAccount(awsAccount);
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 ZTSImplTest method testGetRoleTokenProxyUserMismatchRolesEmptySet.
@Test
public void testGetRoleTokenProxyUserMismatchRolesEmptySet() {
List<RoleMember> writers = new ArrayList<>();
writers.add(new RoleMember().setMemberName("user_domain.joe"));
List<RoleMember> readers = new ArrayList<>();
readers.add(new RoleMember().setMemberName("user_domain.proxy-user2"));
readers.add(new RoleMember().setMemberName("user_domain.jane"));
readers.add(new RoleMember().setMemberName("user_domain.proxy-user1"));
SignedDomain signedDomain = createSignedDomain("coretech-proxy4", "weather-proxy4", "storage", writers, readers, true);
store.processDomain(signedDomain, false);
Principal principal = SimplePrincipal.create("user_domain", "proxy-user1", "v=U1;d=user_domain;n=proxy-user1;s=sig", 0, null);
ResourceContext context = createResourceContext(principal);
try {
zts.getRoleToken(context, "coretech-proxy4", null, Integer.valueOf(600), Integer.valueOf(1200), "user_domain.joe");
fail();
} catch (ResourceException ex) {
assertEquals(ex.getCode(), 403);
}
}
use of com.yahoo.athenz.zms.RoleMember in project athenz by yahoo.
the class DataCacheTest method testProcessRoleMembersWithWildcards.
@Test
public void testProcessRoleMembersWithWildcards() {
List<RoleMember> members1 = new ArrayList<>();
members1.add(new RoleMember().setMemberName("user_domain.user1"));
members1.add(new RoleMember().setMemberName("user_domain.user2"));
members1.add(new RoleMember().setMemberName("user_domain.*"));
members1.add(new RoleMember().setMemberName("user_domain.user*"));
members1.add(new RoleMember().setMemberName("*"));
DataCache cache = new DataCache();
cache.processRoleMembers("dom.role1", members1);
Set<MemberRole> set1 = cache.getMemberRoleSet("user_domain.user1");
assertNotNull(set1);
assertTrue(set1.contains(new MemberRole("dom.role1", 0)));
assertEquals(set1.size(), 1);
Set<MemberRole> set2 = cache.getMemberRoleSet("user_domain.user2");
assertNotNull(set2);
assertTrue(set2.contains(new MemberRole("dom.role1", 0)));
assertEquals(set2.size(), 1);
Set<MemberRole> set3 = cache.getAllMemberRoleSet();
assertNotNull(set3);
assertTrue(set3.contains(new MemberRole("dom.role1", 0)));
assertEquals(set3.size(), 1);
Map<String, Set<MemberRole>> setMap = cache.getPrefixMemberRoleSetMap();
assertNotNull(setMap);
assertEquals(setMap.size(), 2);
Set<MemberRole> set4 = setMap.get("user_domain.");
assertNotNull(set4);
assertTrue(set4.contains(new MemberRole("dom.role1", 0)));
assertEquals(set4.size(), 1);
Set<MemberRole> set5 = setMap.get("user_domain.user");
assertNotNull(set5);
assertTrue(set5.contains(new MemberRole("dom.role1", 0)));
assertEquals(set5.size(), 1);
}
Aggregations