use of org.forgerock.openam.entitlement.conditions.environment.SimpleTimeCondition 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.SimpleTimeCondition in project OpenAM by OpenRock.
the class OpenSSOApplicationPrivilegeManager method toApplicationPrivilege.
private ApplicationPrivilege toApplicationPrivilege(Privilege p) throws EntitlementException {
ApplicationPrivilege ap = new ApplicationPrivilege(p.getName());
ap.setDescription(p.getDescription());
ap.setCreatedBy(p.getCreatedBy());
ap.setCreationDate(p.getCreationDate());
ap.setLastModifiedBy(p.getLastModifiedBy());
ap.setLastModifiedDate(p.getLastModifiedDate());
Entitlement ent = p.getEntitlement();
Set<String> resourceNames = ent.getResourceNames();
Map<String, Set<String>> mapAppToRes = getApplicationPrivilegeResourceNames(resourceNames);
ap.setApplicationResources(mapAppToRes);
ap.setActionValues(getActionValues(ent.getActionValues()));
Set<SubjectImplementation> subjects = new HashSet<SubjectImplementation>();
if (p.getSubject() instanceof OrSubject) {
OrSubject orSubject = (OrSubject) p.getSubject();
for (EntitlementSubject es : orSubject.getESubjects()) {
if (es instanceof SubjectImplementation) {
subjects.add((SubjectImplementation) es);
}
}
} else if (p.getSubject() instanceof SubjectImplementation) {
subjects.add((SubjectImplementation) p.getSubject());
}
ap.setSubject(subjects);
EntitlementCondition cond = p.getCondition();
if (cond instanceof SimpleTimeCondition) {
ap.setCondition(cond);
}
return ap;
}
use of org.forgerock.openam.entitlement.conditions.environment.SimpleTimeCondition 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()");
}
}
use of org.forgerock.openam.entitlement.conditions.environment.SimpleTimeCondition in project OpenAM by OpenRock.
the class AndConditionTest method testConstruction.
@Test
public void testConstruction() throws Exception {
IPv4Condition ipc = new IPv4Condition();
ipc.setStartIpAndEndIp("100.100.100.100", "200.200.200.200");
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);
AndCondition ac = new AndCondition(conditions);
AndCondition ac1 = new AndCondition();
ac1.setState(ac.getState());
if (!ac1.equals(ac1)) {
throw new Exception("AndConditionTest.testConstruction():" + "AndCondition with setState=" + "does not equal AndCondition with getState()");
}
}
Aggregations