Search in sources :

Example 1 with PrivilegeCondition

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;
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) HashMap(java.util.HashMap) PrivilegeCondition(com.sun.identity.policy.plugins.PrivilegeCondition) HashSet(java.util.HashSet)

Example 2 with PrivilegeCondition

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");
        }
    }
}
Also used : Policy(com.sun.identity.policy.Policy) PrivilegeSubject(com.sun.identity.policy.plugins.PrivilegeSubject) OrCondition(com.sun.identity.entitlement.OrCondition) PrivilegeCondition(com.sun.identity.policy.plugins.PrivilegeCondition) Condition(com.sun.identity.policy.interfaces.Condition) EntitlementCondition(com.sun.identity.entitlement.EntitlementCondition) PrivilegeCondition(com.sun.identity.policy.plugins.PrivilegeCondition) Rule(com.sun.identity.policy.Rule) PolicyException(com.sun.identity.policy.PolicyException) EntitlementSubject(com.sun.identity.entitlement.EntitlementSubject) PrivilegeSubject(com.sun.identity.policy.plugins.PrivilegeSubject) Subject(com.sun.identity.policy.interfaces.Subject) Test(org.testng.annotations.Test)

Aggregations

PrivilegeCondition (com.sun.identity.policy.plugins.PrivilegeCondition)2 EntitlementCondition (com.sun.identity.entitlement.EntitlementCondition)1 EntitlementSubject (com.sun.identity.entitlement.EntitlementSubject)1 OrCondition (com.sun.identity.entitlement.OrCondition)1 Policy (com.sun.identity.policy.Policy)1 PolicyException (com.sun.identity.policy.PolicyException)1 Rule (com.sun.identity.policy.Rule)1 Condition (com.sun.identity.policy.interfaces.Condition)1 Subject (com.sun.identity.policy.interfaces.Subject)1 PrivilegeSubject (com.sun.identity.policy.plugins.PrivilegeSubject)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1 Test (org.testng.annotations.Test)1