use of com.yahoo.athenz.zms.Role in project athenz by yahoo.
the class ZTSImplTest method testMatchDelegatedTrustAssertionValidWithPattern.
@Test
public void testMatchDelegatedTrustAssertionValidWithPattern() {
Assertion assertion = new Assertion();
assertion.setAction("ASSUME_ROLE");
assertion.setEffect(AssertionEffect.ALLOW);
assertion.setResource("*:role.Role");
assertion.setRole("weather:role.*");
Role role = null;
List<Role> roles = new ArrayList<>();
role = createRoleObject("weather", "Role1", null, "user_domain.user1", null);
roles.add(role);
role = createRoleObject("weather", "Role", null, "user_domain.user2", null);
roles.add(role);
assertTrue(authorizer.matchDelegatedTrustAssertion(assertion, "weather:role.Role", "user_domain.user2", roles));
}
use of com.yahoo.athenz.zms.Role in project athenz by yahoo.
the class ZTSImplTest method testMatchPrincipalInRoleStdMemberMatch.
@Test
public void testMatchPrincipalInRoleStdMemberMatch() {
Role role = createRoleObject("weather", "Role", null, "user_domain.user2", null);
assertTrue(authorizer.matchPrincipalInRole(role, null, "user_domain.user2", null));
}
use of com.yahoo.athenz.zms.Role in project athenz by yahoo.
the class ZTSImplTest method createRoleObject.
public static Role createRoleObject(String domainName, String roleName, String trust) {
Role role = new Role();
role.setName(domainName + ":role." + roleName);
role.setTrust(trust);
return role;
}
use of com.yahoo.athenz.zms.Role in project athenz by yahoo.
the class ZTSImplTest method testAccessDelegatedTrust.
@Test
public void testAccessDelegatedTrust() {
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", "trust", "coretechtrust:role.role1", false, "ASSUME_ROLE", "weather:role.role1", 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);
domain = new DataCache();
domainData = new DomainData();
domainData.setName("weather");
domain.setDomainData(domainData);
domainData.setRoles(new ArrayList<Role>());
role1 = createRoleObject("weather", "role1", "coretechtrust");
domainData.getRoles().add(role1);
policy = createPolicyObject("weather", "access", "weather:role.role1", false, "update", "weather: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("weather", domain);
Principal principal1 = SimplePrincipal.create("user_domain", "user1", "v=U1;d=user_domain;n=user1;s=signature", 0, null);
assertTrue(authorizer.access("update", "weather:table1", principal1, null));
assertTrue(authorizer.access("update", "weather:table1", principal1, "coretechtrust"));
assertFalse(authorizer.access("update", "weather:table1", principal1, "unknowntrust"));
assertFalse(authorizer.access("update", "weather:table2", principal1, null));
assertFalse(authorizer.access("delete", "weather: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", "weather: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", "weather:table1", principal3, null));
store.getCacheStore().invalidate("coretechtrust");
store.getCacheStore().invalidate("weather");
}
use of com.yahoo.athenz.zms.Role in project athenz by yahoo.
the class ZTSImplTest method testMatchDelegatedTrustAssertionValidWithOutPattern.
@Test
public void testMatchDelegatedTrustAssertionValidWithOutPattern() {
Assertion assertion = new Assertion();
assertion.setAction("ASSUME_ROLE");
assertion.setEffect(AssertionEffect.ALLOW);
assertion.setResource("*:role.Role");
assertion.setRole("weather:role.Role");
Role role = null;
List<Role> roles = new ArrayList<>();
role = createRoleObject("weather", "Role1", null, "user_domain.user1", null);
roles.add(role);
role = createRoleObject("weather", "Role", null, "user_domain.user2", null);
roles.add(role);
assertTrue(authorizer.matchDelegatedTrustAssertion(assertion, "weather:role.Role", "user_domain.user2", roles));
}
Aggregations