use of com.sun.identity.entitlement.EntitlementCondition in project OpenAM by OpenRock.
the class FactoryMethods method createArbitraryPrivilege.
public static Privilege createArbitraryPrivilege(String name, long now) throws EntitlementException {
Privilege privilege = Privilege.getNewInstance();
privilege.setName(name);
privilege.setDescription("Privilege " + name);
privilege.setCreatedBy("creatingAuthor");
privilege.setLastModifiedBy("modifyingAuthor");
privilege.setCreationDate(now);
privilege.setLastModifiedDate(now);
privilege.setActive(true);
privilege.setApplicationIndexes(asSet("arbitraryApplicationIndex"));
EntitlementCondition entitlementCondition = new SessionCondition();
entitlementCondition.setState("{ 'maxSessionTime': 10, 'terminateSession': true }");
privilege.setCondition(entitlementCondition);
// TODO: Define entitlement Subject
Set<ResourceAttribute> resourceAttributes = new HashSet<ResourceAttribute>();
// TODO: Define some ResourceAttributes
privilege.setResourceAttributes(resourceAttributes);
Entitlement entitlement = new Entitlement();
entitlement.setName("arbitraryEntitlementName");
entitlement.setResourceName("http://www.artibrary.com/resource");
Map<String, Boolean> actionValues = new HashMap<String, Boolean>();
actionValues.put("arbitraryAction", true);
entitlement.setActionValues(actionValues);
privilege.setEntitlement(entitlement);
return privilege;
}
use of com.sun.identity.entitlement.EntitlementCondition in project OpenAM by OpenRock.
the class JsonPolicyParserTest method shouldPrintComplexConditions.
@Test
public void shouldPrintComplexConditions() throws Exception {
// Given
Privilege policy = new StubPrivilege();
AndCondition and = new AndCondition();
Set<EntitlementCondition> subConditions = new LinkedHashSet<EntitlementCondition>();
Map<String, Set<String>> props = new HashMap<String, Set<String>>();
props.put("AuthenticateToRealm", Collections.singleton("REALM"));
PolicyCondition policyCondition = new PolicyCondition("test", AuthenticateToRealmCondition.class.getName(), props);
NotCondition not = new NotCondition(policyCondition);
subConditions.add(not);
and.setEConditions(subConditions);
policy.setCondition(and);
// When
JsonValue result = parser.printPolicy(policy);
// Then
assertThat(result.get(new JsonPointer("condition/type")).asString()).isEqualTo("AND");
assertThat(result.get(new JsonPointer("condition/conditions/0/type")).asString()).isEqualTo("NOT");
assertThat(result.get(new JsonPointer("condition/conditions/0/condition/type")).asString()).isEqualTo("Policy");
assertThat(result.get(new JsonPointer("condition/conditions/0/condition/className")).asString()).isEqualTo(AuthenticateToRealmCondition.class.getName());
assertThat(result.get(new JsonPointer("condition/conditions/0/condition/properties")).asMapOfList(String.class)).includes(entry("AuthenticateToRealm", Arrays.asList("REALM")));
}
use of com.sun.identity.entitlement.EntitlementCondition 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.");
}
}
use of com.sun.identity.entitlement.EntitlementCondition in project OpenAM by OpenRock.
the class PolicyConditionUpgrader method isEnvironmentConditionUpgradable.
private boolean isEnvironmentConditionUpgradable(EntitlementCondition condition) {
if (condition == null) {
return true;
}
if (condition instanceof LogicalCondition) {
LogicalCondition logicalCondition = (LogicalCondition) condition;
boolean upgradable = true;
for (EntitlementCondition c : logicalCondition.getEConditions()) {
upgradable &= isUpgradablePolicyCondition(c);
}
return upgradable;
}
return isUpgradablePolicyCondition(condition);
}
use of com.sun.identity.entitlement.EntitlementCondition in project OpenAM by OpenRock.
the class PolicyConditionUpgrader method migrateEnvironmentCondition.
private EntitlementCondition migrateEnvironmentCondition(PolicyCondition condition, MigrationReport migrationReport) throws EntitlementException {
final EntitlementCondition migrated = conditionUpgradeMap.migrateEnvironmentCondition(condition.getClassName(), condition, migrationReport);
migrated.validate();
return migrated;
}
Aggregations