Search in sources :

Example 6 with AdviceExpression

use of com.sun.identity.entitlement.xacml3.core.AdviceExpression in project OpenAM by OpenRock.

the class XACMLSchemaFactory method adviceExpressionToResourceAttribute.

/**
     * Convert the specified {@link com.sun.identity.entitlement.xacml3.core.AdviceExpression} object into a
     * {@link com.sun.identity.entitlement.ResourceAttribute}.
     *
     * @param adviceExpression The specified advice expression
     * @return The resource attribute
     * @throws com.sun.identity.entitlement.EntitlementException if JSON exceptions occur
     */
public ResourceAttribute adviceExpressionToResourceAttribute(AdviceExpression adviceExpression) throws EntitlementException {
    for (AttributeAssignmentExpression attributeAssignmentExpression : adviceExpression.getAttributeAssignmentExpression()) {
        JAXBElement<?> jaxbElement = attributeAssignmentExpression.getExpression();
        Object value = jaxbElement.getValue();
        if (value instanceof AttributeValue) {
            AttributeValue attributeValue = (AttributeValue) value;
            for (Object content : attributeValue.getContent()) {
                if (content instanceof String) {
                    return resourceAttributeUtil.fromJSON((String) content);
                }
            }
        }
    }
    return null;
}
Also used : AttributeValue(com.sun.identity.entitlement.xacml3.core.AttributeValue) AttributeAssignmentExpression(com.sun.identity.entitlement.xacml3.core.AttributeAssignmentExpression)

Example 7 with AdviceExpression

use of com.sun.identity.entitlement.xacml3.core.AdviceExpression in project OpenAM by OpenRock.

the class XACMLSchemaFactory method resourceAttributeToAdviceExpression.

/**
     * Convert one {@link com.sun.identity.entitlement.ResourceAttribute} object into an
     * {@link com.sun.identity.entitlement.xacml3.core.AdviceExpression} object.
     *
     * @param resourceAttribute The resource attribute
     * @return the advice expression
     * @throws com.sun.identity.entitlement.EntitlementException on JSON conversion errors
     */
public AdviceExpression resourceAttributeToAdviceExpression(ResourceAttribute resourceAttribute) throws EntitlementException {
    // A pseudo-urn to use for advice/attribute id
    final String adviceId = XACMLConstants.JSON_RESOURCE_ATTRIBUTE_ADVICE_ID + ":" + resourceAttribute.getClass().getName();
    AdviceExpression result = new AdviceExpression();
    AttributeValue attributeValue = factory.createAttributeValue();
    attributeValue.setDataType(XACMLConstants.XS_STRING);
    // We bypass much of the grief of conversion by getting JSON to do the heavy lifting for us.
    attributeValue.getContent().add(resourceAttributeUtil.toJSON(resourceAttribute));
    JAXBElement<AttributeValue> jaxbElement = factory.createAttributeValue(attributeValue);
    AttributeAssignmentExpression attributeAssignmentExpression = factory.createAttributeAssignmentExpression();
    attributeAssignmentExpression.setExpression(jaxbElement);
    attributeAssignmentExpression.setAttributeId(adviceId + ":" + resourceAttribute.getPropertyName());
    result.getAttributeAssignmentExpression().add(attributeAssignmentExpression);
    // Resource Attributes are returned on successful policy decisions
    result.setAppliesTo(EffectType.PERMIT);
    // Set an AdviceId to be in strict compliance with the schema
    result.setAdviceId(adviceId);
    return result;
}
Also used : AdviceExpression(com.sun.identity.entitlement.xacml3.core.AdviceExpression) AttributeValue(com.sun.identity.entitlement.xacml3.core.AttributeValue) AttributeAssignmentExpression(com.sun.identity.entitlement.xacml3.core.AttributeAssignmentExpression)

Example 8 with AdviceExpression

use of com.sun.identity.entitlement.xacml3.core.AdviceExpression in project OpenAM by OpenRock.

the class XACMLSchemaFactory method resourceAttributesToAdviceExpressions.

/**
     * Convert a set of {@link com.sun.identity.entitlement.ResourceAttribute} objects to a single
     * {@link com.sun.identity.entitlement.xacml3.core.AdviceExpression} object.
     * @param resourceAttributes The set of ResourceAttribute objects.
     * @return The AdviceExpression object.
     */
