Search in sources :

Example 11 with SamlValidationException

use of uk.gov.ida.saml.hub.exception.SamlValidationException in project verify-hub by alphagov.

the class EncryptedResponseFromMatchingServiceValidator method validateStatusAndSubStatus.

protected void validateStatusAndSubStatus(Response response) {
    StatusCode statusCode = response.getStatus().getStatusCode();
    String statusCodeValue = statusCode.getValue();
    StatusCode subStatusCode = statusCode.getStatusCode();
    if (StatusCode.REQUESTER.equals(statusCodeValue))
        return;
    if (subStatusCode == null)
        throw new SamlValidationException(missingSubStatus());
    String subStatusCodeValue = subStatusCode.getValue();
    if (!StatusCode.RESPONDER.equals(statusCodeValue)) {
        validateSuccessResponse(statusCodeValue, subStatusCodeValue);
    } else {
        validateResponderError(subStatusCodeValue);
    }
}
Also used : SamlValidationException(uk.gov.ida.saml.hub.exception.SamlValidationException) SamlStatusCode(uk.gov.ida.saml.core.domain.SamlStatusCode) StatusCode(org.opensaml.saml.saml2.core.StatusCode)

Example 12 with SamlValidationException

use of uk.gov.ida.saml.hub.exception.SamlValidationException in project verify-hub by alphagov.

the class MatchingDatasetAssertionValidator method validateAttribute.

private void validateAttribute(Attribute attribute) {
    String attributeName = attribute.getName();
    if (!VALID_ATTRIBUTE_NAMES_1_1.contains(attributeName))
        throw new SamlValidationException(mdsAttributeNotRecognised(attributeName));
    List<XMLObject> attributeValues = attribute.getAttributeValues();
    if (attributeValues.isEmpty())
        throw new SamlValidationException(emptyAttribute(attributeName));
    QName schemaType = attributeValues.get(0).getSchemaType();
    if (!VALID_TYPE_FOR_ATTRIBUTE.get(attributeName).equals(schemaType))
        throw new SamlValidationException(attributeWithIncorrectType(attributeName, VALID_TYPE_FOR_ATTRIBUTE.get(attributeName), schemaType));
    if (!VALID_ATTRIBUTE_NAME_FORMATS.contains(attribute.getNameFormat()))
        warn(invalidAttributeNameFormat(attribute.getNameFormat()));
}
Also used : SamlValidationException(uk.gov.ida.saml.hub.exception.SamlValidationException) QName(javax.xml.namespace.QName) XMLObject(org.opensaml.core.xml.XMLObject)

Example 13 with SamlValidationException

use of uk.gov.ida.saml.hub.exception.SamlValidationException 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);
}
Also used : SamlValidationException(uk.gov.ida.saml.hub.exception.SamlValidationException) SamlTransformationErrorFactory.emptyAttribute(uk.gov.ida.saml.core.errors.SamlTransformationErrorFactory.emptyAttribute) Attribute(org.opensaml.saml.saml2.core.Attribute) AttributeStatement(org.opensaml.saml.saml2.core.AttributeStatement)

Aggregations

SamlValidationException (uk.gov.ida.saml.hub.exception.SamlValidationException)13 StatusCode (org.opensaml.saml.saml2.core.StatusCode)3 Signature (org.opensaml.xmlsec.signature.Signature)3 SamlTransformationErrorFactory.missingSignature (uk.gov.ida.saml.core.errors.SamlTransformationErrorFactory.missingSignature)3 SamlStatusCode (uk.gov.ida.saml.core.domain.SamlStatusCode)2 SamlTransformationErrorFactory.invalidStatusCode (uk.gov.ida.saml.core.errors.SamlTransformationErrorFactory.invalidStatusCode)2 SamlTransformationErrorFactory.invalidSubStatusCode (uk.gov.ida.saml.core.errors.SamlTransformationErrorFactory.invalidSubStatusCode)2 URI (java.net.URI)1 QName (javax.xml.namespace.QName)1 XMLObject (org.opensaml.core.xml.XMLObject)1 Assertion (org.opensaml.saml.saml2.core.Assertion)1 Attribute (org.opensaml.saml.saml2.core.Attribute)1 AttributeStatement (org.opensaml.saml.saml2.core.AttributeStatement)1 EncryptedAssertion (org.opensaml.saml.saml2.core.EncryptedAssertion)1 Issuer (org.opensaml.saml.saml2.core.Issuer)1 SamlTransformationErrorFactory.emptyAttribute (uk.gov.ida.saml.core.errors.SamlTransformationErrorFactory.emptyAttribute)1 SamlTransformationErrorFactory.emptyIssuer (uk.gov.ida.saml.core.errors.SamlTransformationErrorFactory.emptyIssuer)1 SamlTransformationErrorFactory.missingIssuer (uk.gov.ida.saml.core.errors.SamlTransformationErrorFactory.missingIssuer)1 SamlValidationSpecificationFailure (uk.gov.ida.saml.core.validation.SamlValidationSpecificationFailure)1