Search in sources :

Example 16 with ScannerRuntimeException

use of com.checkmarx.sdk.exception.ScannerRuntimeException in project checkmarx-spring-boot-java-sdk by checkmarx-ltd.

the class CxHttpClient method revokeToken.

public void revokeToken(String token) throws IOException {
    UrlEncodedFormEntity requestEntity = getRevocationRequest(ClientType.CLI, token);
    HttpPost post = new HttpPost(rootUri + REVOCATION);
    try {
        request(post, ContentType.APPLICATION_FORM_URLENCODED.toString(), requestEntity, String.class, HttpStatus.SC_OK, "revocation", false, false);
    } catch (ScannerRuntimeException e) {
        throw new ScannerRuntimeException(String.format("Token revocation failure error was: %s", e.getMessage()), e);
    }
}
Also used : UrlEncodedFormEntity(org.apache.http.client.entity.UrlEncodedFormEntity) ScannerRuntimeException(com.checkmarx.sdk.exception.ScannerRuntimeException)

Example 17 with ScannerRuntimeException

use of com.checkmarx.sdk.exception.ScannerRuntimeException in project checkmarx-spring-boot-java-sdk by checkmarx-ltd.

the class CxHttpClient method getAccessTokenFromRefreshToken.

private TokenLoginResponse getAccessTokenFromRefreshToken(LoginSettings settings) throws IOException {
    UrlEncodedFormEntity requestEntity = getTokenRefreshingRequest(settings);
    HttpPost post = new HttpPost(settings.getAccessControlBaseUrl());
    try {
        return request(post, ContentType.APPLICATION_FORM_URLENCODED.toString(), requestEntity, TokenLoginResponse.class, HttpStatus.SC_OK, AUTH_MESSAGE, false, false);
    } catch (ScannerRuntimeException e) {
        throw new ScannerRuntimeException(String.format("Failed to generate access token from refresh token. The error was: %s", e.getMessage()), e);
    }
}
Also used : UrlEncodedFormEntity(org.apache.http.client.entity.UrlEncodedFormEntity) ScannerRuntimeException(com.checkmarx.sdk.exception.ScannerRuntimeException)

Example 18 with ScannerRuntimeException

use of com.checkmarx.sdk.exception.ScannerRuntimeException in project checkmarx-spring-boot-java-sdk by checkmarx-ltd.

the class ScaScanner method getLatestScanResults.

public AstScaResults getLatestScanResults(ScanParams scanParams) {
    RestClientConfig config = getScanConfig(scanParams);
    try {
        IScanClientHelper client = allocateClient(config);
        client.init();
        ResultsBase results = client.getLatestScanResults();
        AstScaResults result;
        if (results != null) {
            result = toResults(results);
            applyFilterToResults(result, scanParams);
        } else {
            result = new AstScaResults();
        }
        return result;
    } catch (Exception e) {
        throw new ScannerRuntimeException("Error getting latest scan results.", e);
    }
}
Also used : IScanClientHelper(com.checkmarx.sdk.utils.scanner.client.IScanClientHelper) RestClientConfig(com.checkmarx.sdk.config.RestClientConfig) ScannerRuntimeException(com.checkmarx.sdk.exception.ScannerRuntimeException) ScannerRuntimeException(com.checkmarx.sdk.exception.ScannerRuntimeException)

Example 19 with ScannerRuntimeException

use of com.checkmarx.sdk.exception.ScannerRuntimeException in project checkmarx-spring-boot-java-sdk by checkmarx-ltd.

the class AstClientHelper method retrieveScanResults.

private ASTResults retrieveScanResults() {
    try {
        ASTResults result = new ASTResults();
        result.setScanId(scanId);
        AstSummaryResults scanSummary = getSummary();
        result.setSummary(scanSummary);
        List<Finding> findings = getFindings();
        result.setFindings(findings);
        String projectLink = getWebReportLink(config.getAstConfig().getWebAppUrl());
        result.setWebReportLink(projectLink);
        return result;
    } catch (IOException e) {
        String message = String.format("Error getting %s scan results.", getScannerDisplayName());
        throw new ScannerRuntimeException(message, e);
    }
}
Also used : Finding(com.checkmarx.sdk.dto.ast.report.Finding) IOException(java.io.IOException) ScannerRuntimeException(com.checkmarx.sdk.exception.ScannerRuntimeException)

Example 20 with ScannerRuntimeException

use of com.checkmarx.sdk.exception.ScannerRuntimeException in project checkmarx-spring-boot-java-sdk by checkmarx-ltd.

the class AstClientHelper method initiateScan.

@Override
public ResultsBase initiateScan() {
    log.info("----------------------------------- Initiating {} Scan:------------------------------------", getScannerDisplayName());
    ASTResults astResults = new ASTResults();
    scanId = null;
    AstConfig astConfig = config.getAstConfig();
    try {
        SourceLocationType locationType = astConfig.getSourceLocationType();
        HttpResponse response;
        String projectId = determineProjectId(config.getProjectName());
        if (locationType == SourceLocationType.REMOTE_REPOSITORY) {
            response = submitSourcesFromRemoteRepo(projectId, astConfig);
        } else {
            response = submitAllSourcesFromLocalDir(projectId, astConfig);
        }
        scanId = extractScanIdFrom(response);
        astResults.setScanId(scanId);
    } catch (Exception e) {
        log.error(e.getMessage());
        setState(State.FAILED);
        astResults.setException(new ScannerRuntimeException("Error creating scan.", e));
    }
    return astResults;
}
Also used : AstConfig(com.checkmarx.sdk.config.AstConfig) ScannerRuntimeException(com.checkmarx.sdk.exception.ScannerRuntimeException) URISyntaxException(java.net.URISyntaxException) CheckmarxException(com.checkmarx.sdk.exception.CheckmarxException) ScannerRuntimeException(com.checkmarx.sdk.exception.ScannerRuntimeException) CxHTTPClientException(com.checkmarx.sdk.exception.CxHTTPClientException) RestClientException(org.springframework.web.client.RestClientException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Aggregations

ScannerRuntimeException (com.checkmarx.sdk.exception.ScannerRuntimeException)22 IOException (java.io.IOException)6 UnsupportedEncodingException (java.io.UnsupportedEncodingException)5 CheckmarxException (com.checkmarx.sdk.exception.CheckmarxException)4 CxHTTPClientException (com.checkmarx.sdk.exception.CxHTTPClientException)4 MalformedURLException (java.net.MalformedURLException)3 URL (java.net.URL)3 JAXBException (javax.xml.bind.JAXBException)3 UrlEncodedFormEntity (org.apache.http.client.entity.UrlEncodedFormEntity)3 RestClientConfig (com.checkmarx.sdk.config.RestClientConfig)2 Package (com.checkmarx.sdk.dto.sca.report.Package)2 Severity (com.checkmarx.sdk.dto.scansummary.Severity)2 URISyntaxException (java.net.URISyntaxException)2 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)2 URIBuilder (org.apache.http.client.utils.URIBuilder)2 ModelMapper (org.modelmapper.ModelMapper)2 AstConfig (com.checkmarx.sdk.config.AstConfig)1 TokenLoginResponse (com.checkmarx.sdk.dto.TokenLoginResponse)1 Finding (com.checkmarx.sdk.dto.ast.report.Finding)1 ScaUploadUrlRequest (com.checkmarx.sdk.dto.sca.ScaUploadUrlRequest)1