public AdviceExpressions resourceAttributesToAdviceExpressions(Set<ResourceAttribute> resourceAttributes) throws EntitlementException {
    AdviceExpressions result = new AdviceExpressions();
    if (resourceAttributes != null && !resourceAttributes.isEmpty()) {
        List<AdviceExpression> adviceExpressionList = result.getAdviceExpression();
        for (ResourceAttribute resourceAttribute : resourceAttributes) {
            AdviceExpression adviceExpression = resourceAttributeToAdviceExpression(resourceAttribute);
            adviceExpressionList.add(adviceExpression);
        }
    }
    return result;
}
Also used : AdviceExpression(com.sun.identity.entitlement.xacml3.core.AdviceExpression) AdviceExpressions(com.sun.identity.entitlement.xacml3.core.AdviceExpressions) ResourceAttribute(com.sun.identity.entitlement.ResourceAttribute)

Example 9 with AdviceExpression

use of com.sun.identity.entitlement.xacml3.core.AdviceExpression in project OpenAM by OpenRock.

the class XACMLSchemaFactoryTest method checkEqualAdviceExpressionValues.

/**
     * Check that two advice expression objects contain the same values, return true if so, false otherwise.
     * @param ae1 the first advice expression object
     * @param ae2 the second advice expression object
     * @return true if the advice expression objects contain the same values, false otherwise.
     */
private boolean checkEqualAdviceExpressionValues(final AdviceExpression ae1, final AdviceExpression ae2) {
    if (ae1 == ae2) {
        return true;
    }
    if (ae1 == null || ae2 == null) {
        return false;
    }
    if (!compareStrings(ae1.getAdviceId(), ae2.getAdviceId())) {
        return false;
    }
    EffectType effectType1 = ae1.getAppliesTo();
    EffectType effectType2 = ae2.getAppliesTo();
    if (effectType1 == null && effectType2 != null || effectType1 != null && effectType2 == null) {
        return false;
    }
    if (effectType1 != null && effectType2 != null && !effectType1.equals(effectType2)) {
        return false;
    }
    return (compareListsOfAttributeAssignmentExpression(ae1.getAttributeAssignmentExpression(), ae2.getAttributeAssignmentExpression()));
}
Also used : EffectType(com.sun.identity.entitlement.xacml3.core.EffectType)

Example 10 with AdviceExpression

use of com.sun.identity.entitlement.xacml3.core.AdviceExpression in project OpenAM by OpenRock.

the class XACMLSchemaFactoryTest method assertEqualAdviceExpressions.

/**
     * Assert that two advice expressions objects contain the same values, i.e. that the advice expression objects
     * they contain, contain the same values.
     * @param aes1 the first advice expressions object
     * @param aes2 the second advice expressions object
     */
private void assertEqualAdviceExpressions(final AdviceExpressions aes1, final AdviceExpressions aes2) {
    assertThat(aes1.getAdviceExpression().size()).isEqualTo(aes2.getAdviceExpression().size());
    for (AdviceExpression ae : aes1.getAdviceExpression()) {
        boolean found = false;
        for (AdviceExpression other : aes2.getAdviceExpression()) {
            if (checkEqualAdviceExpressionValues(ae, other)) {
                found = true;
                break;
            }
        }
        assertThat(found).isTrue();
    }
}
Also used : AdviceExpression(com.sun.identity.entitlement.xacml3.core.AdviceExpression)

Aggregations

AdviceExpression (com.sun.identity.entitlement.xacml3.core.AdviceExpression)8 ResourceAttribute (com.sun.identity.entitlement.ResourceAttribute)3 AttributeAssignmentExpression (com.sun.identity.entitlement.xacml3.core.AttributeAssignmentExpression)3 AttributeValue (com.sun.identity.entitlement.xacml3.core.AttributeValue)3 Test (org.testng.annotations.Test)3 AdviceExpressions (com.sun.identity.entitlement.xacml3.core.AdviceExpressions)2 StaticAttributes (com.sun.identity.entitlement.StaticAttributes)1 PolicyResponseProvider (com.sun.identity.entitlement.opensso.PolicyResponseProvider)1 EffectType (com.sun.identity.entitlement.xacml3.core.EffectType)1 JAXBElement (javax.xml.bind.JAXBElement)1 BeforeMethod (org.testng.annotations.BeforeMethod)1