Search in sources :

Example 56 with Attribute

use of org.opensaml.saml2.core.Attribute in project cxf by apache.

the class SAMLClaimsTest method testSaml2StaticEndpointClaims.

/**
 * Test the creation of a SAML2 Assertion with StaticEndpointClaimsHandler
 */
@org.junit.Test
public void testSaml2StaticEndpointClaims() throws Exception {
    TokenProvider samlTokenProvider = new SAMLTokenProvider();
    TokenProviderParameters providerParameters = createProviderParameters(WSS4JConstants.WSS_SAML2_TOKEN_TYPE, STSConstants.BEARER_KEY_KEYTYPE, null);
    ClaimsManager claimsManager = new ClaimsManager();
    StaticEndpointClaimsHandler claimsHandler = new StaticEndpointClaimsHandler();
    // Create claims map for specific application
    Map<String, String> endpointClaimsMap = new HashMap<>();
    endpointClaimsMap.put(CLAIM_APPLICATION, CLAIM_APPLICATION_VALUE);
    Map<String, Map<String, String>> staticClaims = new HashMap<>();
    staticClaims.put(APPLICATION_APPLIES_TO, endpointClaimsMap);
    claimsHandler.setEndpointClaims(staticClaims);
    claimsHandler.setSupportedClaims(Collections.singletonList(CLAIM_APPLICATION));
    claimsManager.setClaimHandlers(Collections.singletonList((ClaimsHandler) claimsHandler));
    providerParameters.setClaimsManager(claimsManager);
    ClaimCollection claims = new ClaimCollection();
    Claim claim = new Claim();
    claim.setClaimType(CLAIM_APPLICATION);
    claims.add(claim);
    providerParameters.setRequestedPrimaryClaims(claims);
    assertTrue(samlTokenProvider.canHandleToken(WSS4JConstants.WSS_SAML2_TOKEN_TYPE));
    TokenProviderResponse providerResponse = samlTokenProvider.createToken(providerParameters);
    assertNotNull(providerResponse);
    assertTrue(providerResponse.getToken() != null && providerResponse.getTokenId() != null);
    Element token = (Element) providerResponse.getToken();
    String tokenString = DOM2Writer.nodeToString(token);
    assertTrue(tokenString.contains(providerResponse.getTokenId()));
    assertTrue(tokenString.contains("AttributeStatement"));
    assertTrue(tokenString.contains("alice"));
    assertTrue(tokenString.contains(SAML2Constants.CONF_BEARER));
    SamlAssertionWrapper assertion = new SamlAssertionWrapper(token);
    List<Attribute> attributes = assertion.getSaml2().getAttributeStatements().get(0).getAttributes();
    assertEquals(attributes.size(), 1);
    assertEquals(attributes.get(0).getName(), CLAIM_APPLICATION);
    XMLObject valueObj = attributes.get(0).getAttributeValues().get(0);
    assertEquals(valueObj.getDOM().getTextContent(), CLAIM_APPLICATION_VALUE);
}
Also used : StaticEndpointClaimsHandler(org.apache.cxf.sts.claims.StaticEndpointClaimsHandler) ClaimsHandler(org.apache.cxf.sts.claims.ClaimsHandler) StaticClaimsHandler(org.apache.cxf.sts.claims.StaticClaimsHandler) CustomClaimsHandler(org.apache.cxf.sts.common.CustomClaimsHandler) HashMap(java.util.HashMap) Attribute(org.opensaml.saml.saml2.core.Attribute) Element(org.w3c.dom.Element) SamlAssertionWrapper(org.apache.wss4j.common.saml.SamlAssertionWrapper) XMLObject(org.opensaml.core.xml.XMLObject) ClaimsManager(org.apache.cxf.sts.claims.ClaimsManager) StaticEndpointClaimsHandler(org.apache.cxf.sts.claims.StaticEndpointClaimsHandler) HashMap(java.util.HashMap) Map(java.util.Map) ClaimCollection(org.apache.cxf.rt.security.claims.ClaimCollection) Claim(org.apache.cxf.rt.security.claims.Claim)

Example 57 with Attribute

use of org.opensaml.saml2.core.Attribute in project verify-hub by alphagov.

the class VerifiedAttributesLoggerTest method shouldLogFirstNameHistory.

