use of org.opensaml.saml.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);
}
use of org.opensaml.saml.saml2.core.Attribute in project verify-hub by alphagov.
the class MatchingServiceAssertionToAssertionTransformer method addAttributes.
private void addAttributes(final Assertion transformedAssertion, final List<Attribute> userAttributesForAccountCreation) {
AttributeStatementBuilder attributeStatementBuilder = (AttributeStatementBuilder) builderFactory.getBuilder(AttributeStatement.DEFAULT_ELEMENT_NAME);
AttributeStatement attributeStatement = attributeStatementBuilder.buildObject();
attributeStatement.getAttributes().addAll(userAttributesForAccountCreation);
transformedAssertion.getAttributeStatements().add(attributeStatement);
}
use of org.opensaml.saml.saml2.core.Attribute in project verify-hub by alphagov.
the class AttributeQueryAttributeFactory method createAttribute.
public Attribute createAttribute(final UserAccountCreationAttribute userAccountCreationAttribute) {
final Attribute attribute = openSamlXmlObjectFactory.createAttribute();
attribute.setName(userAccountCreationAttribute.getAttributeName());
attribute.setNameFormat(Attribute.UNSPECIFIED);
return attribute;
}
use of org.opensaml.saml.saml2.core.Attribute in project verify-hub by alphagov.
the class MatchingDatasetAssertionValidator method validateAttributes.
private void validateAttributes(Assertion assertion) {
final List<AttributeStatement> attributeStatements = assertion.getAttributeStatements();
if (attributeStatements.isEmpty())
throw new SamlValidationException(mdsStatementMissing());
if (attributeStatements.size() > 1)
throw new SamlValidationException(mdsMultipleStatements());
final List<Attribute> attributes = attributeStatements.get(0).getAttributes();
if (attributes.isEmpty())
throw new SamlValidationException(attributeStatementEmpty(assertion.getID()));
attributes.forEach(this::validateAttribute);
}
use of org.opensaml.saml.saml2.core.Attribute in project verify-hub by alphagov.
the class IPAddressValidator method validate.
public void validate(Assertion assertion) {
for (AttributeStatement attributeStatement : assertion.getAttributeStatements()) {
for (Attribute attribute : attributeStatement.getAttributes()) {
if (attribute.getName().equals(IdaConstants.Attributes_1_1.IPAddress.NAME)) {
IPAddress ipAddressAttributeValue = (IPAddress) attribute.getAttributeValues().get(0);
String addressValue = ipAddressAttributeValue.getValue();
if (!Strings.isNullOrEmpty(addressValue)) {
return;
}
SamlValidationSpecificationFailure failure = SamlTransformationErrorFactory.emptyIPAddress(assertion.getID());
throw new SamlTransformationErrorException(failure.getErrorMessage(), failure.getLogLevel());
}
}
}
SamlValidationSpecificationFailure failure = SamlTransformationErrorFactory.missingIPAddress(assertion.getID());
throw new SamlTransformationErrorException(failure.getErrorMessage(), failure.getLogLevel());
}
Aggregations