Search in sources :

Example 71 with Attribute

use of org.opensaml.saml.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)

Example 72 with Attribute

use of org.opensaml.saml.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 73 with Attribute

use of org.opensaml.saml.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 74 with Attribute

use of org.opensaml.saml.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 75 with Attribute

use of org.opensaml.saml.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)

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