use of uk.gov.ida.saml.core.validation.SamlTransformationErrorException in project verify-hub by alphagov.
the class ResponseAssertionsFromCountryValidator method validate.
public void validate(ValidatedResponse validatedResponse, Assertion validatedIdentityAssertion) {
assertionValidator.validate(validatedIdentityAssertion, validatedResponse.getInResponseTo(), expectedRecipientId);
if (validatedResponse.isSuccess()) {
if (validatedIdentityAssertion.getAuthnStatements().size() > 1) {
SamlValidationSpecificationFailure failure = SamlTransformationErrorFactory.multipleAuthnStatements();
throw new SamlTransformationErrorException(failure.getErrorMessage(), failure.getLogLevel());
}
authnStatementAssertionValidator.validate(validatedIdentityAssertion);
eidasAttributeStatementAssertionValidator.validate(validatedIdentityAssertion);
authnResponseIssuerValidator.validate(validatedResponse, validatedIdentityAssertion);
}
}
use of uk.gov.ida.saml.core.validation.SamlTransformationErrorException in project verify-hub by alphagov.
the class ExecuteAttributeQueryRequest method convertToElementAndValidate.
private Element convertToElementAndValidate(AttributeQueryContainerDto attributeQueryContainerDto) {
try {
Element matchingServiceRequest;
matchingServiceRequest = XmlUtils.convertToElement(attributeQueryContainerDto.getSamlRequest());
validateRequestSignature(matchingServiceRequest, attributeQueryContainerDto.getMatchingServiceUri());
return matchingServiceRequest;
} catch (ParserConfigurationException | SAXException | IOException e) {
throw new InvalidSamlRequestInAttributeQueryException("Attribute Query had invalid XML.", e);
} catch (SamlTransformationErrorException e) {
throw new InvalidSamlRequestInAttributeQueryException("Attribute Query had invalid Saml", e);
}
}
use of uk.gov.ida.saml.core.validation.SamlTransformationErrorException in project verify-hub by alphagov.
the class ExecuteAttributeQueryRequest method validateRequestSignature.
private void validateRequestSignature(Element matchingServiceRequest, URI matchingServiceUri) {
AttributeQuery attributeQuery = elementToAttributeQueryTransformer.apply(matchingServiceRequest);
SamlValidationResponse signatureValidationResponse = matchingRequestSignatureValidator.validate(attributeQuery, SPSSODescriptor.DEFAULT_ELEMENT_NAME);
protectiveMonitoringLogger.logAttributeQuery(attributeQuery.getID(), matchingServiceUri.toASCIIString(), attributeQuery.getIssuer().getValue(), signatureValidationResponse.isOK());
if (!signatureValidationResponse.isOK()) {
SamlValidationSpecificationFailure failure = signatureValidationResponse.getSamlValidationSpecificationFailure();
throw new SamlTransformationErrorException(failure.getErrorMessage(), signatureValidationResponse.getCause(), Level.ERROR);
}
}
use of uk.gov.ida.saml.core.validation.SamlTransformationErrorException in project verify-hub by alphagov.
the class ExecuteAttributeQueryRequest method validateResponseSignature.
private void validateResponseSignature(Element responseFromMatchingService) {
Response response = elementToSamlResponseTransformer.apply(responseFromMatchingService);
SamlValidationResponse signatureValidationResponse = matchingResponseSignatureValidator.validate(response, AttributeAuthorityDescriptor.DEFAULT_ELEMENT_NAME);
String message = hasStatusMessage(response.getStatus()) ? response.getStatus().getStatusMessage().getMessage() : "";
protectiveMonitoringLogger.logAttributeQueryResponse(response.getID(), response.getInResponseTo(), response.getIssuer().getValue(), signatureValidationResponse.isOK(), response.getStatus().getStatusCode().getValue(), message);
if (!signatureValidationResponse.isOK()) {
SamlValidationSpecificationFailure failure = signatureValidationResponse.getSamlValidationSpecificationFailure();
throw new SamlTransformationErrorException(failure.getErrorMessage(), signatureValidationResponse.getCause(), Level.ERROR);
}
}
use of uk.gov.ida.saml.core.validation.SamlTransformationErrorException in project verify-hub by alphagov.
the class SamlEngineExceptionMapperTest method shouldCreateUnauditedErrorResponse.
@Test
public void shouldCreateUnauditedErrorResponse() throws Exception {
final SamlTransformationErrorException exception = new SamlTransformationErrorException("error", new RuntimeException(), Level.DEBUG);
Response response = samlEngineExceptionMapper.toResponse(exception);
ErrorStatusDto responseEntity = (ErrorStatusDto) response.getEntity();
assertThat(response.getStatus()).isEqualTo(Response.Status.BAD_REQUEST.getStatusCode());
assertThat(responseEntity.isAudited()).isFalse();
checkLogLevel(exception.getLogLevel());
}
Aggregations