attributeStatement.getAttributes().add(authoritiesAttribute); attributeStatement.getAttributes().add(emailAttribute); Attribute idAttribute = buildStringAttribute("id", Collections.singletonList(principal.getId())); attributeStatement.getAttributes().add(idAttribute); Attribute nameAttribute = buildStringAttribute("name", Collections.singletonList(principal.getName())); attributeStatement.getAttributes().add(nameAttribute); Attribute originAttribute = buildStringAttribute("origin", Collections.singletonList(principal.getOrigin())); attributeStatement.getAttributes().add(originAttribute); Attribute zoneAttribute = buildStringAttribute("zoneId", Collections.singletonList(principal.getZoneId())); attributeStatement.getAttributes().add(zoneAttribute); attributeStatement.getAttributes().add(buildStringAttribute(name, stringValues)); if (StringUtils.hasText(givenName) && attributeMappings.containsKey("given_name")) { Attribute givenNameAttribute = buildStringAttribute(attributeMappings.get("given_name").toString(), Collections.singletonList(givenName)); attributeStatement.getAttributes().add(givenNameAttribute); if (StringUtils.hasText(familyName) && attributeMappings.containsKey("family_name")) { Attribute familyNameAttribute = buildStringAttribute(attributeMappings.get("family_name").toString(), Collections.singletonList(familyName)); attributeStatement.getAttributes().add(familyNameAttribute); if (StringUtils.hasText(phoneNumber) && attributeMappings.containsKey("phone_number")) { Attribute phoneNumberAttribute = buildStringAttribute(attributeMappings.get("phone_number").toString(), Collections.singletonList(phoneNumber)); attributeStatement.getAttributes().add(phoneNumberAttribute); if (StringUtils.hasText(email) && attributeMappings.containsKey("email")) { Attribute customEmailAttribute = buildStringAttribute(attributeMappings.get("email").toString(), Collections.singletonList(email)); attributeStatement.getAttributes().add(customEmailAttribute);
/** {@inheritDoc} */ protected void processChildElement(XMLObject parentObject, XMLObject childObject) throws UnmarshallingException { AttributeStatement attributeStatement = (AttributeStatement) parentObject; if (childObject instanceof Attribute) { attributeStatement.getAttributes().add((Attribute) childObject); } else if (childObject instanceof EncryptedAttribute) { attributeStatement.getEncryptedAttributes().add((EncryptedAttribute) childObject); } else { super.processChildElement(parentObject, childObject); } } }
attributeStatement.getEncryptedAttributes().add( encrypter.encrypt(samlAttribute)); } catch (EncryptionException e) { attributeStatement.getAttributes().add(samlAttribute);
private void verifyAssertionAttributes(String authenticationId, Assertion assertion) { List<Attribute> attributes = assertion.getAttributeStatements().get(0).getAttributes(); assertAttributeValue(attributes, "email", "marissa@testing.org"); assertAttributeValue(attributes, "id", authenticationId); assertAttributeValue(attributes, "name", "marissa"); assertAttributeValue(attributes, "origin", OriginKeys.UAA); assertAttributeValue(attributes, "zoneId", "uaa"); }
List<Attribute> attributes = attributeStatement.getAttributes(); for (Attribute attribute : attributes) { if (!attributeStatement.getEncryptedAttributes().isEmpty()) { .getEncryptedAttributes()) {
@Test public void verifyAttributeMappingsIgnoredForNullValues() throws Exception { user.setPhoneNumbers(Collections.singletonList(new ScimUser.PhoneNumber(null))); Map<String, Object> attributeMappings = new HashMap<>(); attributeMappings.put("given_name", "first_name"); attributeMappings.put("phone_number", "cell_phone"); samlServiceProvider.getConfig().setAttributeMappings(attributeMappings); String authenticationId = UUID.randomUUID().toString(); Authentication authentication = samlTestUtils.mockUaaAuthentication(authenticationId); SAMLMessageContext context = samlTestUtils.mockSamlMessageContext( samlTestUtils.mockAuthnRequest(NameIDType.UNSPECIFIED)); IdpWebSSOProfileOptions options = new IdpWebSSOProfileOptions(); options.setAssertionsSigned(false); profile.buildResponse(authentication, context, options); Response response = (Response) context.getOutboundSAMLMessage(); Assertion assertion = response.getAssertions().get(0); profile.buildAttributeStatement(assertion, authentication, samlServiceProvider.getEntityId()); List<Attribute> attributes = assertion.getAttributeStatements().get(0).getAttributes(); assertAttributeValue(attributes, "first_name", user.getGivenName()); assertAttributeDoesNotExist(attributes, "last_name"); assertAttributeDoesNotExist(attributes, "cell_phone"); }
if (assertion == subjectAssertion || isIncludeAllAttributes()) { for (AttributeStatement attStatement : assertion.getAttributeStatements()) { for (Attribute att : attStatement.getAttributes()) { log.debug("Including attribute {} from assertion {}", att.getName(), assertion.getID()); attributes.add(att); for (EncryptedAttribute att : attStatement.getEncryptedAttributes()) { Assert.notNull(context.getLocalDecrypter(), "Can't decrypt Attribute, no decrypter is set in the context"); Attribute decryptedAttribute = context.getLocalDecrypter().decrypt(att);
List<Attribute> attributes = assertion.getAttributeStatements().get(0).getAttributes();
private String getValueFromAttributeStatements(final Assertion assertion, final String name) { final List<AttributeStatement> attributeStatements = assertion.getAttributeStatements(); for (AttributeStatement attributeStatement : attributeStatements) { final List<Attribute> attributes = attributeStatement.getAttributes(); for (Attribute attribute : attributes) { if (name.equals(attribute.getName())) { return attribute.getAttributeValues().get(0).getDOM().getTextContent(); } } } return ""; }
public static String getValueFromAttributeStatements(final List<AttributeStatement> attributeStatements, final String attributeKey) { if (attributeStatements == null || attributeStatements.size() < 1 || attributeKey == null) { return null; } for (AttributeStatement attributeStatement : attributeStatements) { if (attributeStatement == null || attributeStatements.size() < 1) { continue; } for (Attribute attribute : attributeStatement.getAttributes()) { if (attribute.getAttributeValues() != null && attribute.getAttributeValues().size() > 0) { String value = attribute.getAttributeValues().get(0).getDOM().getTextContent(); s_logger.debug("SAML attribute name: " + attribute.getName() + " friendly-name:" + attribute.getFriendlyName() + " value:" + value); if (attributeKey.equals(attribute.getName()) || attributeKey.equals(attribute.getFriendlyName())) { return value; } } } } return null; }
/** * Checks that at least one Attribute is present. * * @param attributeStatement * @throws ValidationException */ protected void validateAttributes(AttributeStatement attributeStatement) throws ValidationException { if (attributeStatement.getAttributes() == null || attributeStatement.getAttributes().size() == 0) { throw new ValidationException("Must contain one or more attributes"); } } }
@Override public AttributeStatement build() { AttributeStatement attributeStatement = new AttributeStatementBuilder().buildObject(); if(attributes.size() >0){ for (Attribute attribute : attributes) { attributeStatement.getAttributes().add(attribute); } } return attributeStatement; } }
/** {@inheritDoc} */ public AttributeStatement buildAttributeStatement(AttributeQuery query, Collection<BaseAttribute> attributes) throws AttributeEncodingException { Collection<Attribute> encodedAttributes = encodeAttributes(query, attributes); filterAttributesByValue(query, encodedAttributes); if (!encodedAttributes.isEmpty()) { AttributeStatement statement = statementBuilder.buildObject(); List<org.opensaml.saml2.core.Attribute> samlAttributes = statement.getAttributes(); samlAttributes.addAll(encodedAttributes); return statement; } else { log.debug("No attributes remained after encoding and filtering by value, no attribute statement built"); return null; } }
private static AttributeStatement buildAttributeStatement(List<SAMLAttribute> attributes) { AttributeStatement attributeStatement = buildSAMLObject(AttributeStatement.class, AttributeStatement.DEFAULT_ELEMENT_NAME); attributes.forEach(entry -> attributeStatement.getAttributes().add( buildAttribute( entry.getName(), entry.getValues()))); return attributeStatement; }
private List<SAML2Attribute> parseAttributes(Assertion assertion){ List<AttributeStatement> attribStatmts = assertion.getAttributeStatements(); List<SAML2Attribute> saml2Attributes = new ArrayList<SAML2Attribute>(); for ( AttributeStatement attrStatement : attribStatmts ) { List<Attribute> attributes = attrStatement.getAttributes(); for ( Attribute attr : attributes ){ List<XMLObject> vals = attr.getAttributeValues(); String value = vals.get(0).getDOM().getFirstChild().getNodeValue(); String name = attr.getName(); String logMess = " " + name + " : " + value; logger.info(logMess); SAML2Attribute sa2attr = new SAML2Attribute(name,value); saml2Attributes.add(sa2attr); } } return saml2Attributes; } }
Iterator<Attribute> attrs = statement.getAttributes().iterator();
private Map<String, String> getAssertionStatements(Assertion assertion) { Map<String, String> results = new HashMap<String, String>(); if (assertion != null && assertion.getAttributeStatements() != null) { List<AttributeStatement> attributeStatementList = assertion.getAttributeStatements(); for (AttributeStatement statement : attributeStatementList) { List<Attribute> attributesList = statement.getAttributes(); for (Attribute attribute : attributesList) { Element value = attribute.getAttributeValues().get(0).getDOM(); String attributeValue = value.getTextContent(); results.put(attribute.getName(), attributeValue); } } } return results; }
List<Attribute> attributesList = statement.getAttributes(); for (Attribute attribute : attributesList) { String attributeName = attribute.getName();
List<Attribute> attributesList = statement.getAttributes(); for (Attribute attribute : attributesList) { String attributeName = attribute.getName();
List<Attribute> attributesList = statement.getAttributes(); for (Attribute attribute : attributesList) { String attributeName = attribute.getName();