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()));
}
}
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()));
}
}
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));
}
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);
}
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));
}
}
Aggregations