Search in sources :

Example 1 with IPv4Condition

use of org.forgerock.openam.entitlement.conditions.environment.IPv4Condition in project OpenAM by OpenRock.

the class PrivilegeManagerTest method testAddPrivilege.

@Test
public void testAddPrivilege() throws Exception {
    if (!migrated) {
        return;
    }
    privilege = createPrivilege();
    PrivilegeManager prm = PrivilegeManager.getInstance("/", SubjectUtils.createSubject(adminToken));
    prm.add(privilege);
    Thread.sleep(1000);
    Privilege p = prm.findByName(PRIVILEGE_NAME);
    IPv4Condition ipc1 = (IPv4Condition) p.getCondition();
    if (!ipc1.getStartIp().equals(startIp)) {
        throw new Exception("PrivilegeManagerTest.testAddPrivilege():" + "READ startIp " + " does not equal set startIp");
    }
    if (!ipc1.getEndIp().equals(endIp)) {
        throw new Exception("PrivilegeManagerTest.testAddPrivilege():" + "READ endIp " + " does not equal set endIp");
    }
    if (!privilege.equals(p)) {
        throw new Exception("PrivilegeManagerTest.testAddPrivilege():" + "read privilege not" + "equal to saved privilege");
    }
    {
        EntitlementSubject subjectCollections = privilege.getSubject();
        if (subjectCollections instanceof OrSubject) {
            OrSubject orSbj = (OrSubject) subjectCollections;
            Set<EntitlementSubject> subjs = orSbj.getESubjects();
            for (EntitlementSubject sbj : subjs) {
                if (!sbj.equals(ua1) && !sbj.equals(ua2)) {
                    throw new Exception("PrivilegeManagerTest.testAddPrivilege: Subject does not matched.");
                }
            }
        }
    }
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) IPv4Condition(org.forgerock.openam.entitlement.conditions.environment.IPv4Condition) SMSException(com.sun.identity.sm.SMSException) IdRepoException(com.sun.identity.idm.IdRepoException) SSOException(com.iplanet.sso.SSOException) Test(org.testng.annotations.Test)

Example 2 with IPv4Condition

use of org.forgerock.openam.entitlement.conditions.environment.IPv4Condition in project OpenAM by OpenRock.

the class PrivilegeManagerTest method createPrivilege.

private Privilege createPrivilege() throws EntitlementException {
    Map<String, Boolean> actionValues = new HashMap<String, Boolean>();
    actionValues.put("GET", Boolean.TRUE);
    actionValues.put("POST", Boolean.FALSE);
    String resourceName = "http://www.privilegemanagertest.com:80";
    Entitlement entitlement = new Entitlement(APPL_NAME, resourceName, actionValues);
    entitlement.setName("ent1");
    String user11 = "id=user11,ou=user," + ServiceManager.getBaseDN();
    String user12 = "id=user12,ou=user," + ServiceManager.getBaseDN();
    ua1 = new OpenSSOUserSubject();
    ua1.setID(user11);
    ua2 = new OpenSSOUserSubject();
    ua2.setID(user12);
    Set<EntitlementSubject> subjects = new HashSet<EntitlementSubject>();
    subjects.add(ua1);
    subjects.add(ua2);
    OrSubject os = new OrSubject(subjects);
    IPv4Condition ipc = new IPv4Condition();
    ipc.setStartIpAndEndIp(startIp, endIp);
    SimpleTimeCondition tc = new SimpleTimeCondition();
    tc.setStartTime("08:00");
    tc.setEndTime("16:00");
    tc.setStartDay("mon");
    tc.setEndDay("fri");
    Set<EntitlementCondition> conditions = new HashSet<EntitlementCondition>();
    conditions.add(tc);
    StaticAttributes sa1 = new StaticAttributes();
    Set<String> aValues = new HashSet<String>();
    aValues.add("a10");
    aValues.add("a20");
    sa1.setPropertyName("a");
    sa1.setPropertyValues(aValues);
    sa1.setPResponseProviderName("sa");
    StaticAttributes sa2 = new StaticAttributes();
    Set<String> bValues = new HashSet<String>();
    bValues.add("b10");
    bValues.add("b20");
    sa2.setPropertyName("b");
    sa2.setPropertyValues(bValues);
    sa2.setPResponseProviderName("sa");
    UserAttributes uat1 = new UserAttributes();
    uat1.setPropertyName("email");
    uat1.setPResponseProviderName("ua");
    UserAttributes uat2 = new UserAttributes();
    uat2.setPropertyName("uid");
    uat2.setPResponseProviderName("ua");
    Set<ResourceAttribute> ra = new HashSet<ResourceAttribute>();
    ra.add(sa1);
    ra.add(sa2);
    ra.add(uat1);
    ra.add(uat2);
    Privilege priv = Privilege.getNewInstance();
    priv.setName(PRIVILEGE_NAME);
    priv.setEntitlement(entitlement);
    priv.setSubject(os);
    priv.setCondition(ipc);
    priv.setResourceAttributes(ra);
    priv.setDescription(PRIVILEGE_DESC);
    return priv;
}
Also used : HashMap(java.util.HashMap) SimpleTimeCondition(org.forgerock.openam.entitlement.conditions.environment.SimpleTimeCondition) IPv4Condition(org.forgerock.openam.entitlement.conditions.environment.IPv4Condition) OpenSSOUserSubject(com.sun.identity.entitlement.opensso.OpenSSOUserSubject) HashSet(java.util.HashSet)

