use of com.sun.identity.policy.plugins.PrivilegeSubject in project OpenAM by OpenRock.
the class PrivilegeUtils method eSubjectToEPSubject.
private static Subject eSubjectToEPSubject(EntitlementSubject es) throws EntitlementException {
if (es instanceof PolicySubject) {
// It already is one captain!
return ((PolicySubject) es).getPolicySubject();
}
PrivilegeSubject ps = new PrivilegeSubject();
Set<String> values = new HashSet<String>();
values.add(es.getClass().getName() + "=" + es.getState());
ps.setValues(values);
return ps;
}
use of com.sun.identity.policy.plugins.PrivilegeSubject 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