Search in sources :

Example 6 with IPv4Condition

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

the class OrConditionEvalTest method setup.

@BeforeClass
public void setup() throws Exception {
    if (migrated) {
        Map<String, Boolean> actions = new HashMap<String, Boolean>();
        actions.put("GET", Boolean.TRUE);
        Entitlement ent = new Entitlement(ApplicationTypeManager.URL_APPLICATION_TYPE_NAME, ROOT_RESOURCE_NAME + "/*", actions);
        OrCondition cond = new OrCondition();
        Set<EntitlementCondition> conditions = new HashSet<EntitlementCondition>();
        IPv4Condition ipc = new IPv4Condition();
        ipc.setStartIpAndEndIp(START_IP, END_IP);
        conditions.add(ipc);
        cond.setEConditions(conditions);
        Privilege privilege = Privilege.getNewInstance();
        privilege.setName(PRIVILEGE_NAME);
        privilege.setEntitlement(ent);
        privilege.setSubject(new AnyUserSubject());
        privilege.setCondition(cond);
        PrivilegeManager pm = PrivilegeManager.getInstance("/", adminSubject);
        pm.add(privilege);
        Thread.sleep(1000);
    }
}
Also used : HashMap(java.util.HashMap) IPv4Condition(org.forgerock.openam.entitlement.conditions.environment.IPv4Condition) HashSet(java.util.HashSet) BeforeClass(org.testng.annotations.BeforeClass)

Example 7 with IPv4Condition

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

the class NotConditionTest method testSingleSubject.

@Test(expectedExceptions = IllegalArgumentException.class)
public void testSingleSubject() throws Exception {
    //given
    Set<EntitlementCondition> conditions = new HashSet<EntitlementCondition>();
    IPv4Condition ip = new IPv4Condition();
    ip.setStartIpAndEndIp("192.168.0.1", "192.168.0.2");
    IPv4Condition ip2 = new IPv4Condition();
    ip2.setStartIpAndEndIp("192.168.0.5", "192.168.0.6");
    conditions.add(ip);
    conditions.add(ip2);
    NotCondition myNotCondition = new NotCondition();
    //when
    myNotCondition.setEConditions(conditions);
//then -- expect error
}
Also used : IPv4Condition(org.forgerock.openam.entitlement.conditions.environment.IPv4Condition) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Example 8 with IPv4Condition

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

the class NotConditionTest method testSingleSubjectEnforced.

@Test
public void testSingleSubjectEnforced() throws Exception {
    //given
    Set<EntitlementCondition> conditions = new HashSet<EntitlementCondition>();
    IPv4Condition ip = new IPv4Condition();
    ip.setStartIpAndEndIp("192.168.0.1", "192.168.0.2");
    conditions.add(ip);
    NotCondition myNotCondition = new NotCondition();
    //when
    myNotCondition.setEConditions(conditions);
    //then
    assertTrue(myNotCondition.getECondition().equals(ip));
}
Also used : IPv4Condition(org.forgerock.openam.entitlement.conditions.environment.IPv4Condition) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Example 9 with IPv4Condition

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

the class OrConditionTest method testConstruction.

@Test
public void testConstruction() throws Exception {
    IPv4Condition ipc = new IPv4Condition();
    ipc.setStartIpAndEndIp("192.168.0.1", "192.168.0.2");
    SimpleTimeCondition tc = new SimpleTimeCondition();
    tc.setStartTime("08:00");
    tc.setEndTime("16:00");
    tc.setStartDay("mon");
    tc.setEndDay("fri");
    tc.setStartDate("01/01/2001");
    tc.setEndDate("02/02/2002");
    tc.setEnforcementTimeZone("PST");
    Set<EntitlementCondition> conditions = new HashSet<EntitlementCondition>();
    conditions.add(ipc);
    conditions.add(tc);
    OrCondition oc = new OrCondition(conditions);
    OrCondition oc1 = new OrCondition();
    oc1.setState(oc.getState());
    if (!oc1.equals(oc)) {
        throw new Exception("OrConditionTest.testConstruction():" + " OrCondition with setState does not equal OrCondition with " + "getState()");
    }
}
Also used : SimpleTimeCondition(org.forgerock.openam.entitlement.conditions.environment.SimpleTimeCondition) IPv4Condition(org.forgerock.openam.entitlement.conditions.environment.IPv4Condition) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Example 10 with IPv4Condition

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

