Search in sources :

Example 61 with Attribute

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

the class MatchingDatasetAssertionValidatorTest method validate_shouldThrowExceptionWhenAttributeValueTypeIsValidButIncorrectForAttribute.

@Test
public void validate_shouldThrowExceptionWhenAttributeValueTypeIsValidButIncorrectForAttribute() {
    Attribute attribute = aPersonName_1_1().addValue(aPersonNameValue().withFrom(null).build()).buildAsFirstname();
    attribute.setName(IdaConstants.Attributes_1_1.DateOfBirth.NAME);
    AttributeStatement attributeStatement = aMatchingDatasetAttributeStatement_1_1().withDateOfBirth(attribute).build();
    Assertion matchingDatasetAssertion = anAssertion().addAttributeStatement(attributeStatement).buildUnencrypted();
    validateFail(() -> validator.validate(matchingDatasetAssertion, RESPONSE_ISSUER_ID), attributeWithIncorrectType(IdaConstants.Attributes_1_1.DateOfBirth.NAME, Date.TYPE_NAME, PersonName.TYPE_NAME));
}
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)

Example 62 with Attribute

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

the class MatchingDatasetAssertionValidatorTest method validate_shouldThrowExceptionWhenAttributeIsMissingValue.

@Test
public void validate_shouldThrowExceptionWhenAttributeIsMissingValue() {
    Attribute attribute = aPersonName_1_1().buildAsFirstnameWithNoAttributeValues();
    AttributeStatement attributeStatement = aMatchingDatasetAttributeStatement_1_1().withFirstname(attribute).build();
    Assertion matchingDatasetAssertion = anAssertion().addAttributeStatement(attributeStatement).buildUnencrypted();
    validateFail(() -> validator.validate(matchingDatasetAssertion, RESPONSE_ISSUER_ID), emptyAttribute("MDS_firstname"));
}
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)

Example 63 with Attribute

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

the class AttributeQueryAttributeFactoryTest method createAttribute_shouldNotSetFriendlyName.

@Test
public void createAttribute_shouldNotSetFriendlyName() {
    UserAccountCreationAttribute userAccountCreationAttribute = UserAccountCreationAttribute.CURRENT_ADDRESS;
    Attribute attribute = attributeQueryAttributeFactory.createAttribute(userAccountCreationAttribute);
    assertThat(attribute.getFriendlyName()).isNull();
}
Also used : UserAccountCreationAttribute(uk.gov.ida.saml.hub.domain.UserAccountCreationAttribute) UserAccountCreationAttribute(uk.gov.ida.saml.hub.domain.UserAccountCreationAttribute) Attribute(org.opensaml.saml.saml2.core.Attribute) Test(org.junit.jupiter.api.Test)

Example 64 with Attribute

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

the class AuthnRequestFromRelyingPartyUnmarshallerTest method createApplicationVersionExtensions.

private Extensions createApplicationVersionExtensions(String version) throws Exception {
    Extensions extensions = new ExtensionsBuilder().buildObject();
    Attribute versionsAttribute = new AttributeBuilder().buildObject();
    versionsAttribute.setName("Versions");
    versionsAttribute.getAttributeValues().add(createApplicationVersion(version));
    extensions.getUnknownXMLObjects().add(encrypter.encrypt(versionsAttribute));
    return extensions;
}
Also used : AttributeBuilder(org.opensaml.saml.saml2.core.impl.AttributeBuilder) Attribute(org.opensaml.saml.saml2.core.Attribute) ExtensionsBuilder(org.opensaml.saml.saml2.core.impl.ExtensionsBuilder) Extensions(org.opensaml.saml.saml2.core.Extensions)

Example 65 with Attribute

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

the class HubAssertionMarshallerTest method transform_shouldTransformLevelOfCycle3DataAssertion.

@Test
public void transform_shouldTransformLevelOfCycle3DataAssertion() {
    String attributeName = "someName";
    String value = "some value";
    HubAssertion assertion = aHubAssertion().withCycle3Data(aCycle3Dataset().addCycle3Data(attributeName, value).build()).build();
    Attribute expectedAttribute = aSimpleStringAttribute().build();
    when(attributeFactory.createCycle3DataAttribute(attributeName, value)).thenReturn(expectedAttribute);
    Assertion transformedAssertion = marshaller.toSaml(assertion);
    List<AttributeStatement> attributeStatements = transformedAssertion.getAttributeStatements();
    assertThat(attributeStatements.size()).isGreaterThan(0);
    Attribute attribute = attributeStatements.get(0).getAttributes().get(0);
    assertThat(attribute).isEqualTo(expectedAttribute);
}
Also used : SimpleStringAttributeBuilder.aSimpleStringAttribute(uk.gov.ida.saml.core.test.builders.SimpleStringAttributeBuilder.aSimpleStringAttribute) Attribute(org.opensaml.saml.saml2.core.Attribute) AttributeStatement(org.opensaml.saml.saml2.core.AttributeStatement) HubAssertionBuilder.aHubAssertion(uk.gov.ida.saml.core.test.builders.HubAssertionBuilder.aHubAssertion) HubAssertion(uk.gov.ida.saml.core.domain.HubAssertion) Assertion(org.opensaml.saml.saml2.core.Assertion) HubAssertionBuilder.aHubAssertion(uk.gov.ida.saml.core.test.builders.HubAssertionBuilder.aHubAssertion) HubAssertion(uk.gov.ida.saml.core.domain.HubAssertion) 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