Search in sources :

Example 31 with CodedException

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;
    }
}
Also used : CodedException(ee.ria.xroad.common.CodedException) SoapFault(ee.ria.xroad.common.message.SoapFault)

Example 32 with CodedException

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);
    }
}
Also used : CodedException(ee.ria.xroad.common.CodedException) ClientId(ee.ria.xroad.common.identifier.ClientId)

Example 33 with CodedException

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);
    }
}
Also used : CodedException(ee.ria.xroad.common.CodedException) X509Certificate(java.security.cert.X509Certificate) CodedException(ee.ria.xroad.common.CodedException) SSLPeerUnverifiedException(javax.net.ssl.SSLPeerUnverifiedException) ErrorCodes.translateException(ee.ria.xroad.common.ErrorCodes.translateException) ServiceId(ee.ria.xroad.common.identifier.ServiceId)

Example 34 with CodedException

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();
    }
}
Also used : DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) DocumentBuilder(javax.xml.parsers.DocumentBuilder) Element(org.w3c.dom.Element) Document(org.w3c.dom.Document) JsonWriter(com.google.gson.stream.JsonWriter) IOException(java.io.IOException) CodedException(ee.ria.xroad.common.CodedException) PrintWriter(java.io.PrintWriter)

Example 35 with CodedException

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");
    }
}
Also used : CodedException(ee.ria.xroad.common.CodedException) AuthKey(ee.ria.xroad.common.conf.globalconf.AuthKey)

Aggregations

CodedException (ee.ria.xroad.common.CodedException)131 X509Certificate (java.security.cert.X509Certificate)28 IOException (java.io.IOException)17 ErrorCodes.translateException (ee.ria.xroad.common.ErrorCodes.translateException)15 SignerNotReachableException (org.niis.xroad.restapi.service.SignerNotReachableException)14 TokenInfo (ee.ria.xroad.signer.protocol.dto.TokenInfo)12 OCSPResp (org.bouncycastle.cert.ocsp.OCSPResp)11 ServiceException (org.niis.xroad.restapi.service.ServiceException)11 ClientId (ee.ria.xroad.common.identifier.ClientId)10 ArrayList (java.util.ArrayList)10 Test (org.junit.Test)10 KeyInfo (ee.ria.xroad.signer.protocol.dto.KeyInfo)8 InputStream (java.io.InputStream)8 URISyntaxException (java.net.URISyntaxException)7 Date (java.util.Date)7 SoapFault (ee.ria.xroad.common.message.SoapFault)6 ServiceId (ee.ria.xroad.common.identifier.ServiceId)5 Soap (ee.ria.xroad.common.message.Soap)5 SoapMessageImpl (ee.ria.xroad.common.message.SoapMessageImpl)5 ByteArrayInputStream (java.io.ByteArrayInputStream)5