@Test
public void shouldLogFirstNameHistory() throws Exception {
    AttributeValue oldFirstNameAttributeValue = new PersonNameAttributeValueBuilder().withTo(DateTime.now().minusDays(181)).withVerified(true).build();
    AttributeValue currentFirstNameAttributeValue = new PersonNameAttributeValueBuilder().withFrom(DateTime.now()).withTo(null).build();
    Attribute firstNameAttribute = new AttributeBuilder().buildObject();
    firstNameAttribute.setName(IdaConstants.Attributes_1_1.Firstname.NAME);
    firstNameAttribute.getAttributeValues().add(oldFirstNameAttributeValue);
    firstNameAttribute.getAttributeValues().add(currentFirstNameAttributeValue);
    List<Attribute> attributes = aMatchingDatasetAttributeStatement_1_1().withFirstname(firstNameAttribute).build().getAttributes();
    AttributeStatementLogData actual = mapper.readValue(formatAttributes("any-issuer", LEVEL_2, attributes), AttributeStatementLogData.class);
    Map<String, List<VerifiedAttributeLogData>> attributesMap = actual.getAttributes();
    assertThat(attributesMap.get(IdaConstants.Attributes_1_1.Firstname.NAME)).isEqualTo(List.of(new VerifiedAttributeLogData(true, "more than 180 days"), new VerifiedAttributeLogData(false, null)));
}
Also used : AttributeValue(org.opensaml.saml.saml2.core.AttributeValue) AttributeBuilder(org.opensaml.saml.saml2.core.impl.AttributeBuilder) Attribute(org.opensaml.saml.saml2.core.Attribute) AttributeStatementLogData(uk.gov.ida.hub.samlengine.logging.data.AttributeStatementLogData) PersonNameAttributeValueBuilder(uk.gov.ida.saml.core.test.builders.PersonNameAttributeValueBuilder) List(java.util.List) VerifiedAttributeLogData(uk.gov.ida.hub.samlengine.logging.data.VerifiedAttributeLogData) Test(org.junit.jupiter.api.Test)

Example 58 with Attribute

use of org.opensaml.saml2.core.Attribute in project verify-hub by alphagov.

the class VerifiedAttributesLoggerTest method shouldLogPreviousAddressHistory.

@Test
public void shouldLogPreviousAddressHistory() throws Exception {
    AttributeValue previousAddressAttributeValue = new AddressAttributeValueBuilder_1_1().withFrom(DateTime.now().minusYears(10)).withTo(DateTime.now().minusYears(1)).withVerified(false).build();
    Attribute previousAddressAttribute = new AttributeBuilder().buildObject();
    previousAddressAttribute.setName(IdaConstants.Attributes_1_1.PreviousAddress.NAME);
    previousAddressAttribute.getAttributeValues().add(previousAddressAttributeValue);
    List<Attribute> attributes = aMatchingDatasetAttributeStatement_1_1().addPreviousAddress(previousAddressAttribute).build().getAttributes();
    AttributeStatementLogData actual = mapper.readValue(formatAttributes("any-issuer", LEVEL_2, attributes), AttributeStatementLogData.class);
    Map<String, List<VerifiedAttributeLogData>> attributesMap = actual.getAttributes();
    assertThat(attributesMap.get(IdaConstants.Attributes_1_1.PreviousAddress.NAME)).isEqualTo(List.of(new VerifiedAttributeLogData(false, "more than 180 days")));
}
Also used : AttributeValue(org.opensaml.saml.saml2.core.AttributeValue) AddressAttributeValueBuilder_1_1(uk.gov.ida.saml.core.test.builders.AddressAttributeValueBuilder_1_1) AttributeBuilder(org.opensaml.saml.saml2.core.impl.AttributeBuilder) Attribute(org.opensaml.saml.saml2.core.Attribute) AttributeStatementLogData(uk.gov.ida.hub.samlengine.logging.data.AttributeStatementLogData) List(java.util.List) VerifiedAttributeLogData(uk.gov.ida.hub.samlengine.logging.data.VerifiedAttributeLogData) Test(org.junit.jupiter.api.Test)

Example 59 with Attribute

use of org.opensaml.saml2.core.Attribute in project verify-hub by alphagov.

the class VerifiedAttributesLoggerTest method shouldLogDateOfBirthHistory.

