private final static String USERNAME_ATTRIBUTE_NAME = "urn:oid:0.9.2342.19200300.100.1.3" private String getUsername(Assertion assertion) { for (AttributeStatement attributeStatement : assertion.getAttributeStatements()) { for (Attribute attribute : attributeStatement.getAttributes()) { if (USERNAME_ATTRIBUTE_NAME.equals(attribute.getName())) { List<XMLObject> attributeValues = attribute.getAttributeValues(); if (!attributeValues.isEmpty()) { return getAttributeValue(attributeValues.get(0)); } } } } throw new IllegalArgumentException("no username attribute found"); }
private Map<String, String> setSAMLDetails(org.opensaml.saml2.core.Response response2){ Map<String, String> samlDetailsMap = new HashMap<String, String>(); try { List<Assertion> assertions = response2.getAssertions(); LOGGER.error("No of assertions : "+assertions.size()); for(Assertion assertion:assertions){ List<AttributeStatement> attributeStatements = assertion.getAttributeStatements(); for(AttributeStatement attributeStatement: attributeStatements){ List<Attribute> attributes = attributeStatement.getAttributes(); for(Attribute attribute: attributes){ String name = attribute.getName(); List<XMLObject> attributes1 = attribute.getAttributeValues(); for(XMLObject xmlObject : attributes1){ if(xmlObject instanceof XSString){ samlDetailsMap.put(name, ((XSString) xmlObject).getValue()); LOGGER.error("Name is : "+name+" value is : "+((XSString) xmlObject).getValue()); }else if(xmlObject instanceof XSAnyImpl){ String value = ((XSAnyImpl) xmlObject).getTextContent(); samlDetailsMap.put(name, value); } } } } } } catch (Exception e) { LOGGER.error("Exception occurred while setting the saml details"); } LOGGER.error("Exiting from setSAMLDetails method"); return samlDetailsMap; }