*
* @param attributes a map with keys from {@link AttributeConstants}
* @return
*/
public static AttributeStatementType createAttributeStatement(Map<String, Object> attributes) {
AttributeStatementType attrStatement = null;
int i = 0;
Set<String> keys = attributes.keySet();
for (String key : keys) {
if (i == 0) {
// Deal with the X500 Profile of SAML2
attrStatement = new AttributeStatementType();
i++;
}
// if the attribute contains roles, add each role as an attribute.
if (AttributeConstants.ROLES.equalsIgnoreCase(key)) {
Object value = attributes.get(key);
if (value instanceof Collection<?>) {
Collection<?> roles = (Collection<?>) value;
attrStatement = createAttributeStatement(new ArrayList(roles));
}
}
else {
AttributeType att;
Object value = attributes.get(key);
String uri = X500SAMLProfileConstants.getOID(key);
if (StringUtil.isNotNull(uri)) {
att = getX500Attribute(uri);
att.setFriendlyName(key);
} else {
att = new AttributeType(key);
att.setFriendlyName(key);
att.setNameFormat(JBossSAMLURIConstants.ATTRIBUTE_FORMAT_URI.get());
}
att.addAttributeValue(value);
attrStatement.addAttribute(new ASTChoiceType(att));
}
}
return attrStatement;
}