Search in sources :

Example 1 with KerberosAuthority

use of com.yahoo.athenz.auth.impl.KerberosAuthority in project athenz by yahoo.

the class KerberosAuthorityTest method testIsTargetPrincipalIlligal.

@Test(groups = "kerberos-tests")
public void testIsTargetPrincipalIlligal() {
    KerberosAuthority check = new KerberosAuthority();
    assertFalse(check.isTargetPrincipal(null, null));
}
Also used : KerberosAuthority(com.yahoo.athenz.auth.impl.KerberosAuthority) BeforeTest(org.testng.annotations.BeforeTest) Test(org.testng.annotations.Test)

Example 2 with KerberosAuthority

use of com.yahoo.athenz.auth.impl.KerberosAuthority in project athenz by yahoo.

the class KerberosAuthorityTest method testKerberosAuthorityMockPrivExcAction.

@Test(groups = "kerberos-tests")
public void testKerberosAuthorityMockPrivExcAction() throws Exception {
    System.setProperty(KerberosToken.KRB_PROP_TOKEN_PRIV_ACTION, "com.yahoo.athenz.auth.impl.MockPrivExcAction");
    System.setProperty(KerberosToken.KRB_PROP_TOKEN_PRIV_ACTION + "_TEST_REALM", "USER_REALM");
    String token = "YIGeBgYrBgEFBQKggZMwgZCgGjAYBgorBgEEAYI3AgIeBgorBgEEAYI3AgIKonIEcE5FR09FWFRTAAfakecreds";
    System.setProperty(KerberosAuthority.KRB_PROP_SVCPRPL, "myserver@EXAMPLE.COM");
    System.setProperty(KerberosAuthority.KRB_PROP_LOGIN_CB_CLASS, KRB_LOGIN_CB_CLASS);
    System.setProperty(KerberosAuthority.KRB_PROP_KEYTAB, "src/test/resources/example.keytab");
    KerberosAuthority authority = new KerberosAuthority();
    authority.initialize();
    String creds = KerberosToken.KRB_AUTH_VAL_FLD + " " + token;
    String remoteAddr = "localhost";
    KerberosToken ktoken = new KerberosToken(creds, remoteAddr);
    boolean ret = ktoken.validate(null, null);
    assertEquals(ret, true);
    StringBuilder errMsg = new StringBuilder();
    Principal principal = authority.authenticate(ktoken.getSignedToken(), null, "GET", errMsg);
    assertNotNull(principal);
    assertNotNull(principal.getAuthority());
    assertEquals(principal.getCredentials(), ktoken.getSignedToken());
    assertEquals(principal.getDomain(), ktoken.getDomain());
    assertEquals(principal.getDomain(), KerberosToken.USER_DOMAIN);
    assertEquals(principal.getName(), ktoken.getUserName());
    assertTrue(principal.getName().indexOf('@') == -1);
    principal = authority.authenticate(ktoken.getSignedToken(), null, "GET", null);
    assertNotNull(principal);
    // test with ygrid realm
    System.setProperty(KerberosToken.KRB_PROP_TOKEN_PRIV_ACTION + "_TEST_REALM", KerberosToken.KRB_USER_REALM);
    ktoken = new KerberosToken(creds, remoteAddr);
    ret = ktoken.validate(null, null);
    assertEquals(ret, true);
    errMsg = new StringBuilder();
    principal = authority.authenticate(ktoken.getSignedToken(), null, "GET", errMsg);
    assertNotNull(principal);
    assertNotNull(principal.getAuthority());
    assertEquals(principal.getCredentials(), ktoken.getSignedToken());
    assertEquals(principal.getDomain(), ktoken.getDomain());
    assertEquals(principal.getDomain(), KerberosToken.KRB_USER_DOMAIN);
    assertEquals(principal.getName(), ktoken.getUserName());
    assertTrue(principal.getName().indexOf('@') == -1);
    principal = authority.authenticate(ktoken.getSignedToken(), null, "GET", null);
    assertNotNull(principal);
    // test with invalid realm
    System.setProperty(KerberosToken.KRB_PROP_TOKEN_PRIV_ACTION + "_TEST_REALM", "REALM.SOMECOMPANY.COM");
    ktoken = new KerberosToken(creds, remoteAddr);
    ret = ktoken.validate(null, null);
    assertEquals(ret, false);
    errMsg = new StringBuilder();
    principal = authority.authenticate(ktoken.getSignedToken(), null, "GET", errMsg);
    assertNull(principal);
    principal = authority.authenticate(ktoken.getSignedToken(), null, "GET", null);
    assertNull(principal);
    principal = authority.authenticate(null, null, "GET", null);
    assertNull(principal);
    System.clearProperty(KerberosToken.KRB_PROP_TOKEN_PRIV_ACTION);
    System.clearProperty(KerberosAuthority.KRB_PROP_SVCPRPL);
    System.clearProperty(KerberosAuthority.KRB_PROP_LOGIN_CB_CLASS);
    System.clearProperty(KerberosAuthority.KRB_PROP_KEYTAB);
}
Also used : KerberosToken(com.yahoo.athenz.auth.token.KerberosToken) Principal(com.yahoo.athenz.auth.Principal) KerberosPrincipal(javax.security.auth.kerberos.KerberosPrincipal) KerberosAuthority(com.yahoo.athenz.auth.impl.KerberosAuthority) BeforeTest(org.testng.annotations.BeforeTest) Test(org.testng.annotations.Test)

