Search in sources :

Example 1 with PrivilegeSubject

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

Example 2 with PrivilegeSubject

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");
        }
    }
}
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

PrivilegeSubject (com.sun.identity.policy.plugins.PrivilegeSubject)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 PrivilegeCondition (com.sun.identity.policy.plugins.PrivilegeCondition)1 HashSet (java.util.HashSet)1 Test (org.testng.annotations.Test)1