Search in sources :

Example 6 with RoleAuthority

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

the class RoleAuthorityTest method testIsWriteOperationNull.

@Test
public void testIsWriteOperationNull() throws IOException {
    RoleAuthority roleAuthority = new RoleAuthority();
    roleAuthority.initialize();
    KeyStore keyStore = new KeyStoreMock();
    roleAuthority.setKeyStore(keyStore);
    // Add some roles
    List<String> roles = new ArrayList<String>();
    roles.add("storage.tenant.weather.updater");
    // Create and sign token with keyVersion = 0
    RoleToken roleToken = new RoleToken.Builder(rolVersion, svcDomain, roles).salt(salt).ip("127.0.0.1").expirationWindow(expirationTime).principal(".").keyId(testKeyVersionK0).build();
    roleToken.sign(ztsPrivateKeyStringK0);
    Principal principal = roleAuthority.authenticate(roleToken.getSignedToken(), "127.0.0.2", null, null);
    assertNotNull(principal);
}
Also used : RoleAuthority(com.yahoo.athenz.auth.impl.RoleAuthority) ArrayList(java.util.ArrayList) KeyStore(com.yahoo.athenz.auth.KeyStore) Principal(com.yahoo.athenz.auth.Principal) RoleToken(com.yahoo.athenz.auth.token.RoleToken) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest)

Example 7 with RoleAuthority

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

the class RoleAuthorityTest method testAuthenticateIlligal.

@Test
public void testAuthenticateIlligal() throws IOException {
    RoleAuthority roleAuthority = new RoleAuthority();
    roleAuthority.initialize();
    Principal principal = roleAuthority.authenticate("", "10.72.118.45", "GET", null);
    assertNull(principal);
    KeyStore keyStore = new KeyStoreMock();
    roleAuthority.setKeyStore(keyStore);
    // Add some roles
    List<String> roles = new ArrayList<String>();
    roles.add("storage.tenant.weather.updater");
    // Create and sign token with keyVersion = 0
    RoleToken roleToken = new RoleToken.Builder(rolVersion, svcDomain, roles).salt(salt).ip("127.0.0.1").expirationWindow(expirationTime).principal(".").keyId(testKeyVersionK0).build();
    roleToken.sign(ztsPrivateKeyStringK0);
    principal = roleAuthority.authenticate(roleToken.getSignedToken(), "127.0.0.2", "DELETE", null);
    assertNull(principal);
    roleToken = new RoleToken.Builder(rolVersion, svcDomain, roles).salt(salt).ip("127.0.0.1").expirationWindow(expirationTime).principal("illigal.joe").keyId(testKeyVersionK0).build();
    roleToken.sign(ztsPrivateKeyStringK0);
    principal = roleAuthority.authenticate(roleToken.getSignedToken(), "127.0.0.2", "DELETE", null);
    assertNotNull(principal);
}
Also used : RoleAuthority(com.yahoo.athenz.auth.impl.RoleAuthority) ArrayList(java.util.ArrayList) KeyStore(com.yahoo.athenz.auth.KeyStore) Principal(com.yahoo.athenz.auth.Principal) RoleToken(com.yahoo.athenz.auth.token.RoleToken) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest)

Example 8 with RoleAuthority

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

the class RoleAuthorityTest method testInitialize.

@Test
public void testInitialize() throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException {
    Class<RoleAuthority> c = RoleAuthority.class;
    RoleAuthority roleAuthority = new RoleAuthority();
    System.setProperty(RoleAuthority.ATHENZ_PROP_TOKEN_OFFSET, "-1");
    roleAuthority.initialize();
    Field f1 = c.getDeclaredField("allowedOffset");
    f1.setAccessible(true);
    int m = (Integer) f1.get(roleAuthority);
    assertEquals(m, 300);
    assertEquals(roleAuthority.userDomain, "user");
}
Also used : Field(java.lang.reflect.Field) RoleAuthority(com.yahoo.athenz.auth.impl.RoleAuthority) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest)

Aggregations

RoleAuthority (com.yahoo.athenz.auth.impl.RoleAuthority)8 BeforeTest (org.testng.annotations.BeforeTest)8 Test (org.testng.annotations.Test)8 KeyStore (com.yahoo.athenz.auth.KeyStore)7 Principal (com.yahoo.athenz.auth.Principal)7 RoleToken (com.yahoo.athenz.auth.token.RoleToken)7 ArrayList (java.util.ArrayList)7 Field (java.lang.reflect.Field)1