Search in sources :

Example 6 with Assertion

use of com.yahoo.athenz.zms.Assertion in project athenz by yahoo.

the class ZMSUtilsTest method testAssumeRoleResourceMatch.

@Test
public void testAssumeRoleResourceMatch() {
    Assertion assertion = new Assertion().setAction("assume_role").setEffect(AssertionEffect.ALLOW).setRole("domain2:role.role1").setResource("domain1:role.role1");
    assertTrue(ZMSUtils.assumeRoleResourceMatch("domain1:role.role1", assertion));
    assertion = new Assertion().setAction("assume_role").setEffect(AssertionEffect.ALLOW).setRole("domain2:role.role1").setResource("domain1:role.*");
    assertTrue(ZMSUtils.assumeRoleResourceMatch("domain1:role.role1", assertion));
    assertion = new Assertion().setAction("assume_role").setEffect(AssertionEffect.ALLOW).setRole("domain2:role.role1").setResource("domain1:*");
    assertTrue(ZMSUtils.assumeRoleResourceMatch("domain1:role.role1", assertion));
    assertion = new Assertion().setAction("assume_role").setEffect(AssertionEffect.ALLOW).setRole("domain2:role.role1").setResource("*:role.role1");
    assertTrue(ZMSUtils.assumeRoleResourceMatch("domain1:role.role1", assertion));
}
Also used : Assertion(com.yahoo.athenz.zms.Assertion) Test(org.testng.annotations.Test)

Example 7 with Assertion

use of com.yahoo.athenz.zms.Assertion in project athenz by yahoo.

the class JDBCConnectionTest method testGetAssertion.

@Test
public void testGetAssertion() throws Exception {
    JDBCConnection jdbcConn = new JDBCConnection(mockConn, true);
    Mockito.when(mockResultSet.next()).thenReturn(true);
    Mockito.when(mockResultSet.getString(ZMSConsts.DB_COLUMN_ROLE)).thenReturn("role1");
    Mockito.when(mockResultSet.getString(ZMSConsts.DB_COLUMN_RESOURCE)).thenReturn("my-domain:*");
    Mockito.when(mockResultSet.getString(ZMSConsts.DB_COLUMN_ACTION)).thenReturn("*");
    Mockito.when(mockResultSet.getString(ZMSConsts.DB_COLUMN_EFFECT)).thenReturn("ALLOW");
    Assertion assertion = jdbcConn.getAssertion("my-domain", "policy1", Long.valueOf(101));
    assertEquals("my-domain:role.role1", assertion.getRole());
    assertEquals("my-domain:*", assertion.getResource());
    assertEquals("*", assertion.getAction());
    assertEquals("ALLOW", assertion.getEffect().toString());
    Mockito.verify(mockPrepStmt, times(1)).setInt(1, 101);
    Mockito.verify(mockPrepStmt, times(1)).setString(2, "my-domain");
    Mockito.verify(mockPrepStmt, times(1)).setString(3, "policy1");
    jdbcConn.close();
}
Also used : Assertion(com.yahoo.athenz.zms.Assertion) JDBCConnection(com.yahoo.athenz.zms.store.jdbc.JDBCConnection) Test(org.testng.annotations.Test)

Example 8 with Assertion

use of com.yahoo.athenz.zms.Assertion in project athenz by yahoo.

the class ZMSUtils method addAssertion.

public static void addAssertion(Policy policy, String resource, String action, String role, AssertionEffect effect) {
    List<Assertion> assertions = policy.getAssertions();
    if (assertions == null) {
        assertions = new ArrayList<>();
        policy.setAssertions(assertions);
    }
    Assertion assertion = new Assertion().setAction(action).setResource(resource).setRole(role);
    assertions.add(assertion);
}
Also used : Assertion(com.yahoo.athenz.zms.Assertion)

Example 9 with Assertion

use of com.yahoo.athenz.zms.Assertion in project athenz by yahoo.

the class JDBCConnection method listAssertions.

