assertion.getAttributeStatements().add(attributeStatement);
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"); }
@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"); }
List<Attribute> attributes = assertion.getAttributeStatements().get(0).getAttributes();
public static String getValueFromAssertions(final List<Assertion> assertions, final String attributeKey) { if (assertions == null || attributeKey == null) { return null; } for (Assertion assertion : assertions) { String value = getValueFromAttributeStatements(assertion.getAttributeStatements(), attributeKey); if (value != null) { return value; } } return null; }
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 ""; }
username = SAMLUtils.getValueFromAttributeStatements(assertion.getAttributeStatements(), SAML2AuthManager.SAMLUserAttributeName.value());
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; }
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; } }
String[] roles = null; String roleClaim = getRoleClaim(); List<AttributeStatement> attributeStatementList = assertion.getAttributeStatements();
if (assertion != null && assertion.getAttributeStatements() != null) { List<AttributeStatement> attributeStatementList = assertion.getAttributeStatements();
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) { if (attribute.getAttributeValues().size() > 1) { List<XMLObject> attributeValues = attribute.getAttributeValues(); List<String> attributeValuesList = new ArrayList<String>(); for (XMLObject attributeValue : attributeValues) { attributeValuesList.add(attributeValue.getDOM().getTextContent()); } userAttributes.put(attribute.getName(), attributeValuesList); } else { userAttributes.put(attribute.getName(), attribute.getAttributeValues().get(0).getDOM().getTextContent()); } } } } return userAttributes; }
/** * Checks that the Subject element is present when required. * * @param assertion * @throws ValidationException */ protected void validateSubject(Assertion assertion) throws ValidationException { if ((assertion.getStatements() == null || assertion.getStatements().size() == 0) && (assertion.getAuthnStatements() == null || assertion.getAuthnStatements().size() == 0) && (assertion.getAttributeStatements() == null || assertion.getAttributeStatements().size() == 0) && (assertion.getAuthzDecisionStatements() == null || assertion.getAuthzDecisionStatements().size() == 0) && assertion.getSubject() == null) { throw new ValidationException("Subject is required when Statements are absent"); } if (assertion.getAuthnStatements().size() > 0 && assertion.getSubject() == null) { throw new ValidationException("Assertions containing AuthnStatements require a Subject"); } if (assertion.getAuthzDecisionStatements().size() > 0 && assertion.getSubject() == null) { throw new ValidationException("Assertions containing AuthzDecisionStatements require a Subject"); } if (assertion.getAttributeStatements().size() > 0 && assertion.getSubject() == null) { throw new ValidationException("Assertions containing AttributeStatements require a Subject"); } } }
for (AttributeStatement atbs : assertion.getAttributeStatements()) { for (Attribute atb : atbs.getAttributes()) { final String name = atb.getName();
@Override public Assertion build() { AssertionBuilder assertionBuilder = (AssertionBuilder) xmlObjectBuilderFactory.getBuilder(Assertion.DEFAULT_ELEMENT_NAME); Assertion assertion = assertionBuilder.buildObject(); assertion.setID(id); assertion.setIssueInstant(issueInstant); assertion.setVersion(SAMLVersion.VERSION_20); assertion.setIssuer(issuer); assertion.setSubject(subject); assertion.setConditions(conditions); if(signature !=null){ assertion.setSignature(signature); } if(authnStatements.size() > 0){ for (AuthnStatement authnStatement : authnStatements) { assertion.getAuthnStatements().add(authnStatement); } } if(attributeStatements.size() > 0){ for (AttributeStatement attributeStatement : attributeStatements) { assertion.getAttributeStatements().add(attributeStatement); } } return assertion; }
protected void buildAttributeStatement(Set<Claim> claims, Assertion assertion, SAML2SSOContext saml2SSOContext, ResponseBuilderConfig config, AuthenticationContext context) { AttributeStatement attStmt = new AttributeStatementBuilder().buildObject(); Iterator<Claim> iterator = claims.iterator(); while (iterator.hasNext()) { Claim claim = iterator.next(); String claimUri = claim.getClaimUri(); String claimValue = claim.getValue(); Attribute attribute = new AttributeBuilder().buildObject(); attribute.setName(claimUri); //setting NAMEFORMAT attribute value to basic attribute profile attribute.setNameFormat(Attribute.BASIC); // 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(claimValue); attribute.getAttributeValues().add(stringValue); attStmt.getAttributes().add(attribute); } if (attStmt != null) { assertion.getAttributeStatements().add(attStmt); } }
public static Assertion buildAssertion(SAMLPrincipal principal, Status status, String entityId) { Assertion assertion = buildSAMLObject(Assertion.class, Assertion.DEFAULT_ELEMENT_NAME); if (status.getStatusCode().getValue().equals(StatusCode.SUCCESS_URI)) { Subject subject = buildSubject(principal.getNameID(), principal.getNameIDType(), principal.getAssertionConsumerServiceURL(), principal.getRequestID()); assertion.setSubject(subject); } Issuer issuer = buildIssuer(entityId); Audience audience = buildSAMLObject(Audience.class, Audience.DEFAULT_ELEMENT_NAME); audience.setAudienceURI(principal.getServiceProviderEntityID()); AudienceRestriction audienceRestriction = buildSAMLObject(AudienceRestriction.class, AudienceRestriction.DEFAULT_ELEMENT_NAME); audienceRestriction.getAudiences().add(audience); Conditions conditions = buildSAMLObject(Conditions.class, Conditions.DEFAULT_ELEMENT_NAME); conditions.getAudienceRestrictions().add(audienceRestriction); assertion.setConditions(conditions); AuthnStatement authnStatement = buildAuthnStatement(new DateTime(), entityId); assertion.setIssuer(issuer); assertion.getAuthnStatements().add(authnStatement); assertion.getAttributeStatements().add(buildAttributeStatement(principal.getAttributes())); assertion.setID(randomSAMLId()); assertion.setIssueInstant(new DateTime()); return assertion; }
SAMLAssertionBuilder.createConditions(assertionBean.getConditionsBean()); assertion.setConditions(conditions); assertion.getAttributeStatements().addAll(attributeStatements); evidenceElement.getAssertions().add(assertion);
assertion.getAttributeStatements().add(this.attributeStmt); assertion.setID(assertionId);
assertion.getAttributeStatements().add(this.attributeStmt); assertion.setID(assertionId);