Search in sources :

Example 11 with EntitlementCondition

use of com.sun.identity.entitlement.EntitlementCondition in project OpenAM by OpenRock.

the class EntitlementRegistryTest method shouldNotReturnSuperTypeConditionNames.

@Test
public void shouldNotReturnSuperTypeConditionNames() {
    // Given
    EntitlementCondition testCondition = new NumericAttributeCondition();
    // Only super-type registered
    testRegistry.registerConditionType(EntitlementCondition.class);
    // When
    String result = testRegistry.getConditionName(testCondition);
    // Then
    assertThat(result).isNull();
}
Also used : EntitlementCondition(com.sun.identity.entitlement.EntitlementCondition) NumericAttributeCondition(com.sun.identity.entitlement.NumericAttributeCondition) Test(org.testng.annotations.Test)

Example 12 with EntitlementCondition

use of com.sun.identity.entitlement.EntitlementCondition in project OpenAM by OpenRock.

the class PrivilegeUtils method mapGenericCondition.

private static EntitlementCondition mapGenericCondition(Object[] nCondition) throws EntitlementException {
    try {
        Object objCondition = nCondition[1];
        if (objCondition instanceof com.sun.identity.policy.plugins.PrivilegeCondition) {
            com.sun.identity.policy.plugins.PrivilegeCondition pipc = (com.sun.identity.policy.plugins.PrivilegeCondition) objCondition;
            Map<String, Set<String>> props = pipc.getProperties();
            String className = props.keySet().iterator().next();
            EntitlementCondition ec = (EntitlementCondition) Class.forName(className).newInstance();
            Set<String> setValues = props.get(className);
            ec.setState(setValues.iterator().next());
            ec.validate();
            return ec;
        } else if (objCondition instanceof Condition) {
            Condition cond = (Condition) objCondition;
            Map<String, Set<String>> props = cond.getProperties();
            String className = cond.getClass().getName();
            return new PolicyCondition((String) nCondition[0], className, props);
        }
    } catch (ClassNotFoundException e) {
        PolicyConstants.DEBUG.error("PrivilegeUtils.mapGenericCondition", e);
    } catch (InstantiationException e) {
        PolicyConstants.DEBUG.error("PrivilegeUtils.mapGenericCondition", e);
    } catch (IllegalAccessException e) {
        PolicyConstants.DEBUG.error("PrivilegeUtils.mapGenericCondition", e);
    }
    return null;
}
Also used : OrCondition(com.sun.identity.entitlement.OrCondition) AndCondition(com.sun.identity.entitlement.AndCondition) PrivilegeCondition(com.sun.identity.policy.plugins.PrivilegeCondition) Condition(com.sun.identity.policy.interfaces.Condition) EntitlementCondition(com.sun.identity.entitlement.EntitlementCondition) EntitlementCondition(com.sun.identity.entitlement.EntitlementCondition) HashSet(java.util.HashSet) Set(java.util.Set) PrivilegeCondition(com.sun.identity.policy.plugins.PrivilegeCondition) PrivilegeCondition(com.sun.identity.policy.plugins.PrivilegeCondition) HashMap(java.util.HashMap) Map(java.util.Map)

Example 13 with EntitlementCondition

use of com.sun.identity.entitlement.EntitlementCondition in project OpenAM by OpenRock.

the class PrivilegeUtils method policyToPrivileges.

public static void policyToPrivileges(Policy policy, Set<IPrivilege> privileges) throws SSOException, PolicyException, EntitlementException {
    String policyName = policy.getName();
    if (policy.isReferralPolicy()) {
        Map<String, Set<String>> resources = getResources(policy);
        Set<String> referredRealms = getReferrals(policy);
        ReferralPrivilege rp = new ReferralPrivilege(policyName, resources, referredRealms);
        rp.setDescription(policy.getDescription());
        rp.setCreationDate(policy.getCreationDate());
        rp.setCreatedBy(policy.getCreatedBy());
        rp.setLastModifiedBy(policy.getLastModifiedBy());
        rp.setLastModifiedDate(policy.getLastModifiedDate());
        rp.setActive(policy.isActive());
        privileges.add(rp);
    } else {
        Set<Entitlement> entitlements = rulesToEntitlement(policy);
        EntitlementSubject eSubject = toEntitlementSubject(policy);
        EntitlementCondition eCondition = toEntitlementCondition(policy);
        Set<ResourceAttribute> resourceAttributesSet = toResourceAttributes(policy);
        if (entitlements.size() == 1) {
            privileges.add(createPrivilege(policyName, policyName, entitlements.iterator().next(), eSubject, eCondition, resourceAttributesSet, policy));
        } else {
            for (Entitlement e : entitlements) {
                String pName = policyName + "_" + e.getName();
                privileges.add(createPrivilege(pName, policyName, e, eSubject, eCondition, resourceAttributesSet, policy));
            }
        }
    }
}
Also used : EntitlementSubject(com.sun.identity.entitlement.EntitlementSubject) EntitlementCondition(com.sun.identity.entitlement.EntitlementCondition) HashSet(java.util.HashSet) Set(java.util.Set) ReferralPrivilege(com.sun.identity.entitlement.ReferralPrivilege) Entitlement(com.sun.identity.entitlement.Entitlement) ResourceAttribute(com.sun.identity.entitlement.ResourceAttribute)

