Source:
<code>protected List<Claim> parseClaimsInAssertion( org.opensaml.saml.saml2.core.Assertion assertion) { List<org.opensaml.saml.saml2.core.AttributeStatement> attributeStatements = assertion .getAttributeStatements(); if (attributeStatements == null || attributeStatements.isEmpty()) { LOG.debug("No attribute statements found"); return Collections.emptyList(); } List<Claim> collection = new ArrayList<>(); Map<String, Claim> claimsMap = new HashMap<>(); for (org.opensaml.saml.saml2.core.AttributeStatement statement : attributeStatements) { LOG.debug("parsing statement: {}", statement.getElementQName()); List<org.opensaml.saml.saml2.core.Attribute> attributes = statement .getAttributes(); for (org.opensaml.saml.saml2.core.Attribute attribute : attributes) { LOG.debug("parsing attribute: {}", attribute.getName()); Claim c = new Claim(); <START> String attributeName; try { attributeName = URLEncoder.encode(attribute.getName(), "UTF-8"); } catch (UnsupportedEncodingException e) { attributeName = attribute.getName(); } URI attrName = URI.create(attributeName); <END> if (ClaimTypes.URI_BASE.toString().equals(attribute.getNameFormat()) && !attrName.isAbsolute()) { c.setClaimType(URI.create(ClaimTypes.URI_BASE + "/" + attributeName)); } else { c.setClaimType(attrName); } c.setIssuer(assertion.getIssuer().getNameQualifier()); List<String> valueList = new ArrayList<>(); for (XMLObject attributeValue : attribute.getAttributeValues()) { Element attributeValueElement = attributeValue.getDOM(); String value = attributeValueElement.getTextContent(); LOG.debug(" [{}]", value); valueList.add(value); } mergeClaimToMap(claimsMap, c, valueList); } } collection.addAll(claimsMap.values()); return collection; }</code><technical_language>This approach is work, URL encode values supposed URL encoded. Instead this work: URI attrName = parseAttributeName(attribute); ... private URI parseAttributeName(Attribute attribute) { try { return URI.create(attribute.getName()); } catch (IllegalArgumentException ex) { // attribute name a space in it... try { return URI.create(URLEncoder.encode(attribute.getName(), StandardCharsets.UTF_8.name())); } catch (UnsupportedEncodingException e) { throw new IllegalStateException("Unsupported Claim type"); } } }</technical_language>

Target:
protected List<Claim> parseClaimsInAssertion( org.opensaml.saml.saml2.core.Assertion assertion) { List<org.opensaml.saml.saml2.core.AttributeStatement> attributeStatements = assertion .getAttributeStatements(); if (attributeStatements == null || attributeStatements.isEmpty()) { LOG.debug("No attribute statements found"); return Collections.emptyList(); } List<Claim> collection = new ArrayList<>(); Map<String, Claim> claimsMap = new HashMap<>(); for (org.opensaml.saml.saml2.core.AttributeStatement statement : attributeStatements) { LOG.debug("parsing statement: {}", statement.getElementQName()); List<org.opensaml.saml.saml2.core.Attribute> attributes = statement .getAttributes(); for (org.opensaml.saml.saml2.core.Attribute attribute : attributes) { LOG.debug("parsing attribute: {}", attribute.getName()); Claim c = new Claim(); URI attrName = parseAttributeName(attribute.getName()); if (ClaimTypes.URI_BASE.toString().equals(attribute.getNameFormat()) && !attrName.isAbsolute()) { c.setClaimType(URI.create(ClaimTypes.URI_BASE + "/" + attrName.toString())); } else { c.setClaimType(attrName); } c.setIssuer(assertion.getIssuer().getNameQualifier()); List<String> valueList = new ArrayList<>(); for (XMLObject attributeValue : attribute.getAttributeValues()) { Element attributeValueElement = attributeValue.getDOM(); String value = attributeValueElement.getTextContent(); LOG.debug(" [{}]", value); valueList.add(value); } mergeClaimToMap(claimsMap, c, valueList); } } collection.addAll(claimsMap.values()); return collection; }