Search in sources :

Example 6 with ResourceAttribute

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

the class XACMLSchemaFactoryTest method checkEqualAttributeValues.

/**
     * Compare two AttributeValue objects, returning true if they contain equal values, false otherwise.
     * @param first The first attribute value.
     * @param second The second attribute value.
     * @return true if the objects contain the same values, false otherwise.
     */
private boolean checkEqualAttributeValues(AttributeValue first, AttributeValue second) {
    if (first == null && second == null) {
        return true;
    }
    if (first == null || second == null) {
        return false;
    }
    List<Object> firstList = first.getContent();
    List<Object> secondList = second.getContent();
    if (firstList == null && secondList == null) {
        return true;
    }
    if (firstList == null || secondList == null) {
        return false;
    }
    if (firstList.size() != secondList.size()) {
        return false;
    }
    for (Object firstObject : firstList) {
        boolean found = false;
        for (Object secondObject : secondList) {
            if (firstObject instanceof String && secondObject instanceof String) {
                String firstString = (String) firstObject;
                String secondString = (String) secondObject;
                try {
                    ResourceAttribute firstRA = resourceAttributeUtil.fromJSON(firstString);
                    ResourceAttribute secondRA = resourceAttributeUtil.fromJSON(secondString);
                    found = checkEqualResourceAttributes(firstRA, secondRA);
                    if (found) {
                        break;
                    }
                } catch (EntitlementException ignored) {
                }
            }
        }
        if (!found) {
            return false;
        }
    }
    return true;
}
Also used : EntitlementException(com.sun.identity.entitlement.EntitlementException) ResourceAttribute(com.sun.identity.entitlement.ResourceAttribute)

Example 7 with ResourceAttribute

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

the class XACMLSchemaFactoryTest method shouldConvertResourceAttributesToAndFrom.

@Test
public void shouldConvertResourceAttributesToAndFrom() throws EntitlementException {
    for (ResourceAttribute ra : rpSet) {
        // When...
        AdviceExpression ae = xacmlSchemaFactory.resourceAttributeToAdviceExpression(ra);
        ResourceAttribute transformed = xacmlSchemaFactory.adviceExpressionToResourceAttribute(ae);
        // Then...
        assertEqualResourceAttributeValues(ra, transformed);
    }
}
Also used : AdviceExpression(com.sun.identity.entitlement.xacml3.core.AdviceExpression) ResourceAttribute(com.sun.identity.entitlement.ResourceAttribute) Test(org.testng.annotations.Test)

Example 8 with ResourceAttribute

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

the class ResourceAttributeUtilTest method shouldDeserialiseMockResourceAttribute.

@Test
public void shouldDeserialiseMockResourceAttribute() throws EntitlementException {
    // Given
    util = new ResourceAttributeUtil();
    ResourceAttribute attribute = new MockResourceAttribute();
    // When
    ResourceAttribute result = util.fromJSON(util.toJSON(attribute));
    // Then
    assertThat(result.getPropertyName()).isEqualTo(attribute.getPropertyName());
}
Also used : ResourceAttribute(com.sun.identity.entitlement.ResourceAttribute) Test(org.testng.annotations.Test)

Example 9 with ResourceAttribute

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

the class XACMLSchemaFactoryTest method shouldConvertAdviceExpressionToAndFrom.

@Test
public void shouldConvertAdviceExpressionToAndFrom() throws EntitlementException {
    for (AdviceExpression ae : aes.getAdviceExpression()) {
        // When...
        ResourceAttribute ra = xacmlSchemaFactory.adviceExpressionToResourceAttribute(ae);
        AdviceExpression transformed = xacmlSchemaFactory.resourceAttributeToAdviceExpression(ra);
        // Then...
        assertEqualAdviceExpressionValues(ae, transformed);
    }
}
Also used : AdviceExpression(com.sun.identity.entitlement.xacml3.core.AdviceExpression) ResourceAttribute(com.sun.identity.entitlement.ResourceAttribute) Test(org.testng.annotations.Test)

Example 10 with ResourceAttribute

use of com.sun.identity.entitlement.ResourceAttribute 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)

Aggregations

ResourceAttribute (com.sun.identity.entitlement.ResourceAttribute)20 Test (org.testng.annotations.Test)11 HashSet (java.util.HashSet)8 StaticAttributes (com.sun.identity.entitlement.StaticAttributes)7 Entitlement (com.sun.identity.entitlement.Entitlement)6 EntitlementCondition (com.sun.identity.entitlement.EntitlementCondition)6 Privilege (com.sun.identity.entitlement.Privilege)6 EntitlementSubject (com.sun.identity.entitlement.EntitlementSubject)5 UserAttributes (com.sun.identity.entitlement.UserAttributes)5 HashMap (java.util.HashMap)5 ReferralPrivilege (com.sun.identity.entitlement.ReferralPrivilege)3 AdviceExpression (com.sun.identity.entitlement.xacml3.core.AdviceExpression)3 AdviceExpressions (com.sun.identity.entitlement.xacml3.core.AdviceExpressions)3 Set (java.util.Set)3 AndCondition (com.sun.identity.entitlement.AndCondition)2 OrSubject (com.sun.identity.entitlement.OrSubject)2 UserSubject (com.sun.identity.entitlement.UserSubject)2 OpenSSOPrivilege (com.sun.identity.entitlement.opensso.OpenSSOPrivilege)2 OpenSSOUserSubject (com.sun.identity.entitlement.opensso.OpenSSOUserSubject)2 ResponseProvider (com.sun.identity.policy.interfaces.ResponseProvider)2