Search in sources :

Example 6 with SamlValidationException

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

the class ResponseAssertionsFromIdpValidator method validate.

public void validate(ValidatedResponse validatedResponse, ValidatedAssertions validatedAssertions) {
    validatedAssertions.getAssertions().forEach(assertion -> identityProviderAssertionValidator.validate(assertion, validatedResponse.getInResponseTo(), hubEntityId));
    if (!validatedResponse.isSuccess())
        return;
    Assertion matchingDatasetAssertion = getMatchingDatasetAssertion(validatedAssertions);
    Assertion authnStatementAssertion = getAuthnStatementAssertion(validatedAssertions);
    if (authnStatementAssertion.getAuthnStatements().size() > 1) {
        throw new SamlValidationException(multipleAuthnStatements());
    }
    matchingDatasetAssertionValidator.validate(matchingDatasetAssertion, validatedResponse.getIssuer().getValue());
    authnStatementAssertionValidator.validate(authnStatementAssertion);
    identityProviderAssertionValidator.validateConsistency(authnStatementAssertion, matchingDatasetAssertion);
    ipAddressValidator.validate(authnStatementAssertion);
}
Also used : SamlValidationException(uk.gov.ida.saml.hub.exception.SamlValidationException) Assertion(org.opensaml.saml.saml2.core.Assertion)

Example 7 with SamlValidationException

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

the class DestinationValidator method validate.

/*
    Validate that the destination sent to us matches the configured host & the given path

    Path is added because we have to do validation on both Responses & Requests
     */
public void validate(String destination) {
    if (destination == null)
        throw new SamlValidationException(destinationMissing(expectedUri));
    URI destinationURI = URI.create(destination);
    URI destinationURIWithoutPort;
    destinationURIWithoutPort = uriWithoutPort(destinationURI, destinationURI.getPath());
    if (!expectedUri.equals(destinationURIWithoutPort))
        throw new SamlValidationException(destinationEmpty(expectedUri, destination));
}
Also used : SamlValidationException(uk.gov.ida.saml.hub.exception.SamlValidationException) URI(java.net.URI)

Example 8 with SamlValidationException

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

the class EncryptedResponseFromIdpValidator method validateResponse.

private void validateResponse(Response response) {
    if (Strings.isNullOrEmpty(response.getID()))
        throw new SamlValidationException(missingId());
    if (response.getIssueInstant() == null)
        throw new SamlValidationException(missingIssueInstant(response.getID()));
    Signature signature = response.getSignature();
    if (signature == null)
        throw new SamlValidationException(missingSignature());
    if (!isSignaturePresent(signature))
        throw new SamlValidationException(signatureNotSigned());
    validateStatus(response.getStatus());
    validateAssertionPresence(response);
}
Also used : SamlValidationException(uk.gov.ida.saml.hub.exception.SamlValidationException) Signature(org.opensaml.xmlsec.signature.Signature) SamlTransformationErrorFactory.missingSignature(uk.gov.ida.saml.core.errors.SamlTransformationErrorFactory.missingSignature)

Example 9 with SamlValidationException

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

the class EncryptedResponseFromIdpValidator method fail.

private void fail(Status status) {
    StatusCode statusCode = status.getStatusCode();
    StatusCode subStatusCode = statusCode.getStatusCode();
    if (subStatusCode == null)
        throw new SamlValidationException(invalidStatusCode(statusCode.getValue()));
    SamlValidationSpecificationFailure failure = invalidSubStatusCode(subStatusCode.getValue(), statusCode.getValue());
    throw new SamlValidationException(failure);
}
Also used : SamlValidationSpecificationFailure(uk.gov.ida.saml.core.validation.SamlValidationSpecificationFailure) SamlValidationException(uk.gov.ida.saml.hub.exception.SamlValidationException) SamlTransformationErrorFactory.invalidSubStatusCode(uk.gov.ida.saml.core.errors.SamlTransformationErrorFactory.invalidSubStatusCode) SamlTransformationErrorFactory.invalidStatusCode(uk.gov.ida.saml.core.errors.SamlTransformationErrorFactory.invalidStatusCode) StatusCode(org.opensaml.saml.saml2.core.StatusCode)

Example 10 with SamlValidationException

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

the class EncryptedResponseFromMatchingServiceValidator method validateResponse.

private void validateResponse(Response response) {
    if (Strings.isNullOrEmpty(response.getID()))
        throw new SamlValidationException(missingId());
    Signature signature = response.getSignature();
    if (signature == null)
        throw new SamlValidationException(missingSignature());
    if (!isSignaturePresent(signature))
        throw new SamlValidationException(signatureNotSigned());
    validateStatusAndSubStatus(response);
    validateAssertionPresence(response);
}
Also used : SamlValidationException(uk.gov.ida.saml.hub.exception.SamlValidationException) Signature(org.opensaml.xmlsec.signature.Signature) SamlTransformationErrorFactory.missingSignature(uk.gov.ida.saml.core.errors.SamlTransformationErrorFactory.missingSignature)

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