Search in sources :

Example 96 with Principal

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

the class SimpleServiceIdentityProviderTest method testSimpleIdentityDefaultV1.

@Test
public void testSimpleIdentityDefaultV1() {
    PrivateKey key = Crypto.loadPrivateKey(servicePrivateKeyStringK1);
    SimpleServiceIdentityProvider provider = new SimpleServiceIdentityProvider("coretech", "athenz", key, "1");
    Principal user = provider.getIdentity("coretech", "athenz");
    assertNotNull(user);
    assertTrue(user.getIssueTime() != 0);
    String token = user.getCredentials();
    PrincipalToken prToken = new PrincipalToken(token);
    assertTrue(prToken.validate(servicePublicKeyStringK1, 0, false));
    assertEquals(prToken.getKeyId(), "1");
}
Also used : PrivateKey(java.security.PrivateKey) PrincipalToken(com.yahoo.athenz.auth.token.PrincipalToken) Principal(com.yahoo.athenz.auth.Principal) SimpleServiceIdentityProvider(com.yahoo.athenz.auth.impl.SimpleServiceIdentityProvider) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest)

Example 97 with Principal

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

the class SimpleServiceIdentityProviderTest method testSimpleIdentityPrivateKeyDomainMismatch.

@Test
public void testSimpleIdentityPrivateKeyDomainMismatch() {
    PrivateKey key = Crypto.loadPrivateKey(servicePrivateKeyStringK1);
    SimpleServiceIdentityProvider provider = new SimpleServiceIdentityProvider("coretech", "athenz", key, "1");
    Principal user = provider.getIdentity("coretech2", "athenz");
    assertNull(user);
    user = provider.getIdentity("coretech", "athenz2");
    assertNull(user);
}
Also used : PrivateKey(java.security.PrivateKey) Principal(com.yahoo.athenz.auth.Principal) SimpleServiceIdentityProvider(com.yahoo.athenz.auth.impl.SimpleServiceIdentityProvider) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest)

Example 98 with Principal

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

the class PrincipalAuthorityTest method testAuthenticateIlligal.

@Test
public void testAuthenticateIlligal() throws IOException {
    PrincipalAuthority serviceAuthority = new PrincipalAuthority();
    Principal principal = serviceAuthority.authenticate("aaaa", null, "GET", null);
    assertNull(principal);
}
Also used : PrincipalAuthority(com.yahoo.athenz.auth.impl.PrincipalAuthority) Principal(com.yahoo.athenz.auth.Principal) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest)

Example 99 with Principal

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

the class PrincipalAuthorityTest method testPrincipalAuthorityAuthenticateIlligal.

@Test
public void testPrincipalAuthorityAuthenticateIlligal() throws IOException, CryptoException {
    PrincipalAuthority serviceAuthority = new PrincipalAuthority();
    KeyStore keyStore = Mockito.mock(KeyStore.class);
    serviceAuthority.setKeyStore(keyStore);
    String t = "v=S1;d=domain;n=hoge;bs=aaaa;s=signatur";
    Principal check = serviceAuthority.authenticate(t, "10", "10", null);
    assertNull(check);
}
Also used : KeyStore(com.yahoo.athenz.auth.KeyStore) PrincipalAuthority(com.yahoo.athenz.auth.impl.PrincipalAuthority) Principal(com.yahoo.athenz.auth.Principal) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest)

Example 100 with Principal

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

the class PrincipalAuthorityTest method testPrincipalAuthority_TamperedToken.

@Test
public void testPrincipalAuthority_TamperedToken() throws IOException, CryptoException {
    PrincipalAuthority serviceAuthority = new PrincipalAuthority();
    KeyStore keyStore = new KeyStoreMock();
    serviceAuthority.setKeyStore(keyStore);
    // Create and sign token
    PrincipalToken serviceToken = new PrincipalToken.Builder(svcVersion, svcDomain, svcName).host(host).salt(salt).expirationWindow(expirationTime).build();
    serviceToken.sign(servicePrivateKeyStringK0);
    String tokenToTamper = serviceToken.getSignedToken();
    StringBuilder errMsg = new StringBuilder();
    Principal principal = serviceAuthority.authenticate(tamperWithServiceToken(tokenToTamper), null, "GET", errMsg);
    // Service Authority should return null when authenticate() fails
    assertNull(principal);
    assertTrue(!errMsg.toString().isEmpty());
    assertTrue(errMsg.toString().contains("authenticate"));
    principal = serviceAuthority.authenticate(tamperWithServiceToken(tokenToTamper), null, "GET", null);
    assertNull(principal);
}
Also used : PrincipalToken(com.yahoo.athenz.auth.token.PrincipalToken) KeyStore(com.yahoo.athenz.auth.KeyStore) PrincipalAuthority(com.yahoo.athenz.auth.impl.PrincipalAuthority) Principal(com.yahoo.athenz.auth.Principal) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest)

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