Search in sources :

Example 21 with Assertion

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

the class SignUtils method asStruct.

private static Struct asStruct(com.yahoo.athenz.zts.Policy policy) {
    // all of our fields are in canonical order based
    // on their attribute name
    Struct struct = new Struct();
    List<com.yahoo.athenz.zts.Assertion> assertions = policy.getAssertions();
    if (assertions != null && !assertions.isEmpty()) {
        Array assertionsArray = new Array();
        for (com.yahoo.athenz.zts.Assertion assertion : assertions) {
            Struct structAssertion = new Struct();
            appendObject(structAssertion, ATTR_ACTION, assertion.getAction());
            appendObject(structAssertion, ATTR_EFFECT, assertion.getEffect());
            appendObject(structAssertion, ATTR_RESOURCE, assertion.getResource());
            appendObject(structAssertion, ATTR_ROLE, assertion.getRole());
            assertionsArray.add(structAssertion);
        }
        appendArray(struct, ATTR_ASSERTIONS, assertionsArray);
    }
    appendObject(struct, ATTR_MODIFIED, policy.getModified());
    appendObject(struct, ATTR_NAME, policy.getName());
    return struct;
}
Also used : Array(com.yahoo.rdl.Array) Assertion(com.yahoo.athenz.zms.Assertion) Struct(com.yahoo.rdl.Struct)

Example 22 with Assertion

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

the class FileConnectionTest method testAssertionMatch.

@Test
public void testAssertionMatch() {
    File fileDir = new File("/home/athenz/zms_store");
    File quotaDir = new File("/home/athenz/zms_quota");
    Assertion assertion1 = new Assertion();
    assertion1.setAction("UPDATE").setResource("resource").setRole("zmsRole");
    Assertion assertion2 = new Assertion();
    assertion2.setAction("UPDATE").setResource("resource").setRole("zmsRole");
    try (FileConnection fileconnection = new FileConnection(fileDir, quotaDir)) {
        assertTrue(fileconnection.assertionMatch(assertion1, assertion2));
        Assertion assertion3 = new Assertion();
        assertion3.setAction("UPDATE").setResource("resource").setRole("zmsRole");
        Assertion assertion4 = new Assertion();
        assertion4.setAction("Delete").setResource("resource").setRole("zmsRole");
        assertFalse(fileconnection.assertionMatch(assertion3, assertion4));
        Assertion assertion5 = new Assertion();
        assertion5.setAction("UPDATE").setResource("resource1").setRole("zmsRole");
        Assertion assertion6 = new Assertion();
        assertion6.setAction("UPDATE").setResource("resource2").setRole("zmsRole");
        assertFalse(fileconnection.assertionMatch(assertion5, assertion6));
        Assertion assertion7 = new Assertion();
        assertion7.setAction("UPDATE").setResource("resource").setRole("zmsRole1");
        Assertion assertion8 = new Assertion();
        assertion8.setAction("UPDATE").setResource("resource").setRole("zmsRole2");
        assertFalse(fileconnection.assertionMatch(assertion7, assertion8));
        Assertion assertion9 = new Assertion();
        AssertionEffect effect1 = AssertionEffect.ALLOW;
        assertion9.setAction("UPDATE").setResource("resource").setRole("zmsRole").setEffect(effect1);
        Assertion assertion10 = new Assertion();
        assertion10.setAction("UPDATE").setResource("resource").setRole("zmsRole").setEffect(effect1);
        assertTrue(fileconnection.assertionMatch(assertion9, assertion10));
        Assertion assertion11 = new Assertion();
        AssertionEffect effect2 = AssertionEffect.ALLOW;
        AssertionEffect effect3 = AssertionEffect.DENY;
        assertion11.setAction("UPDATE").setResource("resource").setRole("zmsRole").setEffect(effect2);
        Assertion assertion12 = new Assertion();
        assertion12.setAction("UPDATE").setResource("resource").setRole("zmsRole").setEffect(effect3);
        assertFalse(fileconnection.assertionMatch(assertion11, assertion12));
    }
}
Also used : AssertionEffect(com.yahoo.athenz.zms.AssertionEffect) Assertion(com.yahoo.athenz.zms.Assertion) File(java.io.File) Test(org.testng.annotations.Test)

Example 23 with Assertion

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

the class FileConnectionTest method testInsertAssertion.

@Test
public void testInsertAssertion() {
    File fileDir = new File("/home/athenz/zms_store");
    File quotaDir = new File("/home/athenz/zms_quota");
    try (FileConnection fileconnection = new FileConnection(fileDir, quotaDir)) {
        Assertion assertion = new Assertion();
        try {
            fileconnection.insertAssertion("Domain1", "policy1", assertion);
        } catch (Exception ex) {
            assertTrue(true);
        }
    }
}
Also used : Assertion(com.yahoo.athenz.zms.Assertion) File(java.io.File) Test(org.testng.annotations.Test)

Example 24 with Assertion

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

the class DataCacheTest method testPolicyWithInvalidAssertionRole.

