Skip to content

Commit

Permalink
skip over attributes with empty value and warn
Browse files Browse the repository at this point in the history
  • Loading branch information
mmoayyed committed Aug 6, 2022
1 parent df1aa92 commit 75ad84f
Showing 1 changed file with 36 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,26 +76,46 @@ public boolean equals(final Object that) {
return EqualsBuilder.reflectionEquals(this, that);
}


private Collection<IdPAttributePrincipal> produceIdpAttributePrincipal(final Map<String, Object> casAttributes) {
final Set<IdPAttributePrincipal> principals = new HashSet<>();
for (final Map.Entry<String, Object> entry : casAttributes.entrySet()) {
final IdPAttribute attr = new IdPAttribute(entry.getKey());

final List<IdPAttributeValue> attributeValues = new ArrayList<>();
if (entry.getValue() instanceof Collection) {
for (final Object value : (Collection) entry.getValue()) {
attributeValues.add(new StringAttributeValue(value.toString()));
logger.debug("Processing CAS attribute {}", entry.getKey());
try {
final List<IdPAttributeValue> attributeValues = new ArrayList<>();
if (entry.getValue() instanceof Collection) {
for (final Object value : (Collection) entry.getValue()) {
final String attributeValue = value.toString();
if (attributeValue.trim().isEmpty()) {
logger.warn("Skipping attribute {} with empty value(s)", entry.getKey());
} else {
logger.debug("Adding value {} for attribute {}", attributeValue, entry.getKey());
attributeValues.add(new StringAttributeValue(attributeValue));
}
}
} else {
final String attributeValue = entry.getValue().toString();
if (attributeValue.trim().isEmpty()) {
logger.warn("Skipping attribute {} with empty value(s)", entry.getKey());
} else {
logger.debug("Adding value {} for attribute {}", attributeValue, entry.getKey());
attributeValues.add(new StringAttributeValue(attributeValue));
}
}
if (!attributeValues.isEmpty()) {
final IdPAttribute attribute = new IdPAttribute(entry.getKey());
attribute.setValues(attributeValues);
logger.debug("Added attribute {} with values {}", entry.getKey(), entry.getValue());
principals.add(new IdPAttributePrincipal(attribute));
} else {
logger.warn("Skipped attribute {} since it contains no values", entry.getKey());
}
} catch (Exception e) {
final String message = "Unable to process attribute: " + entry.getKey() + ":" + e.getMessage();
if (logger.isDebugEnabled()) {
logger.warn(message, e);
} else {
logger.warn(message);
}
} else {
attributeValues.add(new StringAttributeValue(entry.getValue().toString()));
}
if (!attributeValues.isEmpty()) {
attr.setValues(attributeValues);
logger.debug("Added attribute {} with values {}", entry.getKey(), entry.getValue());
principals.add(new IdPAttributePrincipal(attr));
} else {
logger.warn("Skipped attribute {} since it contains no values", entry.getKey());
}
}
return principals;
Expand Down

0 comments on commit 75ad84f

Please sign in to comment.