* @return the attribute statement
*/
private AttributeStatement newAttributeStatement(
final Subject subject, final Map<String, Object> attributes) {
final AttributeStatement attrStatement = newSamlObject(AttributeStatement.class);
attrStatement.setSubject(subject);
for (final Entry<String, Object> e : attributes.entrySet()) {
if (e.getValue() instanceof Collection<?> && ((Collection<?>) e.getValue()).isEmpty()) {
// bnoordhuis: don't add the attribute, it causes a org.opensaml.MalformedException
logger.info("Skipping attribute {} because it does not have any values.", e.getKey());
continue;
}
final Attribute attribute = newSamlObject(Attribute.class);
attribute.setAttributeName(e.getKey());
attribute.setAttributeNamespace(VALIDATION_SAML_ATTRIBUTE_NAMESPACE);
if (e.getValue() instanceof Collection<?>) {
final Collection<?> c = (Collection<?>) e.getValue();
for (final Object value : c) {
attribute.getAttributeValues().add(newAttributeValue(value));
}
} else {
attribute.getAttributeValues().add(newAttributeValue(e.getValue()));
}
attrStatement.getAttributes().add(attribute);
}
return attrStatement;
}