private AttributeStatement buildAttributeStatement(Map<String, String> claims) { AttributeStatement attStmt = null; if (claims != null) { attStmt = new AttributeStatementBuilder().buildObject(); Iterator<String> ite = claims.keySet().iterator(); for (int i = 0; i < claims.size(); i++) { Attribute attrib = new AttributeBuilder().buildObject(); String claimUri = ite.next(); attrib.setName(claimUri); // look // https://wiki.shibboleth.net/confluence/display/OpenSAML/OSTwoUsrManJavaAnyTypes XSStringBuilder stringBuilder = (XSStringBuilder) Configuration.getBuilderFactory().getBuilder(XSString.TYPE_NAME); XSString stringValue = stringBuilder.buildObject(AttributeValue.DEFAULT_ELEMENT_NAME, XSString.TYPE_NAME); stringValue.setValue(claims.get(claimUri)); attrib.getAttributeValues().add(stringValue); attStmt.getAttributes().add(attrib); } } return attStmt; }
private Map<String, Object> getUserAttributes(ResponseImpl samlResponse) { Map<String, Object> userAttributes = new HashMap<>(); // Add 'Subject' Assertion assertion = samlResponse.getAssertions().get(0); userAttributes.put( SAMLConstants.SAML2_ASSERTION_SUBJECT, assertion.getSubject().getNameID().getValue()); // Add other user attributes. List<AttributeStatement> attributeStatements = assertion.getAttributeStatements(); if (attributeStatements != null) { for (AttributeStatement attributeStatement : attributeStatements) { List<Attribute> attributes = attributeStatement.getAttributes(); for (Attribute attribute : attributes) { userAttributes.put( attribute.getName(), attribute.getAttributeValues().get(0).getDOM().getTextContent()); } } } return userAttributes; }