Example 3 with KerberosAuthority

use of com.yahoo.athenz.auth.impl.KerberosAuthority in project athenz by yahoo.

the class KerberosAuthorityTest method testKerberosAuthorityRefreshLogin.

@Test(groups = "kerberos-tests")
public void testKerberosAuthorityRefreshLogin() {
    System.setProperty(KerberosAuthority.KRB_PROP_LOGIN_WINDOW, "1000");
    System.setProperty(KerberosAuthority.KRB_PROP_KEYTAB, "src/test/resources/example.keytab");
    System.setProperty(KerberosAuthority.KRB_PROP_SVCPRPL, "myserver@EXAMPLE.COM");
    System.setProperty(KerberosAuthority.KRB_PROP_LOGIN_CB_CLASS, KRB_LOGIN_CB_CLASS);
    System.setProperty("sun.security.krb5.debug", "true");
    KerberosAuthority kauth = new KerberosAuthority();
    kauth.initialize();
    Exception initState = kauth.getInitState();
    assertNull(initState);
    long lastLogin = kauth.getLastLogin();
    long now = System.currentTimeMillis();
    assertTrue(lastLogin <= now);
    long loginWindow = kauth.getLoginWindow();
    assertEquals(loginWindow, 1000);
    boolean refreshed = kauth.refreshLogin("myserver@EXAMPLE.COM");
    assertEquals(refreshed, true);
    initState = kauth.getInitState();
    assertNull(initState);
    try {
        Thread.sleep(2000);
    } catch (Exception exc) {
        System.out.println("testKerberosAuthorityLogin: sleep failed: continuing...");
    }
    refreshed = kauth.refreshLogin("myserver@EXAMPLE.COM");
    assertEquals(refreshed, true);
    initState = kauth.getInitState();
    assertNull(initState);
    System.clearProperty(KerberosAuthority.KRB_PROP_LOGIN_WINDOW);
    System.clearProperty(KerberosAuthority.KRB_PROP_SVCPRPL);
    System.clearProperty(KerberosAuthority.KRB_PROP_KEYTAB);
    System.clearProperty(KerberosAuthority.KRB_PROP_LOGIN_CB_CLASS);
}
Also used : KerberosAuthority(com.yahoo.athenz.auth.impl.KerberosAuthority) BeforeTest(org.testng.annotations.BeforeTest) Test(org.testng.annotations.Test)

Example 4 with KerberosAuthority

use of com.yahoo.athenz.auth.impl.KerberosAuthority in project athenz by yahoo.

the class KerberosAuthorityTest method testSetInitState.

@Test(groups = "kerberos-tests")
public void testSetInitState() throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException {
    Class<KerberosAuthority> c = KerberosAuthority.class;
    KerberosAuthority check = new KerberosAuthority();
    Exception e = null;
    check.setInitState(e);
    Field f = c.getDeclaredField("initState");
    f.setAccessible(true);
    Exception m = (Exception) f.get(check);
    assertNull(m);
}
Also used : Field(java.lang.reflect.Field) KerberosAuthority(com.yahoo.athenz.auth.impl.KerberosAuthority) BeforeTest(org.testng.annotations.BeforeTest) Test(org.testng.annotations.Test)

Example 5 with KerberosAuthority

use of com.yahoo.athenz.auth.impl.KerberosAuthority in project athenz by yahoo.

the class KerberosAuthorityTest method testSetLoginWindow.

@Test(groups = "kerberos-tests")
public void testSetLoginWindow() throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException {
    Class<KerberosAuthority> c = KerberosAuthority.class;
    KerberosAuthority check = new KerberosAuthority();
    check.setLoginWindow((long) 100);
    Field f = c.getDeclaredField("loginWindow");
    f.setAccessible(true);
    long m = (long) f.get(check);
    assertEquals(m, 100);
}
Also used : Field(java.lang.reflect.Field) KerberosAuthority(com.yahoo.athenz.auth.impl.KerberosAuthority) BeforeTest(org.testng.annotations.BeforeTest) Test(org.testng.annotations.Test)

Aggregations

KerberosAuthority (com.yahoo.athenz.auth.impl.KerberosAuthority)10 BeforeTest (org.testng.annotations.BeforeTest)10 Test (org.testng.annotations.Test)10 KerberosPrincipal (javax.security.auth.kerberos.KerberosPrincipal)3 Principal (com.yahoo.athenz.auth.Principal)2 KerberosToken (com.yahoo.athenz.auth.token.KerberosToken)2 Field (java.lang.reflect.Field)2 KerberosTicket (javax.security.auth.kerberos.KerberosTicket)1