@Test
public void testPolicyWithInvalidAssertionRole() {
    Domain domain = new Domain();
    domain.setName("testDomain");
    Role role1 = new Role();
    role1.setName("testDomain.role.role1");
    List<RoleMember> members1 = new ArrayList<>();
    members1.add(new RoleMember().setMemberName("user_domain.user1"));
    members1.add(new RoleMember().setMemberName("user_domain.user2"));
    role1.setRoleMembers(members1);
    Role role2 = new Role();
    role2.setName("testDomain.role.role2");
    List<RoleMember> members2 = new ArrayList<>();
    members2.add(new RoleMember().setMemberName("user_domain.user2"));
    role2.setRoleMembers(members2);
    Role role3 = new Role();
    role3.setName("testDomain.role.role3");
    List<RoleMember> members3 = new ArrayList<>();
    members3.add(new RoleMember().setMemberName("user_domain.user3"));
    role3.setRoleMembers(members3);
    Policy policy = new Policy();
    policy.setName("testDomain.policy.policy1");
    Assertion assertion = new Assertion();
    assertion.setAction("assume_role");
    assertion.setEffect(AssertionEffect.ALLOW);
    assertion.setResource("testDomain.role");
    assertion.setRole("testDomain.role.Invalid");
    List<Assertion> assertList = new ArrayList<Assertion>();
    assertList.add(assertion);
    policy.setAssertions(assertList);
    HashMap<String, Role> roleList = new HashMap<>();
    roleList.put(role1.getName(), role1);
    roleList.put(role2.getName(), role2);
    roleList.put(role3.getName(), role3);
    DataCache cache = new DataCache();
    cache.processRole(role1);
    cache.processRole(role2);
    cache.processRole(role3);
    cache.processPolicy(domain.getName(), policy, roleList);
    Set<MemberRole> set1 = cache.getMemberRoleSet("user_domain.user1");
    assertNotNull(set1);
    assertTrue(set1.contains(new MemberRole("testDomain.role.role1", 0)));
    assertEquals(set1.size(), 1);
    Set<MemberRole> set2 = cache.getMemberRoleSet("user_domain.user2");
    assertNotNull(set2);
    assertTrue(set2.contains(new MemberRole("testDomain.role.role1", 0)));
    assertTrue(set2.contains(new MemberRole("testDomain.role.role2", 0)));
    assertEquals(set2.size(), 2);
    Set<MemberRole> set3 = cache.getMemberRoleSet("user_domain.user3");
    assertNotNull(set3);
    assertTrue(set3.contains(new MemberRole("testDomain.role.role3", 0)));
    assertEquals(set3.size(), 1);
}
Also used : Policy(com.yahoo.athenz.zms.Policy) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Assertion(com.yahoo.athenz.zms.Assertion) DataCache(com.yahoo.athenz.zts.cache.DataCache) Role(com.yahoo.athenz.zms.Role) Domain(com.yahoo.athenz.zms.Domain) RoleMember(com.yahoo.athenz.zms.RoleMember) Test(org.testng.annotations.Test)

Example 25 with Assertion

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

the class DataCacheTest method testPolicyWithAssertionRoleNoMember.

@Test
public void testPolicyWithAssertionRoleNoMember() {
    Domain domain = new Domain();
    domain.setName("testDomain");
    Role role1 = new Role();
    role1.setName("testDomain.role.role1");
    Role role2 = new Role();
    role2.setName("testDomain.role.role2");
    List<RoleMember> members2 = new ArrayList<>();
    members2.add(new RoleMember().setMemberName("user_domain.user2"));
    role2.setRoleMembers(members2);
    Role role3 = new Role();
    role3.setName("testDomain.role.role3");
    List<RoleMember> members3 = new ArrayList<>();
    members3.add(new RoleMember().setMemberName("user_domain.user3"));
    role3.setRoleMembers(members3);
    Policy policy = new Policy();
    policy.setName("testDomain.policy.policy1");
    Assertion assertion = new Assertion();
    assertion.setAction("assume_role");
    assertion.setEffect(AssertionEffect.ALLOW);
    assertion.setResource("testDomain.roleA");
    assertion.setRole("testDomain.role.role1");
    List<Assertion> assertList = new ArrayList<Assertion>();
    assertList.add(assertion);
    policy.setAssertions(assertList);
    HashMap<String, Role> roleList = new HashMap<>();
    roleList.put(role1.getName(), role1);
    roleList.put(role2.getName(), role2);
    roleList.put(role3.getName(), role3);
    DataCache cache = new DataCache();
    cache.processRole(role1);
    cache.processRole(role2);
    cache.processRole(role3);
    cache.processPolicy(domain.getName(), policy, roleList);
    Set<MemberRole> set1 = cache.getMemberRoleSet("user_domain.user1");
    assertNull(set1);
    Set<MemberRole> set2 = cache.getMemberRoleSet("user_domain.user2");
    assertNotNull(set2);
    assertTrue(set2.contains(new MemberRole("testDomain.role.role2", 0)));
    assertEquals(set2.size(), 1);
    Set<MemberRole> set3 = cache.getMemberRoleSet("user_domain.user3");
    assertNotNull(set3);
    assertTrue(set3.contains(new MemberRole("testDomain.role.role3", 0)));
    assertEquals(set3.size(), 1);
}
Also used : Policy(com.yahoo.athenz.zms.Policy) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Assertion(com.yahoo.athenz.zms.Assertion) DataCache(com.yahoo.athenz.zts.cache.DataCache) Role(com.yahoo.athenz.zms.Role) Domain(com.yahoo.athenz.zms.Domain) RoleMember(com.yahoo.athenz.zms.RoleMember) 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