Search in sources :

Example 26 with Attribute

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

the class MatchingDatasetAssertionValidatorTest method validate_shouldThrowExceptionWhenAttributeValueIsIncorrectType.

@Test
public void validate_shouldThrowExceptionWhenAttributeValueIsIncorrectType() {
    Attribute attribute = aSimpleStringAttribute().withName(IdaConstants.Attributes_1_1.Firstname.NAME).withSimpleStringValue("Joe").build();
    AttributeStatement attributeStatement = aMatchingDatasetAttributeStatement_1_1().withFirstname(attribute).build();
    Assertion matchingDatasetAssertion = anAssertion().addAttributeStatement(attributeStatement).buildUnencrypted();
    validateFail(() -> validator.validate(matchingDatasetAssertion, RESPONSE_ISSUER_ID), attributeWithIncorrectType(IdaConstants.Attributes_1_1.Firstname.NAME, PersonName.TYPE_NAME, StringBasedMdsAttributeValue.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 27 with Attribute

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

the class MatchingDatasetAssertionValidatorTest method validate_shouldNotThrowExceptionWhenAttributeValueVerifiedIsAbsent.

@Test
public void validate_shouldNotThrowExceptionWhenAttributeValueVerifiedIsAbsent() {
    Attribute attribute = aPersonName_1_1().addValue(aPersonNameValue().withVerified(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 28 with Attribute

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

the class MatchingDatasetAssertionValidatorTest method validate_shouldNotThrowExceptionWhenAttributeValueToDateIsAbsent.

@Test
public void validate_shouldNotThrowExceptionWhenAttributeValueToDateIsAbsent() {
    Attribute attribute = aPersonName_1_1().addValue(aPersonNameValue().withTo(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 29 with Attribute

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

the class AttributeQueryAttributeFactoryTest method createAttribute_shouldPopulateAttributeNameFromUserAccountCreationAttributeValue.

@Test
public void createAttribute_shouldPopulateAttributeNameFromUserAccountCreationAttributeValue() {
    UserAccountCreationAttribute userAccountCreationAttribute = UserAccountCreationAttribute.CURRENT_ADDRESS;
    Attribute attribute = attributeQueryAttributeFactory.createAttribute(userAccountCreationAttribute);
    assertThat(attribute.getName()).isEqualTo("currentaddress");
}
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 30 with Attribute

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

the class AttributeQueryAttributeFactoryTest method createAttribute_shouldPopulateAttributeNameFormatWithUnspecifiedFormat.

@Test
public void createAttribute_shouldPopulateAttributeNameFormatWithUnspecifiedFormat() {
    UserAccountCreationAttribute userAccountCreationAttribute = UserAccountCreationAttribute.CURRENT_ADDRESS;
    Attribute attribute = attributeQueryAttributeFactory.createAttribute(userAccountCreationAttribute);
    assertThat(attribute.getNameFormat()).isEqualTo("urn:oasis:names:tc:SAML:2.0:attrname-format:unspecified");
}
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)

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