public void processIDPResponse(HttpServletRequest httpRequest, HttpServletResponse httpResponse, StatusResponseType statusResponse) throws InvalidRequestException {
SamlExternalIdentityProvider idp = (SamlExternalIdentityProvider) samlDialogue.getExternalProvider();
StatusType status = statusResponse.getStatus();
if (status == null) {
throw new InvalidRequestException("Response does not contain a status");
}
String statusValue = status.getStatusCode().getValue();
if (!SamlConstants.STATUS_SUCCESS.equals(statusValue)) {
String statusCodeLevel1 = statusValue;
String statusCodeLevel2 = null;
if (status.getStatusCode().getStatusCode() != null) {
statusCodeLevel2 = status.getStatusCode().getStatusCode().getValue();
}
samlServiceProviderSpi.get().loginFailed(statusCodeLevel1, statusCodeLevel2, responseHandler.createResponseHolder(httpResponse));
}
if (!(statusResponse instanceof ResponseType)) {
throw new InvalidRequestException("Response does not have type ResponseType");
}
ResponseType response = (ResponseType) statusResponse;
List<Object> assertions = response.getAssertionOrEncryptedAssertion();
if (assertions.size() == 0) {
throw new RuntimeException("IDP response does not contain assertions");
}
SamlSpSessionImpl session = createSession(response, idp);
if (session == null) {
throw new InvalidRequestException("Not possible to login based on the supplied assertions");
} else {
session.setIdentityProvider(idp);
loginUser(httpRequest, httpResponse, session, statusResponse.getInResponseTo() == null, httpRequest.getParameter(SamlRedirectMessage.QSP_RELAY_STATE));
}