use of com.yahoo.athenz.auth.Principal in project athenz by yahoo.
the class ZTSImplTest method testGetSignedDomainPolicyData.
@Test
public void testGetSignedDomainPolicyData() {
ChangeLogStore structStore = new ZMSFileChangeLogStore("/tmp/zts_server_unit_tests/zts_root", privateKey, "0");
DataStore store = new DataStore(structStore, null);
ZTSImpl ztsImpl = new ZTSImpl(mockCloudStore, store);
ZTSImpl.serverHostName = "localhost";
SignedDomain signedDomain = createSignedDomain("coretech", "weather", "storage", true);
store.processDomain(signedDomain, false);
Principal principal = SimplePrincipal.create("user_domain", "user", "v=U1;d=user_domain;n=user;s=signature", 0, null);
ResourceContext context = createResourceContext(principal);
GetDomainSignedPolicyDataResult result = new GetDomainSignedPolicyDataResult(context);
int code = 0;
try {
ztsImpl.getDomainSignedPolicyData(context, "coretech", null, result);
} catch (WebApplicationException ex) {
code = ex.getResponse().getStatus();
}
assertEquals(code, 200);
try {
ztsImpl.getDomainSignedPolicyData(context, "unknowndomain", null, result);
fail();
} catch (ResourceException ex) {
assertEquals(ex.getCode(), 404);
}
}
use of com.yahoo.athenz.auth.Principal in project athenz by yahoo.
the class ZTSImplTest method testGetRoleTokenTrustDomainWildCardGivenRole.
@Test
public void testGetRoleTokenTrustDomainWildCardGivenRole() {
SignedDomain signedDomain = createSignedDomainWildCard("weather", "netops");
store.processDomain(signedDomain, false);
signedDomain = createTenantSignedDomainWildCard("netops", "weather");
store.processDomain(signedDomain, false);
Principal principal = SimplePrincipal.create("user_domain", "siteops_user_1", "v=U1;d=user_domain;n=siteops_user_1;s=signature", 0, null);
ResourceContext context = createResourceContext(principal);
RoleToken roleToken = zts.getRoleToken(context, "weather", "netops_superusers", null, null, null);
com.yahoo.athenz.auth.token.RoleToken token = new com.yahoo.athenz.auth.token.RoleToken(roleToken.getToken());
assertEquals(token.getRoles().size(), 1);
assertTrue(token.getRoles().contains("netops_superusers"));
}
use of com.yahoo.athenz.auth.Principal in project athenz by yahoo.
the class ZTSImplTest method testGetAccess.
@Test
public void testGetAccess() {
SignedDomain signedDomain = createSignedDomain("coretech", "weather", "storage", true);
store.processDomain(signedDomain, false);
Principal principal = SimplePrincipal.create("user_domain", "user", "v=U1;d=user_domain;n=user;s=signature", 0, null);
ResourceContext context = createResourceContext(principal);
// user_domain.user only has access to writers
Access access = zts.getAccess(context, "coretech", "writers", "user_domain.user");
assertTrue(access.getGranted());
access = zts.getAccess(context, "coretech", "readers", "user_domain.user");
assertFalse(access.getGranted());
// user_domain.user1 had access to readers and writers
access = zts.getAccess(context, "coretech", "writers", "user_domain.user1");
assertTrue(access.getGranted());
access = zts.getAccess(context, "coretech", "readers", "user_domain.user1");
assertTrue(access.getGranted());
access = zts.getAccess(context, "coretech", "editors", "user_domain.user1");
assertFalse(access.getGranted());
// user_domain.user4 only has access to readers
access = zts.getAccess(context, "coretech", "readers", "user_domain.user4");
assertTrue(access.getGranted());
access = zts.getAccess(context, "coretech", "writers", "user_domain.user4");
assertFalse(access.getGranted());
}
use of com.yahoo.athenz.auth.Principal in project athenz by yahoo.
the class DebugRoleAuthority method authenticate.
public Principal authenticate(String zToken, String remoteAddr, String httpMethod, StringBuilder errMsg) {
if (zToken == null) {
return null;
}
String domainName = null;
String roleNames = null;
String version = null;
if (zToken.indexOf(';') > 0) {
for (String item : zToken.split(";")) {
String[] kv = item.split("=");
if (kv.length == 2) {
if ("d".equals(kv[0])) {
domainName = kv[1];
} else if ("r".equals(kv[0])) {
roleNames = kv[1];
} else if ("v".equals(kv[0])) {
version = kv[1];
}
}
}
}
if (!"Z1".equals(version)) {
return null;
}
if (domainName == null || roleNames == null) {
return null;
}
// Expiration is not checked in this debugging class.
List<String> roles = Arrays.asList(roleNames.split(","));
Principal p = SimplePrincipal.create(domainName, zToken, roles, this);
if (LOG.isInfoEnabled()) {
LOG.info("[debug-authenticated: '" + p + "']");
}
return p;
}
use of com.yahoo.athenz.auth.Principal in project athenz by yahoo.
the class DebugPrincipalAuthorityTest method testPrincipalAuthority.
@Test
public void testPrincipalAuthority() {
Authority principalAuthority = new com.yahoo.athenz.common.server.debug.DebugPrincipalAuthority();
assertNotNull(principalAuthority);
principalAuthority.initialize();
((DebugPrincipalAuthority) principalAuthority).setKeyStore(null);
assertNull(principalAuthority.getDomain());
assertEquals(principalAuthority.getHeader(), "Athenz-Principal-Auth");
// invalid authenticate values
assertNull(principalAuthority.authenticate(null, "10.11.12.13", "GET", null));
assertNull(principalAuthority.authenticate("abc", "10.11.12.13", "GET", null));
assertNull(principalAuthority.authenticate("v=S1;d=coretech;s=signature", "10.11.12.13", "GET", null));
assertNull(principalAuthority.authenticate("v=S1;n=storage;s=signature", "10.11.12.13", "GET", null));
// valid values
String token = "v=S1;d=coretech;n=storage;s=signature";
Principal p = principalAuthority.authenticate(token, "10.11.12.13", "GET", null);
assertNotNull(p);
assertEquals(p.getDomain(), "coretech");
assertEquals(p.getName(), "storage");
assertEquals(p.getCredentials(), token);
assertNull(p.getRoles());
}
Aggregations