use of com.checkmarx.sdk.exception.CheckmarxException in project checkmarx-spring-boot-java-sdk by checkmarx-ltd.
the class CxService method setProjectRepositoryDetails.
/**
* Set Repository details for a project
*/
public void setProjectRepositoryDetails(Integer projectId, String gitUrl, String branch, CxScanParams params) throws CheckmarxException {
String sshKey = getSshKey(params);
CxProjectSource projectSource;
if (sshKey.length() > 0) {
projectSource = CxProjectSource.builder().url(createGitURL(gitUrl)).privateKey(sshKey).branch(branch).build();
} else {
projectSource = CxProjectSource.builder().url(gitUrl).branch(branch).build();
}
log.debug("branch {}", branch);
log.debug("project {}", projectId);
HttpEntity<CxProjectSource> requestEntity = new HttpEntity<>(projectSource, authClient.createAuthHeaders());
try {
log.info("Updating Source details for project Id {}", projectId);
restTemplate.exchange(cxProperties.getUrl().concat(PROJECT_SOURCE), HttpMethod.POST, requestEntity, String.class, projectId);
} catch (HttpStatusCodeException e) {
log.error("Error occurred while updating Project source info for project {}.", projectId);
log.debug(ExceptionUtils.getStackTrace(e));
throw new CheckmarxException("Error occurred while adding source details to project. Please ensure GIT is defined within Checkmarx");
}
}
use of com.checkmarx.sdk.exception.CheckmarxException in project checkmarx-spring-boot-java-sdk by checkmarx-ltd.
the class CxService method getLdapRoleMapId.
@Override
public Integer getLdapRoleMapId(Integer ldapServerId, Integer roleId, String ldapGroupDn) throws CheckmarxException {
if (cxProperties.getVersion() < 9.0) {
throw new CheckmarxException(ONLY_SUPPORTED_IN_90_PLUS);
}
try {
HttpEntity requestEntity = new HttpEntity<>(authClient.createAuthHeaders());
ResponseEntity<String> response = restTemplate.exchange(cxProperties.getUrl().concat(ROLE_LDAP_MAPPINGS), HttpMethod.GET, requestEntity, String.class, ldapServerId);
JSONArray objs = new JSONArray(response.getBody());
for (int i = 0; i < objs.length(); i++) {
JSONObject obj = objs.getJSONObject(i);
String cn = obj.getString("ldapGroupDn");
if (roleId.equals(obj.getInt("roleId")) && cn.equals(ldapGroupDn)) {
return obj.getInt("id");
}
}
log.info("No mapping found for {} with Server id {}", ldapGroupDn, ldapServerId);
} catch (HttpStatusCodeException e) {
log.error("Error occurred while retrieving ldap server mappings, http error {}", e.getStatusCode());
log.error(ExceptionUtils.getStackTrace(e));
}
return UNKNOWN_INT;
}
use of com.checkmarx.sdk.exception.CheckmarxException in project checkmarx-spring-boot-java-sdk by checkmarx-ltd.
the class CxService method createScanAndReport.
/**
* @param params attributes used to define the project
*/
@Override
public CxXMLResultsType createScanAndReport(CxScanParams params, String comment) throws CheckmarxException {
Integer scanId = createScan(params, comment);
waitForScanCompletion(scanId);
try {
Integer reportId = createScanReport(scanId);
waitForReportCreateOrFail(reportId);
Thread.sleep(1000);
return getXmlReportContent(reportId);
} catch (InterruptedException e) {
log.error(ExceptionUtils.getStackTrace(e));
Thread.currentThread().interrupt();
throw new CheckmarxException(INTERRUPTED_EXCEPTION_MESSAGE);
}
}
use of com.checkmarx.sdk.exception.CheckmarxException in project checkmarx-spring-boot-java-sdk by checkmarx-ltd.
the class CxService method waitForScanCompletion.
/**
* Wait for a for a scan with a given scan Id to complete with a finished or failure state
*
* @param scanId
* @throws CheckmarxException
*/
public void waitForScanCompletion(Integer scanId) throws CheckmarxException {
Integer status = getScanStatus(scanId);
long timer = 0;
long queueTimer = 0;
try {
while (!status.equals(CxService.SCAN_STATUS_FINISHED) && !status.equals(CxService.SCAN_STATUS_CANCELED) && !status.equals(CxService.SCAN_STATUS_FAILED)) {
Thread.sleep(cxProperties.getScanPolling());
status = getScanStatus(scanId);
timer += cxProperties.getScanPolling();
// Scan Queuing Timeout = '0' and Scan Queuing = true would be waiting forever with the scan in the queue
if (cxProperties.getScanQueuing() && status.equals(CxService.SCAN_STATUS_QUEUED)) {
queueTimer += cxProperties.getScanPolling();
if (cxProperties.getScanQueuingTimeout() != 0 && queueTimer >= (cxProperties.getScanQueuingTimeout() * 60000)) {
log.error("Scan queued time exceded. {} minutes ", cxProperties.getScanQueuingTimeout());
throw new CheckmarxException("Timeout exceeded for Scan Queuing.");
}
}
if (timer >= (cxProperties.getScanTimeout() * 60000)) {
log.error("Scan timeout exceeded. {} minutes", cxProperties.getScanTimeout());
throw new CheckmarxException("Timeout exceeded during scan");
}
}
if (status.equals(CxService.SCAN_STATUS_FAILED) || status.equals(CxService.SCAN_STATUS_CANCELED)) {
throw new CheckmarxException("Scan was cancelled or failed");
}
} catch (InterruptedException e) {
throw new CheckmarxException("Thread interrupted");
} catch (HttpStatusCodeException e) {
throw new CheckmarxException("HTTP Error".concat(ExceptionUtils.getRootCauseMessage(e)));
}
}
use of com.checkmarx.sdk.exception.CheckmarxException in project checkmarx-spring-boot-java-sdk by checkmarx-ltd.
the class CxService method uploadProjectSource.
/**
* Upload file (zip of source) for a project
*/
public void uploadProjectSource(Integer projectId, File file) throws CheckmarxException {
HttpHeaders headers = authClient.createAuthHeaders();
headers.setContentType(MediaType.MULTIPART_FORM_DATA);
LinkedMultiValueMap<String, Object> map = new LinkedMultiValueMap<>();
FileSystemResource value = new FileSystemResource(file);
map.add("zippedSource", value);
HttpEntity<LinkedMultiValueMap<String, Object>> requestEntity = new HttpEntity<>(map, headers);
try {
log.info("Updating Source details for project Id {}", projectId);
restTemplate.exchange(cxProperties.getUrl().concat(PROJECT_SOURCE_FILE), HttpMethod.POST, requestEntity, String.class, projectId);
} catch (HttpStatusCodeException e) {
log.error(ExceptionUtils.getStackTrace(e));
log.error("Error occurred while uploading Project source for project id {}.", projectId);
throw new CheckmarxException("Error occurred while uploading source");
}
}
Aggregations