@Override
public List<Assertion> listAssertions(String domainName, String policyName) {
    final String caller = "listAssertions";
    int domainId = getDomainId(domainName);
    if (domainId == 0) {
        throw notFoundError(caller, ZMSConsts.OBJECT_DOMAIN, domainName);
    }
    int policyId = getPolicyId(domainId, policyName);
    if (policyId == 0) {
        throw notFoundError(caller, ZMSConsts.OBJECT_POLICY, ZMSUtils.policyResourceName(domainName, policyName));
    }
    List<Assertion> assertions = new ArrayList<>();
    try (PreparedStatement ps = con.prepareStatement(SQL_LIST_ASSERTION)) {
        ps.setInt(1, policyId);
        try (ResultSet rs = executeQuery(ps, caller)) {
            while (rs.next()) {
                Assertion assertion = new Assertion();
                assertion.setRole(ZMSUtils.roleResourceName(domainName, rs.getString(ZMSConsts.DB_COLUMN_ROLE)));
                assertion.setResource(rs.getString(ZMSConsts.DB_COLUMN_RESOURCE));
                assertion.setAction(rs.getString(ZMSConsts.DB_COLUMN_ACTION));
                assertion.setEffect(AssertionEffect.valueOf(rs.getString(ZMSConsts.DB_COLUMN_EFFECT)));
                assertion.setId((long) rs.getInt(ZMSConsts.DB_COLUMN_ASSERT_ID));
                assertions.add(assertion);
            }
        }
    } catch (SQLException ex) {
        throw sqlError(ex, caller);
    }
    return assertions;
}
Also used : SQLException(java.sql.SQLException) Assertion(com.yahoo.athenz.zms.Assertion) ArrayList(java.util.ArrayList) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement)

Example 10 with Assertion

use of com.yahoo.athenz.zms.Assertion in project athenz by yahoo.

the class JDBCConnectionTest method testAddRoleAssertionsEmptyList.

@Test
public void testAddRoleAssertionsEmptyList() throws SQLException {
    JDBCConnection jdbcConn = new JDBCConnection(mockConn, true);
    List<Assertion> principalAssertions = new ArrayList<>();
    jdbcConn.addRoleAssertions(principalAssertions, null, null);
    assertEquals(0, principalAssertions.size());
    jdbcConn.addRoleAssertions(principalAssertions, new ArrayList<Assertion>(), null);
    assertEquals(0, principalAssertions.size());
    jdbcConn.close();
}
Also used : Assertion(com.yahoo.athenz.zms.Assertion) ArrayList(java.util.ArrayList) JDBCConnection(com.yahoo.athenz.zms.store.jdbc.JDBCConnection) Test(org.testng.annotations.Test)

Aggregations

Assertion (com.yahoo.athenz.zms.Assertion)61 Test (org.testng.annotations.Test)38 ArrayList (java.util.ArrayList)29 Policy (com.yahoo.athenz.zms.Policy)23 Role (com.yahoo.athenz.zms.Role)19 JDBCConnection (com.yahoo.athenz.zms.store.jdbc.JDBCConnection)16 RoleMember (com.yahoo.athenz.zms.RoleMember)11 DomainData (com.yahoo.athenz.zms.DomainData)10 HashMap (java.util.HashMap)9 SQLException (java.sql.SQLException)8 SignedDomain (com.yahoo.athenz.zms.SignedDomain)7 DataCache (com.yahoo.athenz.zts.cache.DataCache)7 Domain (com.yahoo.athenz.zms.Domain)5 ResourceAccessList (com.yahoo.athenz.zms.ResourceAccessList)5 ResourceAccess (com.yahoo.athenz.zms.ResourceAccess)4 ResourceException (com.yahoo.athenz.zms.ResourceException)4 PreparedStatement (java.sql.PreparedStatement)4 ResultSet (java.sql.ResultSet)4 DomainModifiedList (com.yahoo.athenz.zms.DomainModifiedList)3 ServiceIdentity (com.yahoo.athenz.zms.ServiceIdentity)3