Search in sources :

Example 6 with Principal

use of com.yahoo.athenz.auth.Principal in project athenz by yahoo.

the class ZTSClientTest method testPrefetchInterval.

@Test
public void testPrefetchInterval() {
    Principal principal = SimplePrincipal.create("user_domain", "user", "auth_creds", PRINCIPAL_AUTHORITY);
    ZTSClient client = new ZTSClient("http://localhost:4080", principal);
    client.setPrefetchInterval(10L);
    assertEquals(client.getPrefetchInterval(), 10l);
    client.close();
}
Also used : SimplePrincipal(com.yahoo.athenz.auth.impl.SimplePrincipal) Principal(com.yahoo.athenz.auth.Principal) Test(org.testng.annotations.Test)

Example 7 with Principal

use of com.yahoo.athenz.auth.Principal in project athenz by yahoo.

the class ZTSClientTest method testGetRoleTokenCacheKeyMultipleRoles.

@Test
public void testGetRoleTokenCacheKeyMultipleRoles() {
    Principal principal = SimplePrincipal.create("user_domain", "user", "auth_creds", PRINCIPAL_AUTHORITY);
    ZTSClient client = new ZTSClient("http://localhost:4080/", principal);
    assertEquals(client.getRoleTokenCacheKey("coretech", "writers,admin,readers", "proxyuser"), "p=user_domain.user;d=coretech;r=admin,readers,writers;u=proxyuser");
    client.close();
}
Also used : SimplePrincipal(com.yahoo.athenz.auth.impl.SimplePrincipal) Principal(com.yahoo.athenz.auth.Principal) Test(org.testng.annotations.Test)

Example 8 with Principal

use of com.yahoo.athenz.auth.Principal in project athenz by yahoo.

the class ZTSClientTest method testHostnamVerifierDnsMatchNone.

@Test
public void testHostnamVerifierDnsMatchNone() {
    ZTSRDLClientMock ztsClientMock = new ZTSRDLClientMock();
    Principal principal = SimplePrincipal.create("user_domain", "user", "v=S1;d=user_domain;n=user;s=sig", PRINCIPAL_AUTHORITY);
    ZTSClient client = new ZTSClient("http://localhost:4080", principal);
    client.setZTSRDLGeneratedClient(ztsClientMock);
    ZTSClient.AWSHostNameVerifier hostnameVerifier = client.new AWSHostNameVerifier("host1");
    ArrayList<List<?>> altNames = new ArrayList<>();
    ArrayList<Object> rfcName = new ArrayList<>();
    rfcName.add(Integer.valueOf(1));
    rfcName.add("rfcname");
    altNames.add(rfcName);
    ArrayList<Object> dnsName = new ArrayList<>();
    dnsName.add(Integer.valueOf(3));
    dnsName.add("host1");
    altNames.add(dnsName);
    assertFalse(hostnameVerifier.matchDnsHostname(altNames));
    client.close();
}
Also used : ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) SimplePrincipal(com.yahoo.athenz.auth.impl.SimplePrincipal) Principal(com.yahoo.athenz.auth.Principal) Test(org.testng.annotations.Test)

Example 9 with Principal

use of com.yahoo.athenz.auth.Principal in project athenz by yahoo.

the class ZTSClientTest method testPostInstanceRefreshRequest.

@Test
public void testPostInstanceRefreshRequest() {
    Principal principal = SimplePrincipal.create("user_domain", "user", "auth_creds", PRINCIPAL_AUTHORITY);
    ZTSRDLClientMock ztsClientMock = new ZTSRDLClientMock();
    ZTSClient client = new ZTSClient("http://localhost:4080", principal);
    client.setZTSRDLGeneratedClient(ztsClientMock);
    InstanceRefreshRequest req = new InstanceRefreshRequest().setExpiryTime(600);
    Identity identity = client.postInstanceRefreshRequest("coretech", "unit", req);
    assertNotNull(identity);
    assertNotNull(identity.getServiceToken());
    client.close();
}
Also used : SimplePrincipal(com.yahoo.athenz.auth.impl.SimplePrincipal) Principal(com.yahoo.athenz.auth.Principal) Test(org.testng.annotations.Test)

Example 10 with Principal

use of com.yahoo.athenz.auth.Principal in project athenz by yahoo.

the class ZMSAuthorizerTest method testAuthorizerResourceWithDomain.

@Test
public void testAuthorizerResourceWithDomain() {
    ZMSClient client = getClient(systemAdminUser);
    String domain = "AuthorizerDom4";
    ZMSAuthorizer authorizer = new ZMSAuthorizer(zmsUrl, domain);
    assertNotNull(authorizer);
    // create 3 user client objects
    Principal p1 = createPrincipal("user1");
    Principal p2 = createPrincipal("user2");
    Principal p3 = createPrincipal("user3");
    ZMSRDLGeneratedClient c = Mockito.mock(ZMSRDLGeneratedClient.class);
    client.setZMSRDLGeneratedClient(c);
    Domain domainMock = Mockito.mock(Domain.class);
    Mockito.when(c.postTopLevelDomain(Mockito.<String>any(), Mockito.any(TopLevelDomain.class))).thenReturn(domainMock);
    setupAccess(client, domain);
    // only user1 and user3 have access to UPDATE/resource1
    ZMSClient mockZMSClient = Mockito.mock(ZMSClient.class);
    authorizer.setZMSClient(mockZMSClient);
    Access accessMock = Mockito.mock(Access.class);
    Mockito.when(mockZMSClient.getAccess("UPDATE", "AuthorizerDom4:resource1", "AuthorizerDom4")).thenReturn(accessMock);
    Mockito.when(accessMock.getGranted()).thenReturn(true, false, true);
    Mockito.when(c.getAccess("UPDATE", "AuthorizerDom4:resource1", "AuthorizerDom4", null)).thenReturn(accessMock);
    boolean access = authorizer.access("UPDATE", domain + ":resource1", p1, domain);
    assertTrue(access);
    access = authorizer.access("UPDATE", domain + ":resource1", p2, domain);
    assertFalse(access);
    access = authorizer.access("UPDATE", domain + ":resource1", p3, domain);
    assertTrue(access);
    TopLevelDomain topLevelDomainMock = Mockito.mock(TopLevelDomain.class);
    Mockito.when(c.deleteTopLevelDomain(domain, AUDIT_REF)).thenReturn(topLevelDomainMock);
    cleanUpAccess(domain);
}
Also used : ZMSAuthorizer(com.yahoo.athenz.zms.ZMSAuthorizer) Principal(com.yahoo.athenz.auth.Principal) SimplePrincipal(com.yahoo.athenz.auth.impl.SimplePrincipal) Test(org.testng.annotations.Test)

Aggregations

Principal (com.yahoo.athenz.auth.Principal)258 SimplePrincipal (com.yahoo.athenz.auth.impl.SimplePrincipal)218 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 AuditLogMsgBuilder (com.yahoo.athenz.common.server.log.AuditLogMsgBuilder)13 IOException (java.io.IOException)13 PrincipalToken (com.yahoo.athenz.auth.token.PrincipalToken)12 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