Search in sources :

Example 6 with AdapterException

use of com.mercedesbenz.sechub.adapter.AdapterException in project sechub by mercedes-benz.

the class NessusAdapterV1 method resolvePolicyUIDByTitle.

String resolvePolicyUIDByTitle(String content, String searchedPolicyTitle, NessusAdapterContext context) throws AdapterException {
    try {
        ArrayNode templatesArray = context.json().fetch("templates", content).asArray();
        for (Iterator<JsonNode> elements = templatesArray.elements(); elements.hasNext(); ) {
            JsonNode node = elements.next();
            String title = context.json().fetch("title", node).asText();
            if (searchedPolicyTitle.equals(title)) {
                return context.json().fetch("uuid", node).asText();
            }
        }
        return null;
    } catch (Exception e) {
        // JSON errors are marked as adapter exceptions and all others too...
        throw asAdapterException("Was not able to resolve policy uid", e, context);
    }
}
Also used : JsonNode(com.fasterxml.jackson.databind.JsonNode) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) AdapterException(com.mercedesbenz.sechub.adapter.AdapterException) HttpClientErrorException(org.springframework.web.client.HttpClientErrorException)

Example 7 with AdapterException

use of com.mercedesbenz.sechub.adapter.AdapterException in project sechub by mercedes-benz.

the class CheckmarxAdapterV1 method execute.

@Override
public String execute(CheckmarxAdapterConfig config, AdapterRuntimeContext runtimeContext) throws AdapterException {
    try {
        assertNotInterrupted();
        CheckmarxContext context = new CheckmarxContext(config, this, runtimeContext);
        context.setFullScan(context.isNewProject() || config.isAlwaysFullScanEnabled());
        CheckmarxOAuthSupport oauthSupport = new CheckmarxOAuthSupport();
        oauthSupport.loginAndGetOAuthToken(context);
        assertNotInterrupted();
        /* ensure project and get project context */
        CheckmarxProjectSupport projectSupport = new CheckmarxProjectSupport();
        projectSupport.ensureProjectExists(context);
        assertNotInterrupted();
        handleUploadSourceCodeAndStartScan(oauthSupport, context);
        assertNotInterrupted();
        CheckmarxScanReportSupport scanReportSupport = new CheckmarxScanReportSupport();
        scanReportSupport.startFetchReport(oauthSupport, context);
        return context.getResult();
    } catch (Exception e) {
        throw asAdapterException("Was not able to perform scan!", e, config);
    }
}
Also used : CheckmarxOAuthSupport(com.mercedesbenz.sechub.adapter.checkmarx.support.CheckmarxOAuthSupport) CheckmarxProjectSupport(com.mercedesbenz.sechub.adapter.checkmarx.support.CheckmarxProjectSupport) CheckmarxScanReportSupport(com.mercedesbenz.sechub.adapter.checkmarx.support.CheckmarxScanReportSupport) AdapterException(com.mercedesbenz.sechub.adapter.AdapterException) CheckmarxFullScanNecessaryException(com.mercedesbenz.sechub.adapter.checkmarx.support.CheckmarxFullScanNecessaryException)

Example 8 with AdapterException

use of com.mercedesbenz.sechub.adapter.AdapterException in project sechub by mercedes-benz.

the class AssertProject method hasWhiteListEntries.

public AssertProject hasWhiteListEntries(String... expectedArray) {
    String content = fetchProjectDetails();
    List<String> found = new ArrayList<>();
    ArrayNode whiteListArray;
    try {
        whiteListArray = JSONAdapterSupport.FOR_UNKNOWN_ADAPTER.fetch("whiteList", content).asArray();
        for (JsonNode node : whiteListArray) {
            found.add(node.asText());
        }
    } catch (AdapterException e) {
        e.printStackTrace();
        fail("adapter json failure:" + e.getMessage());
    }
    assertArrayEquals(expectedArray, found.toArray(new String[found.size()]));
    return this;
}
Also used : ArrayList(java.util.ArrayList) JsonNode(com.fasterxml.jackson.databind.JsonNode) AdapterException(com.mercedesbenz.sechub.adapter.AdapterException) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode)

Example 9 with AdapterException

use of com.mercedesbenz.sechub.adapter.AdapterException in project sechub by mercedes-benz.

the class TrustAllSupport method createTrustAllFactory.

