Search in sources :

Example 21 with SamlTransformationErrorException

use of uk.gov.ida.saml.core.validation.SamlTransformationErrorException in project verify-hub by alphagov.

the class SamlMessageReceiverApi method handleEidasResponsePost.

@POST
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@Path(Urls.SamlProxyUrls.EIDAS_RESPONSE_POST_PATH)
@Timed
public Response handleEidasResponsePost(SamlRequestDto samlRequestDto) {
    if (eidasAuthnResponseSignatureValidator.isPresent()) {
        final SessionId sessionId = new SessionId(samlRequestDto.getRelayState());
        MDC.put("SessionId", sessionId);
        relayStateValidator.validate(samlRequestDto.getRelayState());
        org.opensaml.saml.saml2.core.Response samlResponse = stringSamlResponseTransformer.apply(samlRequestDto.getSamlRequest());
        SamlValidationResponse signatureValidationResponse = eidasAuthnResponseSignatureValidator.get().validate(samlResponse, IDPSSODescriptor.DEFAULT_ELEMENT_NAME);
        protectiveMonitoringLogger.logAuthnResponse(samlResponse, Direction.INBOUND, signatureValidationResponse.isOK());
        if (!signatureValidationResponse.isOK()) {
            SamlValidationSpecificationFailure failure = signatureValidationResponse.getSamlValidationSpecificationFailure();
            throw new SamlTransformationErrorException(failure.getErrorMessage(), signatureValidationResponse.getCause(), Level.ERROR);
        }
        final SamlAuthnResponseContainerDto authnResponseDto = new SamlAuthnResponseContainerDto(samlRequestDto.getSamlRequest(), sessionId, samlRequestDto.getPrincipalIpAsSeenByFrontend());
        return Response.ok(sessionProxy.receiveAuthnResponseFromCountry(authnResponseDto, sessionId)).build();
    }
    return Response.status(Response.Status.NOT_FOUND).build();
}
Also used : SamlValidationResponse(uk.gov.ida.saml.core.validation.SamlValidationResponse) SamlValidationSpecificationFailure(uk.gov.ida.saml.core.validation.SamlValidationSpecificationFailure) SamlTransformationErrorException(uk.gov.ida.saml.core.validation.SamlTransformationErrorException) SamlAuthnResponseContainerDto(uk.gov.ida.hub.samlproxy.domain.SamlAuthnResponseContainerDto) SessionId(uk.gov.ida.common.SessionId) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) Timed(com.codahale.metrics.annotation.Timed)

Example 22 with SamlTransformationErrorException

use of uk.gov.ida.saml.core.validation.SamlTransformationErrorException in project verify-hub by alphagov.

the class MatchingServiceHealthChecker method validateRequestSignature.

private void validateRequestSignature(Element matchingServiceRequest) {
    AttributeQuery attributeQuery = elementToAttributeQueryTransformer.apply(matchingServiceRequest);
    SamlValidationResponse signatureValidationResponse = matchingRequestSignatureValidator.validate(attributeQuery, AttributeAuthorityDescriptor.DEFAULT_ELEMENT_NAME);
    if (!signatureValidationResponse.isOK()) {
        SamlValidationSpecificationFailure failure = signatureValidationResponse.getSamlValidationSpecificationFailure();
        throw new SamlTransformationErrorException(failure.getErrorMessage(), signatureValidationResponse.getCause(), Level.ERROR);
    }
}
Also used : SamlValidationResponse(uk.gov.ida.saml.core.validation.SamlValidationResponse) SamlValidationSpecificationFailure(uk.gov.ida.saml.core.validation.SamlValidationSpecificationFailure) AttributeQuery(org.opensaml.saml.saml2.core.AttributeQuery) SamlTransformationErrorException(uk.gov.ida.saml.core.validation.SamlTransformationErrorException)

Aggregations

SamlTransformationErrorException (uk.gov.ida.saml.core.validation.SamlTransformationErrorException)22 SamlValidationSpecificationFailure (uk.gov.ida.saml.core.validation.SamlValidationSpecificationFailure)10 Test (org.junit.Test)9 Response (javax.ws.rs.core.Response)8 SamlValidationResponse (uk.gov.ida.saml.core.validation.SamlValidationResponse)8 ErrorStatusDto (uk.gov.ida.common.ErrorStatusDto)7 Timed (com.codahale.metrics.annotation.Timed)3 Consumes (javax.ws.rs.Consumes)3 POST (javax.ws.rs.POST)3 Produces (javax.ws.rs.Produces)3 SessionId (uk.gov.ida.common.SessionId)3 Path (javax.ws.rs.Path)2 AttributeQuery (org.opensaml.saml.saml2.core.AttributeQuery)2 AuthnRequest (org.opensaml.saml.saml2.core.AuthnRequest)2 Response (org.opensaml.saml.saml2.core.Response)2 SamlAuthnResponseContainerDto (uk.gov.ida.hub.samlproxy.domain.SamlAuthnResponseContainerDto)2 SamlDuplicateRequestIdException (uk.gov.ida.saml.hub.exception.SamlDuplicateRequestIdException)2 SamlRequestTooOldException (uk.gov.ida.saml.hub.exception.SamlRequestTooOldException)2 SamlFailedToDecryptException (uk.gov.ida.saml.security.exception.SamlFailedToDecryptException)2 IOException (java.io.IOException)1