use of ee.ria.xroad.common.CodedException in project X-Road by nordic-institute.
the class ServerRestMessageProcessor method handleException.
private void handleException(Exception ex) throws Exception {
log.debug("Request failed", ex);
if (encoder != null) {
CodedException exception;
if (ex instanceof CodedException.Fault) {
exception = (CodedException.Fault) ex;
} else {
exception = translateWithPrefix(SERVER_SERVERPROXY_X, ex);
}
opMonitoringData.setFaultCodeAndString(exception);
monitorAgentNotifyFailure(exception);
encoder.fault(SoapFault.createFaultXml(exception));
encoder.close();
} else {
throw ex;
}
}
use of ee.ria.xroad.common.CodedException in project X-Road by nordic-institute.
the class ServerRestMessageProcessor method verifyClientStatus.
private void verifyClientStatus() {
ClientId client = requestServiceId.getClientId();
String status = ServerConf.getMemberStatus(client);
if (!ClientType.STATUS_REGISTERED.equals(status)) {
throw new CodedException(X_UNKNOWN_MEMBER, "Client '%s' not found", client);
}
}
use of ee.ria.xroad.common.CodedException in project X-Road by nordic-institute.
the class AuthTrustVerifier method verify.
static void verify(HttpContext context, SSLSession sslSession, URI selectedAddress) {
log.debug("verify()");
ServiceId service = (ServiceId) context.getAttribute(ID_PROVIDERNAME);
if (service == null) {
throw new CodedException(X_SSL_AUTH_FAILED, "Could not get provider name from context");
}
X509Certificate[] certs = getPeerCertificates(sslSession);
if (certs.length == 0) {
throw new CodedException(X_SSL_AUTH_FAILED, "Could not get peer certificates from context");
}
try {
verifyAuthCert(service.getClientId(), certs, selectedAddress);
} catch (Exception e) {
throw translateException(e);
}
}
use of ee.ria.xroad.common.CodedException in project X-Road by nordic-institute.
the class ClientRestMessageHandler method sendErrorResponse.
@Override
public void sendErrorResponse(HttpServletRequest request, HttpServletResponse response, CodedException ex) throws IOException {
if (ex.getFaultCode().startsWith("Server.")) {
response.setStatus(HttpStatus.INTERNAL_SERVER_ERROR_500);
} else {
response.setStatus(HttpStatus.BAD_REQUEST_400);
}
response.setCharacterEncoding(MimeUtils.UTF8);
response.setHeader("X-Road-Error", ex.getFaultCode());
final String responseContentType = decideErrorResponseContentType(request.getHeaders("Accept"));
response.setContentType(responseContentType);
if (XML_TYPES.contains(responseContentType)) {
DocumentBuilderFactory docFactory = XmlUtils.createDocumentBuilderFactory();
try {
DocumentBuilder docBuilder = docFactory.newDocumentBuilder();
Document doc = docBuilder.newDocument();
Element errorRootElement = doc.createElement("error");
doc.appendChild(errorRootElement);
Element typeElement = doc.createElement("type");
typeElement.appendChild(doc.createTextNode(ex.getFaultCode()));
errorRootElement.appendChild(typeElement);
Element messageElement = doc.createElement("message");
messageElement.appendChild(doc.createTextNode(ex.getFaultString()));
errorRootElement.appendChild(messageElement);
Element detailElement = doc.createElement("detail");
detailElement.appendChild(doc.createTextNode(ex.getFaultDetail()));
errorRootElement.appendChild(detailElement);
response.getOutputStream().write(XmlUtils.prettyPrintXml(doc, "UTF-8", 0).getBytes());
} catch (Exception e) {
log.error("Unable to generate XML document");
}
} else {
final JsonWriter writer = new JsonWriter(new PrintWriter(response.getOutputStream()));
writer.beginObject().name("type").value(ex.getFaultCode()).name("message").value(ex.getFaultString()).name("detail").value(ex.getFaultDetail()).endObject().close();
}
}
use of ee.ria.xroad.common.CodedException in project X-Road by nordic-institute.
the class ClientRestMessageHandler method verifyCanProcess.
private void verifyCanProcess() {
GlobalConf.verifyValidity();
if (!SystemProperties.isSslEnabled()) {
return;
}
AuthKey authKey = KeyConf.getAuthKey();
if (authKey.getCertChain() == null) {
throw new CodedException(X_SSL_AUTH_FAILED, "Security server has no valid authentication certificate");
}
}
Aggregations