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));
}
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();
}
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);
}
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;
}
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();
}
Aggregations