Search in sources :

Example 1 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 2 with AdviceExpression

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

the class XACMLSchemaFactoryTest method setup.

@BeforeMethod
public void setup() throws EntitlementException {
    xacmlSchemaFactory = new XACMLSchemaFactory();
    resourceAttributeUtil = new ResourceAttributeUtil();
    PolicyResponseProvider rp1 = createPolicyResponseProvider(1);
    PolicyResponseProvider rp2 = createPolicyResponseProvider(2);
    PolicyResponseProvider rp3 = createPolicyResponseProvider(3);
    PolicyResponseProvider rp4 = createPolicyResponseProvider(4);
    rpSet = CollectionUtils.asSet(rp1, rp2, rp3, rp4);
    AdviceExpression ae1 = createAdviceExpression(rp1);
    AdviceExpression ae2 = createAdviceExpression(rp2);
    AdviceExpression ae3 = createAdviceExpression(rp3);
    AdviceExpression ae4 = createAdviceExpression(rp4);
    aes = new AdviceExpressions();
    aes.getAdviceExpression().addAll(Arrays.asList(ae1, ae2, ae3, ae4));
}
Also used : AdviceExpression(com.sun.identity.entitlement.xacml3.core.AdviceExpression) PolicyResponseProvider(com.sun.identity.entitlement.opensso.PolicyResponseProvider) AdviceExpressions(com.sun.identity.entitlement.xacml3.core.AdviceExpressions) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 3 with AdviceExpression

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

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

the class XACMLSchemaFactoryTest method shouldEnsureAdviceIsForPermitEffect.

@Test
public void shouldEnsureAdviceIsForPermitEffect() throws Exception {
    // Given
    StaticAttributes testAttribute = new StaticAttributes();
    // When
    AdviceExpression result = xacmlSchemaFactory.resourceAttributeToAdviceExpression(testAttribute);
    // Then
    assertThat(result).isNotNull();
    assertThat(result.getAppliesTo()).isEqualTo(EffectType.PERMIT);
}
Also used : AdviceExpression(com.sun.identity.entitlement.xacml3.core.AdviceExpression) StaticAttributes(com.sun.identity.entitlement.StaticAttributes) Test(org.testng.annotations.Test)

Example 5 with AdviceExpression

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

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