use of com.checkmarx.sdk.exception.ScannerRuntimeException in project checkmarx-spring-boot-java-sdk by checkmarx-ltd.
the class CxHttpClient method getTrustAllSSLSocketFactory.
private static SSLConnectionSocketFactory getTrustAllSSLSocketFactory() {
TrustStrategy acceptingTrustStrategy = new TrustAllStrategy();
SSLContext sslContext;
try {
sslContext = SSLContexts.custom().loadTrustMaterial(null, acceptingTrustStrategy).build();
} catch (NoSuchAlgorithmException | KeyStoreException | KeyManagementException e) {
throw new ScannerRuntimeException("Fail to set trust all certificate, 'SSLConnectionSocketFactory'", e);
}
return new SSLConnectionSocketFactory(sslContext, NoopHostnameVerifier.INSTANCE);
}
use of com.checkmarx.sdk.exception.ScannerRuntimeException in project checkmarx-spring-boot-java-sdk by checkmarx-ltd.
the class CxHttpClient method generateToken.
public TokenLoginResponse generateToken(LoginSettings settings) throws IOException {
UrlEncodedFormEntity requestEntity = getAuthRequest(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) {
if (!e.getMessage().contains("invalid_scope")) {
throw new ScannerRuntimeException(String.format("Failed to generate access token, failure error was: %s", e.getMessage()), e);
}
ClientType.RESOURCE_OWNER.setScopes("sast_rest_api");
settings.setClientTypeForPasswordAuth(ClientType.RESOURCE_OWNER);
requestEntity = getAuthRequest(settings);
return request(post, ContentType.APPLICATION_FORM_URLENCODED.toString(), requestEntity, TokenLoginResponse.class, HttpStatus.SC_OK, AUTH_MESSAGE, false, false);
}
}
use of com.checkmarx.sdk.exception.ScannerRuntimeException in project checkmarx-spring-boot-java-sdk by checkmarx-ltd.
the class AstClientHelper method getScanStartHandler.
/**
* @param repoInfo may represent an actual git repo or a presigned URL of an uploaded archive.
* @param sourceLocation
*/
protected AstScanStartHandler getScanStartHandler(RemoteRepositoryInfo repoInfo, SourceLocationType sourceLocation) {
log.debug("Creating the handler object.");
try {
HandlerRef ref = getBranchToScan(repoInfo);
URL effectiveUrl = repoInfo.getUrl();
String username = "";
GitCredentials credentials = calculateGitCredentials(repoInfo, sourceLocation);
if (sourceLocation.REMOTE_REPOSITORY.equals(sourceLocation)) {
effectiveUrl = sanitize(repoInfo.getUrl());
}
// The ref/username/credentials properties are mandatory even if not specified in repoInfo.
return AstScanStartHandler.builder().ref(ref).username(username).credentials(credentials).repoUrl(effectiveUrl.toString()).build();
} catch (MalformedURLException e) {
throw new ScannerRuntimeException(e.getMessage());
}
}
use of com.checkmarx.sdk.exception.ScannerRuntimeException in project checkmarx-spring-boot-java-sdk by checkmarx-ltd.
the class AstClientHelper method prepareURL.
private String prepareURL(Set<String> ids, Set<String> processedIds) {
try {
int lengthOtherParams = new URIBuilder().setPath(DESCRIPTIONS_PATH).setParameter(SCAN_ID_PARAM_NAME, scanId).build().toString().length();
URIBuilder uriBuilder = new URIBuilder();
uriBuilder.setPath(DESCRIPTIONS_PATH);
int idsAllowedLength = URL_MAX_CHAR_SIZE - lengthOtherParams;
List<NameValuePair> nameValues = new LinkedList<>();
for (String id : ids) {
idsAllowedLength = idsAllowedLength - ID_PARAM_NAME.length() - 2 - id.length();
if (idsAllowedLength > 0) {
processedIds.add(id);
nameValues.add(new BasicNameValuePair(ID_PARAM_NAME, id));
}
}
uriBuilder.setParameters(nameValues);
String result = uriBuilder.setParameter(SCAN_ID_PARAM_NAME, scanId).build().toString();
log.debug(String.format("Getting descriptions from %s", result));
return result;
} catch (URISyntaxException e) {
throw new ScannerRuntimeException(URL_PARSING_EXCEPTION, e);
}
}
use of com.checkmarx.sdk.exception.ScannerRuntimeException in project checkmarx-spring-boot-java-sdk by checkmarx-ltd.
the class ClientTypeResolver method getScopesForAuth.
private Set<String> getScopesForAuth(Set<String> supportedScopes) {
Set<String> result;
if (supportedScopes.containsAll(scopesForCloudAuth)) {
result = scopesForCloudAuth;
} else if (supportedScopes.containsAll(scopesForOnPremAuth)) {
result = scopesForOnPremAuth;
} else {
String message = String.format("Access control server doesn't support the necessary scopes (either %s or %s)." + " It only supports the following scopes: %s.", scopesForCloudAuth, scopesForOnPremAuth, supportedScopes);
throw new ScannerRuntimeException(message);
}
log.debug(String.format("Using scopes: %s", result));
return result;
}
Aggregations