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;
}
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));
}
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);
}
}
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);
}
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;
}
Aggregations