Search in sources :

Example 66 with Principal

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);
    }
}
Also used : ChangeLogStore(com.yahoo.athenz.zts.store.ChangeLogStore) MockZMSFileChangeLogStore(com.yahoo.athenz.zts.store.impl.MockZMSFileChangeLogStore) ZMSFileChangeLogStore(com.yahoo.athenz.zts.store.impl.ZMSFileChangeLogStore) MockZMSFileChangeLogStore(com.yahoo.athenz.zts.store.impl.MockZMSFileChangeLogStore) ZMSFileChangeLogStore(com.yahoo.athenz.zts.store.impl.ZMSFileChangeLogStore) WebApplicationException(javax.ws.rs.WebApplicationException) DataStore(com.yahoo.athenz.zts.store.DataStore) SignedDomain(com.yahoo.athenz.zms.SignedDomain) SimplePrincipal(com.yahoo.athenz.auth.impl.SimplePrincipal) Principal(com.yahoo.athenz.auth.Principal) Test(org.testng.annotations.Test)

Example 67 with Principal

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"));
}
Also used : SignedDomain(com.yahoo.athenz.zms.SignedDomain) SimplePrincipal(com.yahoo.athenz.auth.impl.SimplePrincipal) Principal(com.yahoo.athenz.auth.Principal) Test(org.testng.annotations.Test)

Example 68 with Principal

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());
}
Also used : SignedDomain(com.yahoo.athenz.zms.SignedDomain) SimplePrincipal(com.yahoo.athenz.auth.impl.SimplePrincipal) Principal(com.yahoo.athenz.auth.Principal) Test(org.testng.annotations.Test)

Example 69 with Principal

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;
}
Also used : Principal(com.yahoo.athenz.auth.Principal) SimplePrincipal(com.yahoo.athenz.auth.impl.SimplePrincipal)

Example 70 with Principal

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());
}
Also used : DebugPrincipalAuthority(com.yahoo.athenz.common.server.debug.DebugPrincipalAuthority) Authority(com.yahoo.athenz.auth.Authority) DebugPrincipalAuthority(com.yahoo.athenz.common.server.debug.DebugPrincipalAuthority) Principal(com.yahoo.athenz.auth.Principal) Test(org.testng.annotations.Test)

Aggregations

Principal (com.yahoo.athenz.auth.Principal)259 SimplePrincipal (com.yahoo.athenz.auth.impl.SimplePrincipal)219 Test (org.testng.annotations.Test)168 Authority (com.yahoo.athenz.auth.Authority)66 PrincipalAuthority (com.yahoo.athenz.auth.impl.PrincipalAuthority)52 ArrayList (java.util.ArrayList)35 SignedDomain (com.yahoo.athenz.zms.SignedDomain)33 BeforeTest (org.testng.annotations.BeforeTest)17 AthenzDomain (com.yahoo.athenz.zms.store.AthenzDomain)14 SimpleServiceIdentityProvider (com.yahoo.athenz.auth.impl.SimpleServiceIdentityProvider)13 PrincipalToken (com.yahoo.athenz.auth.token.PrincipalToken)13 AuditLogMsgBuilder (com.yahoo.athenz.common.server.log.AuditLogMsgBuilder)13 IOException (java.io.IOException)13 HttpServletRequest (javax.servlet.http.HttpServletRequest)12 KeyStore (com.yahoo.athenz.auth.KeyStore)11 UnsupportedEncodingException (java.io.UnsupportedEncodingException)10 WebApplicationException (javax.ws.rs.WebApplicationException)10 X509Certificate (java.security.cert.X509Certificate)9 ServiceIdentityProvider (com.yahoo.athenz.auth.ServiceIdentityProvider)8 CertificateAuthority (com.yahoo.athenz.auth.impl.CertificateAuthority)8