Search in sources :

Example 1 with SamlValidationException

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

the class EncryptedResponseFromIdpValidator method validateAssertionPresence.

protected void validateAssertionPresence(Response response) {
    if (!response.getAssertions().isEmpty())
        throw new SamlValidationException(unencryptedAssertion());
    boolean responseWasSuccessful = response.getStatus().getStatusCode().getValue().equals(StatusCode.SUCCESS);
    List<EncryptedAssertion> encryptedAssertions = response.getEncryptedAssertions();
    if (responseWasSuccessful && encryptedAssertions.isEmpty()) {
        throw new SamlValidationException(missingSuccessUnEncryptedAssertions());
    }
    if (!responseWasSuccessful && !encryptedAssertions.isEmpty()) {
        throw new SamlValidationException(nonSuccessHasUnEncryptedAssertions());
    }
    if (responseWasSuccessful && encryptedAssertions.size() != 2) {
        throw new SamlValidationException(unexpectedNumberOfAssertions(2, encryptedAssertions.size()));
    }
}
Also used : SamlValidationException(uk.gov.ida.saml.hub.exception.SamlValidationException) EncryptedAssertion(org.opensaml.saml.saml2.core.EncryptedAssertion)

Example 2 with SamlValidationException

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

the class EncryptedResponseFromMatchingServiceValidator method validateAssertionPresence.

protected void validateAssertionPresence(Response response) {
    if (!response.getAssertions().isEmpty())
        throw new SamlValidationException(unencryptedAssertion());
    boolean responseWasSuccessful = StatusCode.SUCCESS.equals(response.getStatus().getStatusCode().getValue());
    boolean responseHasNoAssertions = response.getEncryptedAssertions().isEmpty();
    if (responseWasSuccessful && responseHasNoAssertions)
        throw new SamlValidationException(missingSuccessUnEncryptedAssertions());
    if (!responseWasSuccessful && !responseHasNoAssertions) {
        throw new SamlValidationException(nonSuccessHasUnEncryptedAssertions());
    }
    if (response.getEncryptedAssertions().size() > 1) {
        throw new SamlValidationException(unexpectedNumberOfAssertions(1, response.getEncryptedAssertions().size()));
    }
}
Also used : SamlValidationException(uk.gov.ida.saml.hub.exception.SamlValidationException)

Example 3 with SamlValidationException

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

the class IssuerValidator method validate.

public static void validate(Response response) {
    Issuer issuer = response.getIssuer();
    if (issuer == null)
        throw new SamlValidationException(missingIssuer());
    String issuerId = issuer.getValue();
    if (Strings.isNullOrEmpty(issuerId))
        throw new SamlValidationException(emptyIssuer());
    String issuerFormat = issuer.getFormat();
    if (issuerFormat != null && !NameIDType.ENTITY.equals(issuerFormat))
        throw new SamlValidationException(illegalIssuerFormat(issuerFormat, NameIDType.ENTITY));
}
Also used : SamlValidationException(uk.gov.ida.saml.hub.exception.SamlValidationException) SamlTransformationErrorFactory.missingIssuer(uk.gov.ida.saml.core.errors.SamlTransformationErrorFactory.missingIssuer) SamlTransformationErrorFactory.emptyIssuer(uk.gov.ida.saml.core.errors.SamlTransformationErrorFactory.emptyIssuer) Issuer(org.opensaml.saml.saml2.core.Issuer)

Example 4 with SamlValidationException

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

the class HealthCheckResponseFromMatchingServiceValidator 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);
}
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 5 with SamlValidationException

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

the class HealthCheckResponseFromMatchingServiceValidator method validateStatusAndSubStatus.

protected void validateStatusAndSubStatus(Response response) {
    StatusCode statusCode = response.getStatus().getStatusCode();
    if (StatusCode.REQUESTER.equals(statusCode.getValue()))
        return;
    if (statusCode.getStatusCode() == null)
        throw new SamlValidationException(missingSubStatus());
    String statusCodeValue = statusCode.getValue();
    if (!StatusCode.SUCCESS.equals(statusCodeValue))
        throw new SamlValidationException(invalidStatusCode(statusCodeValue));
    String subStatusCodeValue = statusCode.getStatusCode().getValue();
    if (!SamlStatusCode.HEALTHY.equals(subStatusCodeValue)) {
        throw new SamlValidationException(invalidSubStatusCode(subStatusCodeValue, StatusCode.SUCCESS));
    }
}
Also used : SamlValidationException(uk.gov.ida.saml.hub.exception.SamlValidationException) SamlStatusCode(uk.gov.ida.saml.core.domain.SamlStatusCode) 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)

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