use of com.sun.identity.policy.plugins.PrivilegeCondition in project OpenAM by OpenRock.
the class PrivilegeUtils method eConditionToEPCondition.
private static Condition eConditionToEPCondition(EntitlementCondition ec) throws PolicyException, EntitlementException {
if (ec instanceof PolicyCondition) {
return ((PolicyCondition) ec).getPolicyCondition();
}
PrivilegeCondition pc = new PrivilegeCondition();
Map<String, Set<String>> map = new HashMap<String, Set<String>>();
Set<String> set = new HashSet<String>(2);
set.add(ec.getState());
map.put(ec.getClass().getName(), set);
pc.setProperties(map);
return pc;
}
use of com.sun.identity.policy.plugins.PrivilegeCondition in project OpenAM by OpenRock.
the class PrivilegePolicyMapping method privilegeToPolicy.
@Test(dependsOnMethods = { "policyToPrivilege" })
public void privilegeToPolicy() throws Exception {
Policy p = PrivilegeUtils.privilegeToPolicy("/", privilege);
Set<String> ruleNames = p.getRuleNames();
for (String ruleName : ruleNames) {
Rule r = p.getRule(ruleName);
if (!RES_NAME.equals(r.getResourceName())) {
throw new Exception("PrivilegePolicyMapping.privilegeToPolicy: resource is incorrect");
}
if (!actionValues.equals(r.getActionValues())) {
throw new Exception("PrivilegePolicyMapping.privilegeToPolicy: action value is incorrect");
}
}
Set<String> subjectNames = p.getSubjectNames();
for (String subjectName : subjectNames) {
Subject sbj = p.getSubject(subjectName);
if (!(sbj instanceof PrivilegeSubject)) {
throw new Exception("PrivilegePolicyMapping.privilegeToPolicy: not instance of privilege subject");
}
}
Set<String> conditionNames = p.getConditionNames();
if (conditionNames.size() != 1) {
throw new Exception("PrivilegePolicyMapping.privilegeToPolicy: number of condition is incorrect");
}
for (String conditionName : conditionNames) {
Condition cond = p.getCondition(conditionName);
if (!(cond instanceof PrivilegeCondition)) {
throw new Exception("PrivilegePolicyMapping.privilegeToPolicy: not instance of privilege condition");
}
}
}
Aggregations