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