public ClientHttpRequestFactory createTrustAllFactory() {
    HttpClientBuilder clientBuilder = HttpClients.custom();
    SSLContext sslContext = null;
    if (config.isTrustAllCertificatesEnabled()) {
        try {
            sslContext = createTrustAllSSLContext(adapter);
        } catch (AdapterException e) {
            throw new IllegalStateException("Should not happen! See trace", e);
        }
    } else {
        sslContext = SSLContexts.createSystemDefault();
    }
    if (config.isProxyDefined()) {
        // proxy with socks not working with standard HTTPHost,
        // clientBuilder.setProxy(..)
        // So own approach necessary, details see
        // https://stackoverflow.com/questions/22937983/how-to-use-socks-5-proxy-with-apache-http-client-4
        Registry<ConnectionSocketFactory> reg = RegistryBuilder.<ConnectionSocketFactory>create().register("http", new SocksProxyConnectionSocketFactory()).register("https", new SocksProxySSLConnectionSocketFactory(sslContext)).build();
        PoolingHttpClientConnectionManager cm = new PoolingHttpClientConnectionManager(reg, new FakeDnsResolver());
        clientBuilder.setConnectionManager(cm);
    } else {
        clientBuilder.setSSLContext(sslContext);
        clientBuilder.setSSLHostnameVerifier(new HostnameVerifier() {

            public boolean verify(String hostname, SSLSession session) {
                return /* NOSONAR - we know what we do here! */
                true;
            }
        });
    }
    CloseableHttpClient httpClient = clientBuilder.build();
    HttpComponentsClientHttpRequestFactory requestFactory2 = new HttpComponentsClientHttpRequestFactory();
    requestFactory2.setHttpClient(httpClient);
    return requestFactory2;
}
Also used : CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) SSLSession(javax.net.ssl.SSLSession) AdapterException(com.mercedesbenz.sechub.adapter.AdapterException) HttpClientBuilder(org.apache.http.impl.client.HttpClientBuilder) SSLContext(javax.net.ssl.SSLContext) PoolingHttpClientConnectionManager(org.apache.http.impl.conn.PoolingHttpClientConnectionManager) NoopHostnameVerifier(org.apache.http.conn.ssl.NoopHostnameVerifier) HostnameVerifier(javax.net.ssl.HostnameVerifier) PlainConnectionSocketFactory(org.apache.http.conn.socket.PlainConnectionSocketFactory) SSLConnectionSocketFactory(org.apache.http.conn.ssl.SSLConnectionSocketFactory) ConnectionSocketFactory(org.apache.http.conn.socket.ConnectionSocketFactory) HttpComponentsClientHttpRequestFactory(org.springframework.http.client.HttpComponentsClientHttpRequestFactory)

Aggregations

AdapterException (com.mercedesbenz.sechub.adapter.AdapterException)9 JsonNode (com.fasterxml.jackson.databind.JsonNode)3 Test (org.junit.Test)3 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)2 AdapterLogId (com.mercedesbenz.sechub.adapter.AdapterLogId)2 ProductExecutorCallback (com.mercedesbenz.sechub.domain.scan.product.ProductExecutorCallback)2 ProductExecutorContext (com.mercedesbenz.sechub.domain.scan.product.ProductExecutorContext)2 ProductResult (com.mercedesbenz.sechub.domain.scan.product.ProductResult)2 ProductExecutorConfig (com.mercedesbenz.sechub.domain.scan.product.config.ProductExecutorConfig)2 ProductExecutorConfigSetup (com.mercedesbenz.sechub.domain.scan.product.config.ProductExecutorConfigSetup)2 SecHubExecutionContext (com.mercedesbenz.sechub.sharedkernel.execution.SecHubExecutionContext)2 CheckmarxFullScanNecessaryException (com.mercedesbenz.sechub.adapter.checkmarx.support.CheckmarxFullScanNecessaryException)1 CheckmarxOAuthSupport (com.mercedesbenz.sechub.adapter.checkmarx.support.CheckmarxOAuthSupport)1 CheckmarxProjectSupport (com.mercedesbenz.sechub.adapter.checkmarx.support.CheckmarxProjectSupport)1 CheckmarxScanReportSupport (com.mercedesbenz.sechub.adapter.checkmarx.support.CheckmarxScanReportSupport)1 PDSJobStatus (com.mercedesbenz.sechub.adapter.pds.data.PDSJobStatus)1 PDSAdapterJobStatusState (com.mercedesbenz.sechub.adapter.pds.data.PDSJobStatus.PDSAdapterJobStatusState)1 SecHubExecutionException (com.mercedesbenz.sechub.sharedkernel.execution.SecHubExecutionException)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1