Example 3 with IPv4Condition

use of org.forgerock.openam.entitlement.conditions.environment.IPv4Condition in project OpenAM by OpenRock.

the class PrivilegeManagerTest method testAddPrivilege2.

@Test(dependsOnMethods = { "testAddPrivilege" })
public void testAddPrivilege2() throws Exception {
    if (!migrated) {
        return;
    }
    privilege = createPrivilege();
    privilege.setName(PRIVILEGE_NAME2);
    PrivilegeManager prm = PrivilegeManager.getInstance("/", SubjectUtils.createSubject(adminToken));
    prm.add(privilege);
    Thread.sleep(1000);
    Privilege p = prm.findByName(PRIVILEGE_NAME2);
    IPv4Condition ipc1 = (IPv4Condition) p.getCondition();
    if (!ipc1.getStartIp().equals(startIp)) {
        throw new Exception("PrivilegeManagerTest.testAddPrivilege():" + "READ startIp " + " does not equal set startIp");
    }
    if (!ipc1.getEndIp().equals(endIp)) {
        throw new Exception("PrivilegeManagerTest.testAddPrivilege():" + "READ endIp " + " does not equal set endIp");
    }
    if (!privilege.equals(p)) {
        throw new Exception("PrivilegeManagerTest.testAddPrivilege():" + "read privilege not" + "equal to saved privilege");
    }
    {
        EntitlementSubject subjectCollections = privilege.getSubject();
        if (subjectCollections instanceof OrSubject) {
            OrSubject orSbj = (OrSubject) subjectCollections;
            Set<EntitlementSubject> subjs = orSbj.getESubjects();
            for (EntitlementSubject sbj : subjs) {
                if (!sbj.equals(ua1) && !sbj.equals(ua2)) {
                    throw new Exception("PrivilegeManagerTest.testAddPrivilege: Subject does not matched.");
                }
            }
        }
    }
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) IPv4Condition(org.forgerock.openam.entitlement.conditions.environment.IPv4Condition) SMSException(com.sun.identity.sm.SMSException) IdRepoException(com.sun.identity.idm.IdRepoException) SSOException(com.iplanet.sso.SSOException) Test(org.testng.annotations.Test)

Example 4 with IPv4Condition

use of org.forgerock.openam.entitlement.conditions.environment.IPv4Condition in project OpenAM by OpenRock.

the class NotConditionTest method testConstruction.

@Test
public void testConstruction() throws Exception {
    IPv4Condition ipc = new IPv4Condition();
    ipc.setStartIpAndEndIp("100.100.100.100", "200.200.200.200");
    NotCondition ac = new NotCondition(ipc);
    NotCondition ac1 = new NotCondition();
    ac1.setState(ac.getState());
    if (!ac1.equals(ac)) {
        throw new Exception("NotConditionTest.testConstruction():" + " NotCondition with setState does not equal NotCondition " + "with getState()");
    }
}
Also used : IPv4Condition(org.forgerock.openam.entitlement.conditions.environment.IPv4Condition) Test(org.testng.annotations.Test)

Example 5 with IPv4Condition

use of org.forgerock.openam.entitlement.conditions.environment.IPv4Condition in project OpenAM by OpenRock.

the class NotConditionTest method testSingleSubjectEnforcedRetrieval.

@Test
public void testSingleSubjectEnforcedRetrieval() throws Exception {
    //given
    IPv4Condition ip = new IPv4Condition();
    ip.setStartIpAndEndIp("192.168.0.1", "192.168.0.2");
    NotCondition myNotCondition = new NotCondition(ip);
    //when
    myNotCondition.setECondition(ip);
    //then
    assertTrue(myNotCondition.getEConditions().iterator().next().equals(ip));
}
Also used : IPv4Condition(org.forgerock.openam.entitlement.conditions.environment.IPv4Condition) Test(org.testng.annotations.Test)

Aggregations

IPv4Condition (org.forgerock.openam.entitlement.conditions.environment.IPv4Condition)14 HashSet (java.util.HashSet)12 Test (org.testng.annotations.Test)10 HashMap (java.util.HashMap)6 OpenSSOUserSubject (com.sun.identity.entitlement.opensso.OpenSSOUserSubject)4 SSOException (com.iplanet.sso.SSOException)3 IdRepoException (com.sun.identity.idm.IdRepoException)3 SimpleTimeCondition (org.forgerock.openam.entitlement.conditions.environment.SimpleTimeCondition)3 BeforeClass (org.testng.annotations.BeforeClass)3 AndCondition (com.sun.identity.entitlement.AndCondition)2 Entitlement (com.sun.identity.entitlement.Entitlement)2 EntitlementCondition (com.sun.identity.entitlement.EntitlementCondition)2 EntitlementSubject (com.sun.identity.entitlement.EntitlementSubject)2 OrSubject (com.sun.identity.entitlement.OrSubject)2 Privilege (com.sun.identity.entitlement.Privilege)2 ResourceAttribute (com.sun.identity.entitlement.ResourceAttribute)2 StaticAttributes (com.sun.identity.entitlement.StaticAttributes)2 UserAttributes (com.sun.identity.entitlement.UserAttributes)2 UserSubject (com.sun.identity.entitlement.UserSubject)2 SMSException (com.sun.identity.sm.SMSException)2