use of org.opensaml.saml.saml2.core.AttributeValue 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;
}
use of org.opensaml.saml.saml2.core.AttributeValue in project OpenAM by OpenRock.
the class XACMLPrivilegeUtils method resourceNameToMatch.
public static Match resourceNameToMatch(String resourceName, String applicationName) {
if (resourceName == null || resourceName.length() == 0) {
return null;
}
Match match = new Match();
String matchId = XACMLConstants.ENTITLEMENT_RESOURCE_MATCH + ":" + applicationName;
match.setMatchId(matchId);
AttributeValue attributeValue = new AttributeValue();
String dataType = XACMLConstants.XS_STRING;
attributeValue.setDataType(dataType);
attributeValue.getContent().add(resourceName);
AttributeDesignator attributeDesignator = new AttributeDesignator();
String category = XACMLConstants.XACML_RESOURCE_CATEGORY;
attributeDesignator.setCategory(category);
String attributeId = XACMLConstants.XACML_RESOURCE_ID;
attributeDesignator.setAttributeId(attributeId);
String dt = XACMLConstants.XS_STRING;
attributeDesignator.setDataType(dt);
// TOOD: not a constant?
String issuer = XACMLConstants.RESOURCE_ISSUER;
// attributeDesignator.setIssuer(issuer); TODO: verify and fix
boolean mustBePresent = true;
attributeDesignator.setMustBePresent(mustBePresent);
match.setAttributeValue(attributeValue);
match.setAttributeDesignator(attributeDesignator);
return match;
}
use of org.opensaml.saml.saml2.core.AttributeValue in project OpenAM by OpenRock.
the class XACMLPrivilegeUtils method getRealmsAppsResources.
static JSONObject getRealmsAppsResources(List<Match> matches) throws JSONException {
if (matches == null) {
return null;
}
JSONObject jo = null;
String jsonString = null;
for (Match match : matches) {
String matchId = match.getMatchId();
if ((matchId != null) && matchId.equals(XACMLConstants.JSON_REALMS_APPS_RESOURCES_MATCH)) {
AttributeValue attributeValue = match.getAttributeValue();
if (attributeValue != null) {
List<Object> contentList = attributeValue.getContent();
if ((contentList != null) && !contentList.isEmpty()) {
Object obj = contentList.get(0);
jsonString = obj.toString();
break;
}
}
}
}
if (jsonString != null) {
jo = new JSONObject(jsonString);
}
return jo;
}
use of org.opensaml.saml.saml2.core.AttributeValue 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 org.opensaml.saml.saml2.core.AttributeValue in project verify-hub by alphagov.
the class VerifiedAttributesLoggerTest method shouldLogMiddleNamesNameHistory.
@Test
public void shouldLogMiddleNamesNameHistory() throws Exception {
AttributeValue oldMiddleNamesAttributeValue = new PersonNameAttributeValueBuilder().withFrom(DateTime.parse("2000-12-31")).withTo(DateTime.now().minusDays(406)).withVerified(true).build();
AttributeValue currentMiddleNamesAttributeValue = new PersonNameAttributeValueBuilder().withFrom(DateTime.now().minusDays(405)).withVerified(true).build();
Attribute middleNamesAttribute = new AttributeBuilder().buildObject();
middleNamesAttribute.setName(IdaConstants.Attributes_1_1.Middlename.NAME);
middleNamesAttribute.getAttributeValues().add(oldMiddleNamesAttributeValue);
middleNamesAttribute.getAttributeValues().add(currentMiddleNamesAttributeValue);
List<Attribute> attributes = aMatchingDatasetAttributeStatement_1_1().withMiddleNames(middleNamesAttribute).build().getAttributes();
AttributeStatementLogData actual = mapper.readValue(formatAttributes("any-issuer", LEVEL_2, attributes), AttributeStatementLogData.class);
Map<String, List<VerifiedAttributeLogData>> attributesMap = actual.getAttributes();
assertThat(attributesMap.get(IdaConstants.Attributes_1_1.Middlename.NAME)).isEqualTo(ImmutableList.of(new VerifiedAttributeLogData(true, "more than 405 days"), new VerifiedAttributeLogData(true, null)));
}
Aggregations