use of com.yahoo.athenz.zms.Role in project athenz by yahoo.
the class ZTSImplTest method testMatchPrincipalInRoleStdMemberNoMatch.
@Test
public void testMatchPrincipalInRoleStdMemberNoMatch() {
Role role = createRoleObject("weather", "Role", null, "user_domain.user2", null);
assertFalse(authorizer.matchPrincipalInRole(role, null, "user_domain.user23", null));
}
use of com.yahoo.athenz.zms.Role in project athenz by yahoo.
the class ZTSImplTest method createSignedDomainExpiration.
private SignedDomain createSignedDomainExpiration(String domainName, String serviceName, Boolean enabled) {
SignedDomain signedDomain = new SignedDomain();
List<Role> roles = new ArrayList<>();
String memberName = "user_domain.user1";
Role role = new Role();
role.setName(generateRoleName(domainName, "admin"));
List<RoleMember> members = new ArrayList<RoleMember>();
RoleMember roleMember = new RoleMember();
roleMember.setMemberName("user_domain.adminuser");
members.add(roleMember);
role.setRoleMembers(members);
roles.add(role);
role = new Role();
role.setName(generateRoleName(domainName, "role1"));
members = new ArrayList<RoleMember>();
roleMember = new RoleMember();
roleMember.setMemberName(memberName);
roleMember.setExpiration(Timestamp.fromMillis(System.currentTimeMillis() - 100));
members.add(roleMember);
role.setRoleMembers(members);
roles.add(role);
role = new Role();
role.setName(generateRoleName(domainName, "role2"));
members = new ArrayList<RoleMember>();
roleMember = new RoleMember();
roleMember.setMemberName(memberName);
roleMember.setExpiration(Timestamp.fromMillis(System.currentTimeMillis() + TimeUnit.DAYS.toMillis(1)));
members.add(roleMember);
role.setRoleMembers(members);
roles.add(role);
List<ServiceIdentity> services = new ArrayList<>();
ServiceIdentity service = new ServiceIdentity();
service.setName(generateServiceIdentityName(domainName, serviceName));
setServicePublicKey(service, "0", ZTS_Y64_CERT0);
services.add(service);
DomainData domain = new DomainData();
domain.setName(domainName);
domain.setRoles(roles);
domain.setServices(services);
domain.setModified(Timestamp.fromCurrentTime());
domain.setEnabled(enabled);
signedDomain.setDomain(domain);
signedDomain.setSignature(Crypto.sign(SignUtils.asCanonicalString(domain), privateKey));
signedDomain.setKeyId("0");
return signedDomain;
}
use of com.yahoo.athenz.zms.Role in project athenz by yahoo.
the class ZTSImplTest method testMatchDelegatedTrustAssertionNoMemberMatch.
@Test
public void testMatchDelegatedTrustAssertionNoMemberMatch() {
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);
assertFalse(authorizer.matchDelegatedTrustAssertion(assertion, "weather:role.Role", "user_domain.user1", roles));
}
use of com.yahoo.athenz.zms.Role in project athenz by yahoo.
the class SignUtilsTest method testAsStructRoleService.
@Test
public void testAsStructRoleService() {
List<Role> roles = new ArrayList<Role>();
Role mRole = Mockito.mock(Role.class);
roles.add(mRole);
List<String> items = new ArrayList<String>();
String item = "check_item";
items.add(item);
List<ServiceIdentity> services = new ArrayList<ServiceIdentity>();
ServiceIdentity mService = Mockito.mock(ServiceIdentity.class);
services.add(mService);
List<PublicKeyEntry> publicKeys = new ArrayList<PublicKeyEntry>();
PublicKeyEntry mPublicKey = Mockito.mock(PublicKeyEntry.class);
publicKeys.add(mPublicKey);
SignedPolicies signedPolicies = Mockito.mock(SignedPolicies.class);
Mockito.when(mockDomain.getEnabled()).thenReturn(null);
Mockito.when(mockDomain.getAccount()).thenReturn("chk_string");
Mockito.when(mockDomain.getRoles()).thenReturn(roles);
Mockito.when(mRole.getMembers()).thenReturn(items);
Mockito.when(mockDomain.getServices()).thenReturn(services);
Mockito.when(mService.getHosts()).thenReturn(null);
Mockito.when(mService.getPublicKeys()).thenReturn(publicKeys);
Mockito.when(mockDomain.getPolicies()).thenReturn(signedPolicies);
Mockito.when(signedPolicies.getContents()).thenReturn(mockPolicies);
String check = SignUtils.asCanonicalString(mockDomain);
assertNotNull(check);
assertEquals(check, "{\"account\":\"chk_string\",\"policies\":{\"contents\":{\"policies\":[]}},\"roles\":[{\"members\":[\"check_item\"],\"roleMembers\":[]}],\"services\":[{\"publicKeys\":[{}]}],\"ypmId\":0}");
Mockito.when(mService.getPublicKeys()).thenReturn(null);
check = SignUtils.asCanonicalString(mockDomain);
assertNotNull(check);
assertEquals(check, "{\"account\":\"chk_string\",\"policies\":{\"contents\":{\"policies\":[]}},\"roles\":[{\"members\":[\"check_item\"],\"roleMembers\":[]}],\"services\":[{\"publicKeys\":[]}],\"ypmId\":0}");
}
use of com.yahoo.athenz.zms.Role in project athenz by yahoo.
the class SignUtils method asStruct.
private static Struct asStruct(DomainData domainData) {
// all of our fields are in canonical order based
// on their attribute name
Struct struct = new Struct();
appendObject(struct, ATTR_ACCOUNT, domainData.getAccount());
appendObject(struct, ATTR_ENABLED, domainData.getEnabled());
appendObject(struct, ATTR_MODIFIED, domainData.getModified());
appendObject(struct, ATTR_NAME, domainData.getName());
SignedPolicies signedPolicies = domainData.getPolicies();
if (signedPolicies != null) {
Struct structSignedPolicies = new Struct();
appendObject(structSignedPolicies, ATTR_CONTENTS, asStruct(signedPolicies.getContents()));
appendObject(structSignedPolicies, ATTR_KEYID, signedPolicies.getKeyId());
appendObject(struct, ATTR_POLICIES, structSignedPolicies);
appendObject(structSignedPolicies, ATTR_SIGNATURE, signedPolicies.getSignature());
}
Array structRoles = new Array();
if (domainData.getRoles() != null) {
for (Role role : domainData.getRoles()) {
structRoles.add(asStruct(role));
}
}
appendArray(struct, ATTR_ROLES, structRoles);
Array structServices = new Array();
if (domainData.getServices() != null) {
for (ServiceIdentity service : domainData.getServices()) {
structServices.add(asStruct(service));
}
}
appendArray(struct, ATTR_SERVICES, structServices);
appendObject(struct, ATTR_YPMID, domainData.getYpmId());
return struct;
}
Aggregations