Search in sources :

Example 31 with Attribute

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

the class HubAttributeQueryRequestToSamlAttributeQueryTransformerTest method transform_shouldSetAttributesToUserAccountCreationAttributes.

@Test
public void transform_shouldSetAttributesToUserAccountCreationAttributes() {
    Attribute attribute1 = openSamlXmlObjectFactory.createAttribute();
    Attribute attribute2 = openSamlXmlObjectFactory.createAttribute();
    when(attributeQueryAttributeFactory.createAttribute(CURRENT_ADDRESS)).thenReturn(attribute1);
    when(attributeQueryAttributeFactory.createAttribute(DATE_OF_BIRTH)).thenReturn(attribute2);
    HubAttributeQueryRequest hubAttributeQueryRequest = aHubAttributeQueryRequest().addUserAccountCreationAttribute(CURRENT_ADDRESS).addUserAccountCreationAttribute(DATE_OF_BIRTH).build();
    AttributeQuery transformedQuery = transformer.apply(hubAttributeQueryRequest);
    List<Attribute> transformedQueryAttributes = transformedQuery.getAttributes();
    assertThat(transformedQueryAttributes.size()).isEqualTo(2);
    assertThat(transformedQueryAttributes).contains(attribute1);
    assertThat(transformedQueryAttributes).contains(attribute2);
}
Also used : Attribute(org.opensaml.saml.saml2.core.Attribute) AttributeQuery(org.opensaml.saml.saml2.core.AttributeQuery) HubAttributeQueryRequestBuilder.aHubAttributeQueryRequest(uk.gov.ida.saml.hub.test.builders.HubAttributeQueryRequestBuilder.aHubAttributeQueryRequest) HubAttributeQueryRequest(uk.gov.ida.saml.hub.domain.HubAttributeQueryRequest) Test(org.junit.jupiter.api.Test)

Example 32 with Attribute

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

the class HubAttributeQueryRequestToSamlAttributeQueryTransformerTest method transform_shouldNotExplodeWhenUserAccountCreationAttributesAreAbsent.

@Test
public void transform_shouldNotExplodeWhenUserAccountCreationAttributesAreAbsent() {
    HubAttributeQueryRequest hubAttributeQueryRequest = aHubAttributeQueryRequest().withoutUserAccountCreationAttributes().build();
    AttributeQuery transformedQuery = transformer.apply(hubAttributeQueryRequest);
    List<Attribute> transformedQueryAttributes = transformedQuery.getAttributes();
    assertThat(transformedQueryAttributes.size()).isEqualTo(0);
}
Also used : AttributeQuery(org.opensaml.saml.saml2.core.AttributeQuery) Attribute(org.opensaml.saml.saml2.core.Attribute) HubAttributeQueryRequestBuilder.aHubAttributeQueryRequest(uk.gov.ida.saml.hub.test.builders.HubAttributeQueryRequestBuilder.aHubAttributeQueryRequest) HubAttributeQueryRequest(uk.gov.ida.saml.hub.domain.HubAttributeQueryRequest) Test(org.junit.jupiter.api.Test)

Example 33 with Attribute

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

the class VerifiedAttributesLoggerTest method shouldLogCurrentAddressHistory.

@Test
public void shouldLogCurrentAddressHistory() throws Exception {
    AttributeValue currentAddressAttributeValue = new AddressAttributeValueBuilder_1_1().withFrom(DateTime.now().minusYears(1)).withVerified(true).build();
    Attribute currentAddressAttribute = new AttributeBuilder().buildObject();
    currentAddressAttribute.setName(IdaConstants.Attributes_1_1.CurrentAddress.NAME);
    currentAddressAttribute.getAttributeValues().add(currentAddressAttributeValue);
    List<Attribute> attributes = aMatchingDatasetAttributeStatement_1_1().withCurrentAddress(currentAddressAttribute).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.CurrentAddress.NAME)).isEqualTo(List.of(new VerifiedAttributeLogData(true, null)));
}
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 34 with Attribute

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

the class VerifiedAttributesLoggerTest method shouldLogSurnameNameHistory.

@Test
public void shouldLogSurnameNameHistory() throws Exception {
    AttributeValue surnameAttributeValue = new PersonNameAttributeValueBuilder().withFrom(DateTime.parse("2000-12-31")).withVerified(true).build();
    Attribute surnameAttribute = new AttributeBuilder().buildObject();
    surnameAttribute.setName(IdaConstants.Attributes_1_1.Surname.NAME);
    surnameAttribute.getAttributeValues().add(surnameAttributeValue);
    List<Attribute> attributes = aMatchingDatasetAttributeStatement_1_1().withSurname(surnameAttribute).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.Surname.NAME)).isEqualTo(List.of(new VerifiedAttributeLogData(true, 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 35 with Attribute

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

the class VerifiedAttributesLoggerTest method shouldLogIssuerAndLevelOfAssurance.

@Test
public void shouldLogIssuerAndLevelOfAssurance() throws Exception {
    List<Attribute> anyAttributesList = aMatchingDatasetAttributeStatement_1_1().build().getAttributes();
    AttributeStatementLogData actual = mapper.readValue(formatAttributes("some-issuer", LEVEL_2, anyAttributesList), AttributeStatementLogData.class);
    assertThat(actual.getIssuer()).isEqualTo("some-issuer");
    assertThat(actual.getLevelOfAssurance()).isEqualTo(LEVEL_2);
}
Also used : Attribute(org.opensaml.saml.saml2.core.Attribute) AttributeStatementLogData(uk.gov.ida.hub.samlengine.logging.data.AttributeStatementLogData) Test(org.junit.jupiter.api.Test)

Aggregations

Attribute (org.opensaml.saml.saml2.core.Attribute)63 AttributeStatement (org.opensaml.saml.saml2.core.AttributeStatement)44 Test (org.junit.jupiter.api.Test)27 Assertion (org.opensaml.saml.saml2.core.Assertion)23 List (java.util.List)18 XMLObject (org.opensaml.core.xml.XMLObject)18 lombok.val (lombok.val)15 AttributeBuilder (org.opensaml.saml.saml2.core.impl.AttributeBuilder)13 Map (java.util.Map)12 EncryptedAttribute (org.opensaml.saml.saml2.core.EncryptedAttribute)12 ArrayList (java.util.ArrayList)11 HashMap (java.util.HashMap)11 XSString (org.opensaml.core.xml.schema.XSString)11 NameID (org.opensaml.saml.saml2.core.NameID)10 Slf4j (lombok.extern.slf4j.Slf4j)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 Issuer (org.opensaml.saml.saml2.core.Issuer)7 AttributeStatementLogData (uk.gov.ida.hub.samlengine.logging.data.AttributeStatementLogData)7