Example 14 with EntitlementCondition

use of com.sun.identity.entitlement.EntitlementCondition in project OpenAM by OpenRock.

the class PrivilegeUtils method toEntitlementCondition.

private static EntitlementCondition toEntitlementCondition(Policy policy) throws PolicyException, EntitlementException {
    Set conditionNames = policy.getConditionNames();
    Set nConditions = new HashSet();
    for (Object conditionNameObj : conditionNames) {
        String conditionName = (String) conditionNameObj;
        Condition condition = policy.getCondition(conditionName);
        Object[] nCondition = new Object[2];
        nCondition[0] = conditionName;
        nCondition[1] = condition;
        nConditions.add(nCondition);
    }
    return nConditionsToECondition(nConditions);
}
Also used : OrCondition(com.sun.identity.entitlement.OrCondition) AndCondition(com.sun.identity.entitlement.AndCondition) PrivilegeCondition(com.sun.identity.policy.plugins.PrivilegeCondition) Condition(com.sun.identity.policy.interfaces.Condition) EntitlementCondition(com.sun.identity.entitlement.EntitlementCondition) HashSet(java.util.HashSet) Set(java.util.Set) HashSet(java.util.HashSet)

Example 15 with EntitlementCondition

use of com.sun.identity.entitlement.EntitlementCondition in project OpenAM by OpenRock.

the class OpenSSOApplicationPrivilegeManager method toApplicationPrivilege.

private ApplicationPrivilege toApplicationPrivilege(Privilege p) throws EntitlementException {
    ApplicationPrivilege ap = new ApplicationPrivilege(p.getName());
    ap.setDescription(p.getDescription());
    ap.setCreatedBy(p.getCreatedBy());
    ap.setCreationDate(p.getCreationDate());
    ap.setLastModifiedBy(p.getLastModifiedBy());
    ap.setLastModifiedDate(p.getLastModifiedDate());
    Entitlement ent = p.getEntitlement();
    Set<String> resourceNames = ent.getResourceNames();
    Map<String, Set<String>> mapAppToRes = getApplicationPrivilegeResourceNames(resourceNames);
    ap.setApplicationResources(mapAppToRes);
    ap.setActionValues(getActionValues(ent.getActionValues()));
    Set<SubjectImplementation> subjects = new HashSet<SubjectImplementation>();
    if (p.getSubject() instanceof OrSubject) {
        OrSubject orSubject = (OrSubject) p.getSubject();
        for (EntitlementSubject es : orSubject.getESubjects()) {
            if (es instanceof SubjectImplementation) {
                subjects.add((SubjectImplementation) es);
            }
        }
    } else if (p.getSubject() instanceof SubjectImplementation) {
        subjects.add((SubjectImplementation) p.getSubject());
    }
    ap.setSubject(subjects);
    EntitlementCondition cond = p.getCondition();
    if (cond instanceof SimpleTimeCondition) {
        ap.setCondition(cond);
    }
    return ap;
}
Also used : EntitlementCondition(com.sun.identity.entitlement.EntitlementCondition) HashSet(java.util.HashSet) Set(java.util.Set) SimpleTimeCondition(org.forgerock.openam.entitlement.conditions.environment.SimpleTimeCondition) OrSubject(com.sun.identity.entitlement.OrSubject) EntitlementSubject(com.sun.identity.entitlement.EntitlementSubject) ApplicationPrivilege(com.sun.identity.entitlement.ApplicationPrivilege) SubjectImplementation(com.sun.identity.entitlement.SubjectImplementation) Entitlement(com.sun.identity.entitlement.Entitlement) HashSet(java.util.HashSet)

Aggregations

EntitlementCondition (com.sun.identity.entitlement.EntitlementCondition)28 HashSet (java.util.HashSet)17 Test (org.testng.annotations.Test)14 Privilege (com.sun.identity.entitlement.Privilege)13 PolicyCondition (com.sun.identity.entitlement.opensso.PolicyCondition)10 Set (java.util.Set)10 AndCondition (com.sun.identity.entitlement.AndCondition)9 EntitlementSubject (com.sun.identity.entitlement.EntitlementSubject)9 OrCondition (com.sun.identity.entitlement.OrCondition)8 Entitlement (com.sun.identity.entitlement.Entitlement)7 HashMap (java.util.HashMap)6 ResourceAttribute (com.sun.identity.entitlement.ResourceAttribute)5 OrSubject (com.sun.identity.entitlement.OrSubject)4 NotCondition (com.sun.identity.entitlement.NotCondition)3 ReferralPrivilege (com.sun.identity.entitlement.ReferralPrivilege)3 Condition (com.sun.identity.policy.interfaces.Condition)3 PrivilegeCondition (com.sun.identity.policy.plugins.PrivilegeCondition)3 IPrivilege (com.sun.identity.entitlement.IPrivilege)2 LogicalCondition (com.sun.identity.entitlement.LogicalCondition)2 NumericAttributeCondition (com.sun.identity.entitlement.NumericAttributeCondition)2