the class PrivilegeUtilsTest method testPrivilegeToXACMLPolicy.

@Test
public void testPrivilegeToXACMLPolicy() throws Exception {
    try {
        UnittestLog.logMessage("PrivilegeUtils.testPrivilegeToXACMLPolicy():" + " entered");
        Map<String, Boolean> actionValues = new HashMap<String, Boolean>();
        actionValues.put("GET", Boolean.TRUE);
        actionValues.put("POST", Boolean.FALSE);
        // The port is required for passing equals  test
        // opensso policy would add default port if port not specified
        String resourceName = "http://www.sun.com:80";
        Entitlement entitlement = new Entitlement(SERVICE_NAME, resourceName, actionValues);
        entitlement.setName("ent1");
        String user11 = "id=user11,ou=user," + ServiceManager.getBaseDN();
        String user12 = "id=user12,ou=user," + ServiceManager.getBaseDN();
        UserSubject ua1 = new OpenSSOUserSubject();
        ua1.setID(user11);
        UserSubject ua2 = new OpenSSOUserSubject();
        ua2.setID(user12);
        Set<EntitlementSubject> subjects = new HashSet<EntitlementSubject>();
        subjects.add(ua1);
        subjects.add(ua2);
        OrSubject os = new OrSubject(subjects);
        Set<EntitlementCondition> conditions = new HashSet<EntitlementCondition>();
        String startIp = "100.100.100.100";
        String endIp = "200.200.200.200";
        IPv4Condition ipc = new IPv4Condition();
        ipc.setStartIpAndEndIp(startIp, endIp);
        conditions.add(ipc);
        OrCondition oc = new OrCondition(conditions);
        AndCondition ac = new AndCondition(conditions);
        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 privilege = Privilege.getNewInstance();
        privilege.setName(PRIVILEGE_NAME);
        privilege.setEntitlement(entitlement);
        privilege.setSubject(ua1);
        privilege.setCondition(ipc);
        privilege.setResourceAttributes(ra);
        privilege.setCreatedBy("amadmin");
        privilege.setLastModifiedBy("amadmin");
        privilege.setCreationDate(System.currentTimeMillis());
        privilege.setLastModifiedDate(System.currentTimeMillis());
        UnittestLog.logMessage("PrivilegeUtils.testPrivilegeToXACMLPolicy():" + "Privilege=" + privilege.toString());
        UnittestLog.logMessage("PrivilegeUtils.testPrivilegeToXACMLPolicy():" + "converting to xacml policy");
        // TODO(jtb): not compiling
        String xacmlString = XACMLPrivilegeUtils.toXACML(privilege);
        UnittestLog.logMessage("xacml policy=" + xacmlString);
    } catch (Throwable t) {
        UnittestLog.logError("Throwable:", t);
        UnittestLog.logMessage("Throwable:" + t.getMessage());
        t.printStackTrace();
    }
}
Also used : EntitlementCondition(com.sun.identity.entitlement.EntitlementCondition) HashMap(java.util.HashMap) IPv4Condition(org.forgerock.openam.entitlement.conditions.environment.IPv4Condition) OpenSSOUserSubject(com.sun.identity.entitlement.opensso.OpenSSOUserSubject) StaticAttributes(com.sun.identity.entitlement.StaticAttributes) OrSubject(com.sun.identity.entitlement.OrSubject) AndCondition(com.sun.identity.entitlement.AndCondition) UserAttributes(com.sun.identity.entitlement.UserAttributes) EntitlementSubject(com.sun.identity.entitlement.EntitlementSubject) OpenSSOUserSubject(com.sun.identity.entitlement.opensso.OpenSSOUserSubject) UserSubject(com.sun.identity.entitlement.UserSubject) OrCondition(com.sun.identity.entitlement.OrCondition) Entitlement(com.sun.identity.entitlement.Entitlement) ResourceAttribute(com.sun.identity.entitlement.ResourceAttribute) Privilege(com.sun.identity.entitlement.Privilege) HashSet(java.util.HashSet) 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