@Test
public void shouldLogDateOfBirthHistory() throws Exception {
    Attribute dateOfBirthAttribute = new AttributeBuilder().buildObject();
    dateOfBirthAttribute.setName(IdaConstants.Attributes_1_1.DateOfBirth.NAME);
    AttributeValue oldDateOfBirthAttributeValue = new DateAttributeValueBuilder().withTo(DateTime.now().minusDays(1)).withVerified(true).build();
    AttributeValue currentDateOfBirthAttributeValue = new DateAttributeValueBuilder().withTo(null).build();
    dateOfBirthAttribute.getAttributeValues().add(oldDateOfBirthAttributeValue);
    dateOfBirthAttribute.getAttributeValues().add(currentDateOfBirthAttributeValue);
    List<Attribute> attributes = aMatchingDatasetAttributeStatement_1_1().withDateOfBirth(dateOfBirthAttribute).build().getAttributes();
    AttributeStatementLogData actual = mapper.readValue(formatAttributes("any-issuer", LEVEL_2, attributes), AttributeStatementLogData.class);
    Map<String, List<VerifiedAttributeLogData>> attributesMap = actual.getAttributes();
    assertThat(attributesMap.get(IdaConstants.Attributes_1_1.DateOfBirth.NAME)).isEqualTo(List.of(new VerifiedAttributeLogData(true, "less than 180 days"), new VerifiedAttributeLogData(false, null)));
}
Also used : AttributeBuilder(org.opensaml.saml.saml2.core.impl.AttributeBuilder) AttributeValue(org.opensaml.saml.saml2.core.AttributeValue) Attribute(org.opensaml.saml.saml2.core.Attribute) AttributeStatementLogData(uk.gov.ida.hub.samlengine.logging.data.AttributeStatementLogData) List(java.util.List) DateAttributeValueBuilder(uk.gov.ida.saml.core.test.builders.DateAttributeValueBuilder) VerifiedAttributeLogData(uk.gov.ida.hub.samlengine.logging.data.VerifiedAttributeLogData) Test(org.junit.jupiter.api.Test)

Example 60 with Attribute

use of org.opensaml.saml2.core.Attribute in project verify-hub by alphagov.

the class MatchingDatasetAssertionValidatorTest method validate_shouldNotThrowExceptionWhenAttributeValueFromDateIsAbsent.

@Test
public void validate_shouldNotThrowExceptionWhenAttributeValueFromDateIsAbsent() {
    Attribute attribute = aPersonName_1_1().addValue(aPersonNameValue().withFrom(null).build()).buildAsFirstname();
    AttributeStatement attributeStatement = aMatchingDatasetAttributeStatement_1_1().withFirstname(attribute).build();
    Assertion matchingDatasetAssertion = anAssertion().addAttributeStatement(attributeStatement).buildUnencrypted();
    validator.validate(matchingDatasetAssertion, RESPONSE_ISSUER_ID);
}
Also used : SimpleStringAttributeBuilder.aSimpleStringAttribute(uk.gov.ida.saml.core.test.builders.SimpleStringAttributeBuilder.aSimpleStringAttribute) Attribute(org.opensaml.saml.saml2.core.Attribute) SamlTransformationErrorFactory.emptyAttribute(uk.gov.ida.saml.core.errors.SamlTransformationErrorFactory.emptyAttribute) AttributeStatement(org.opensaml.saml.saml2.core.AttributeStatement) AssertionBuilder.anAssertion(uk.gov.ida.saml.core.test.builders.AssertionBuilder.anAssertion) Assertion(org.opensaml.saml.saml2.core.Assertion) Test(org.junit.jupiter.api.Test)

Aggregations

Attribute (org.opensaml.saml.saml2.core.Attribute)63 AttributeStatement (org.opensaml.saml.saml2.core.AttributeStatement)39 Test (org.junit.jupiter.api.Test)21 Assertion (org.opensaml.saml.saml2.core.Assertion)19 XMLObject (org.opensaml.core.xml.XMLObject)16 AttributeBuilder (org.opensaml.saml.saml2.core.impl.AttributeBuilder)13 List (java.util.List)10 EncryptedAttribute (org.opensaml.saml.saml2.core.EncryptedAttribute)10 XSString (org.opensaml.core.xml.schema.XSString)9 SimpleStringAttributeBuilder.aSimpleStringAttribute (uk.gov.ida.saml.core.test.builders.SimpleStringAttributeBuilder.aSimpleStringAttribute)9 Element (org.w3c.dom.Element)8 SamlTransformationErrorFactory.emptyAttribute (uk.gov.ida.saml.core.errors.SamlTransformationErrorFactory.emptyAttribute)8 ArrayList (java.util.ArrayList)7 AttributeStatementLogData (uk.gov.ida.hub.samlengine.logging.data.AttributeStatementLogData)7 AssertionBuilder.anAssertion (uk.gov.ida.saml.core.test.builders.AssertionBuilder.anAssertion)7 Map (java.util.Map)6 SAMLObjectBuilder (org.opensaml.common.SAMLObjectBuilder)6 AttributeValue (org.opensaml.saml.saml2.core.AttributeValue)6 NameID (org.opensaml.saml.saml2.core.NameID)6 VerifiedAttributeLogData (uk.gov.ida.hub.samlengine.logging.data.VerifiedAttributeLogData)6