Search in sources :

Example 1 with AttributeAssignmentExpression

use of com.sun.identity.entitlement.xacml3.core.AttributeAssignmentExpression 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 2 with AttributeAssignmentExpression

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

the class XACMLSchemaFactoryTest method createAdviceExpression.

/**
     * Create an advice expression using the values in the specified resource attribute
     * @param ra the specified resource attribute
     * @return an advice expression
     * @throws EntitlementException if there are JSON errors
     */
private AdviceExpression createAdviceExpression(final ResourceAttribute ra) throws EntitlementException {
    AdviceExpression result = new AdviceExpression();
    AttributeValue attributeValue = new AttributeValue();
    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(ra));
    JAXBElement<AttributeValue> jaxbElement = new JAXBElement<AttributeValue>(QName.valueOf(AttributeValue.class.getSimpleName()), AttributeValue.class, null, attributeValue);
    AttributeAssignmentExpression attributeAssignmentExpression = new AttributeAssignmentExpression();
    attributeAssignmentExpression.setExpression(jaxbElement);
    attributeAssignmentExpression.setAttributeId(XACMLConstants.JSON_RESOURCE_ATTRIBUTE_ADVICE_ID + ":" + ra.getClass().getName() + ":" + ra.getPropertyName());
    result.getAttributeAssignmentExpression().add(attributeAssignmentExpression);
    result.setAppliesTo(EffectType.PERMIT);
    result.setAdviceId(XACMLConstants.JSON_RESOURCE_ATTRIBUTE_ADVICE_ID + ":" + ra.getClass().getName());
    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) JAXBElement(javax.xml.bind.JAXBElement)

Example 3 with AttributeAssignmentExpression

use of com.sun.identity.entitlement.xacml3.core.AttributeAssignmentExpression 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 4 with AttributeAssignmentExpression

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

the class XACMLSchemaFactoryTest method checkEqualAttributeAssignmentExpressions.

/**
     * @param first First attribute assignment expression to check
     * @param second Second attribute assignment expression to check
     * @return true if both attribute assignment expressions contain the same values, false otherwise
     */
private boolean checkEqualAttributeAssignmentExpressions(AttributeAssignmentExpression first, AttributeAssignmentExpression second) {
    if (first == null && second == null) {
        return true;
    }
    if (first == null || second == null) {
        return false;
    }
    JAXBElement<?> firstJaxbElement = first.getExpression();
    JAXBElement<?> secondJaxbElement = second.getExpression();
    Object firstObject = firstJaxbElement.getValue();
    Object secondObject = secondJaxbElement.getValue();
    if (firstObject == null && secondObject == null) {
        return true;
    }
    if (firstObject == null || secondObject == null) {
        return false;
    }
    if (!(firstObject instanceof AttributeValue) || !(secondObject instanceof AttributeValue)) {
        return false;
    }
    AttributeValue firstAttributeValue = (AttributeValue) firstObject;
    AttributeValue secondAttributeValue = (AttributeValue) secondObject;
    return checkEqualAttributeValues(firstAttributeValue, secondAttributeValue);
}
Also used : AttributeValue(com.sun.identity.entitlement.xacml3.core.AttributeValue)

Aggregations

AttributeValue (com.sun.identity.entitlement.xacml3.core.AttributeValue)4 AttributeAssignmentExpression (com.sun.identity.entitlement.xacml3.core.AttributeAssignmentExpression)3 AdviceExpression (com.sun.identity.entitlement.xacml3.core.AdviceExpression)2 JAXBElement (javax.xml.bind.JAXBElement)1