use of org.forgerock.openam.entitlement.conditions.environment.IPv4Condition in project OpenAM by OpenRock.
the class XACMLExportTest method setup.
@BeforeClass
public void setup() throws SSOException, IdRepoException, EntitlementException, SMSException, InstantiationException, IllegalAccessException {
if (!migrated) {
throw new RuntimeException("Server not in entitlement mode");
}
pm = PrivilegeManager.getInstance("/", SubjectUtils.createSubject(adminToken));
Map<String, Boolean> actionValues = new HashMap<String, Boolean>();
actionValues.put("GET", Boolean.TRUE);
actionValues.put("POST", Boolean.FALSE);
Entitlement entitlement = new Entitlement(APPLICATION_NAME, RESOURCE, actionValues);
entitlement.setName("ent1");
String user11 = "id=user11,ou=user," + ServiceManager.getBaseDN();
UserSubject ua1 = new OpenSSOUserSubject();
ua1.setID(user11);
UserSubject ua2 = new OpenSSOUserSubject();
String user12 = "id=user12,ou=user," + ServiceManager.getBaseDN();
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);
/*
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);
*/
privilege1 = Privilege.getNewInstance();
privilege1.setName(PRIVILEGE_NAME);
privilege1.setEntitlement(entitlement);
privilege1.setSubject(ua1);
privilege1.setCondition(ipc);
//privilege.setResourceAttributes(ra);
pm.add(privilege1);
//UnittestLog.logMessage("XACMLExportTest.setup(), added privilege:" +
//"Privilege1=" + privilege1.toString());
}
use of org.forgerock.openam.entitlement.conditions.environment.IPv4Condition in project OpenAM by OpenRock.
the class AndConditionEvalTest 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);
AndCondition cond = new AndCondition();
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);
}
}
use of org.forgerock.openam.entitlement.conditions.environment.IPv4Condition 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()");
}
}
use of org.forgerock.openam.entitlement.conditions.environment.IPv4Condition in project OpenAM by OpenRock.
the class PrivilegeUtilsTest method testPrivilegeToPolicy.
@Test
public void testPrivilegeToPolicy() throws Exception {
String BASE_DN = Constants.DEFAULT_ROOT_SUFFIX;
Map<String, Boolean> actionValues = new HashMap<String, Boolean>();
actionValues.put("GET", Boolean.TRUE);
actionValues.put("POST", Boolean.TRUE);
String resourceName = "http://www.sun.com";
Entitlement entitlement = new Entitlement("iPlanetAMWebAgentService", resourceName, actionValues);
entitlement.setName("ent1");
String user11 = "id=user11,ou=user," + BASE_DN;
String user12 = "id=user12,ou=user," + BASE_DN;
UserSubject us1 = new OpenSSOUserSubject();
us1.setID(user11);
UserSubject us2 = new OpenSSOUserSubject();
us2.setID(user12);
Set<EntitlementSubject> subjects = new HashSet<EntitlementSubject>();
subjects.add(us1);
subjects.add(us2);
OrSubject os = new OrSubject(subjects);
IPv4Condition ipc = new IPv4Condition();
ipc.setStartIpAndEndIp("100.100.100.100", "200.200.200.200");
Set<EntitlementCondition> setConditions = new HashSet<EntitlementCondition>();
setConditions.add(ipc);
AndCondition andCondition = new AndCondition();
andCondition.setEConditions(setConditions);
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("PrivilegeUtilsTest");
privilege.setEntitlement(entitlement);
//orSubject
privilege.setSubject(os);
privilege.setCondition(andCondition);
privilege.setResourceAttributes(ra);
Policy policy = PrivilegeUtils.privilegeToPolicy("/", privilege);
Set<IPrivilege> ps = PrivilegeUtils.policyToPrivileges(policy);
if ((ps == null) || ps.isEmpty()) {
throw new Exception("PrivilegeUtilsTest.testPrivilegeToPolicy failed.");
}
}
Aggregations