Search in sources :

Example 1 with ClientType

use of com.checkmarx.sdk.dto.sca.ClientType in project checkmarx-spring-boot-java-sdk by checkmarx-ltd.

the class CxHttpClient method getTokenRefreshingRequest.

private static UrlEncodedFormEntity getTokenRefreshingRequest(LoginSettings settings) throws UnsupportedEncodingException {
    ClientType clientType = settings.getClientTypeForRefreshToken();
    List<BasicNameValuePair> parameters = new ArrayList<>();
    parameters.add(new BasicNameValuePair("grant_type", REFRESH_TOKEN_PROP));
    parameters.add(new BasicNameValuePair(CLIENT_ID_PROP, clientType.getClientId()));
    parameters.add(new BasicNameValuePair(CLIENT_SECRET_PROP, clientType.getClientSecret()));
    parameters.add(new BasicNameValuePair(REFRESH_TOKEN_PROP, settings.getRefreshToken()));
    return new UrlEncodedFormEntity(parameters, StandardCharsets.UTF_8.name());
}
Also used : ClientType(com.checkmarx.sdk.dto.sca.ClientType) BasicNameValuePair(org.apache.http.message.BasicNameValuePair) ArrayList(java.util.ArrayList) UrlEncodedFormEntity(org.apache.http.client.entity.UrlEncodedFormEntity)

Example 2 with ClientType

use of com.checkmarx.sdk.dto.sca.ClientType in project checkmarx-spring-boot-java-sdk by checkmarx-ltd.

the class CxHttpClient method getAuthRequest.

private static UrlEncodedFormEntity getAuthRequest(LoginSettings settings) {
    ClientType clientType = settings.getClientTypeForPasswordAuth();
    String grantType = StringUtils.defaultString(clientType.getGrantType(), DEFAULT_GRANT_TYPE);
    List<BasicNameValuePair> parameters = new ArrayList<>();
    parameters.add(new BasicNameValuePair("username", settings.getUsername()));
    parameters.add(new BasicNameValuePair(PASSWORD_PROP, settings.getPassword()));
    parameters.add(new BasicNameValuePair("grant_type", grantType));
    parameters.add(new BasicNameValuePair("scope", clientType.getScopes()));
    parameters.add(new BasicNameValuePair(CLIENT_ID_PROP, clientType.getClientId()));
    parameters.add(new BasicNameValuePair(CLIENT_SECRET_PROP, clientType.getClientSecret()));
    if (!StringUtils.isEmpty(settings.getTenant())) {
        String authContext = String.format("Tenant:%s", settings.getTenant());
        parameters.add(new BasicNameValuePair("acr_values", authContext));
    }
    return new UrlEncodedFormEntity(parameters, StandardCharsets.UTF_8);
}
Also used : ClientType(com.checkmarx.sdk.dto.sca.ClientType) BasicNameValuePair(org.apache.http.message.BasicNameValuePair) ArrayList(java.util.ArrayList) UrlEncodedFormEntity(org.apache.http.client.entity.UrlEncodedFormEntity)

Example 3 with ClientType

use of com.checkmarx.sdk.dto.sca.ClientType in project checkmarx-spring-boot-java-sdk by checkmarx-ltd.

the class AstClientHelper method init.

@Override
public ResultsBase init() {
    log.debug("Initializing {} client.", getScannerDisplayName());
    ASTResults astResults = new ASTResults();
    try {
        ClientType clientType = getClientType();
        LoginSettings settings = getLoginSettings(clientType);
        httpClient.login(settings);
    } catch (Exception e) {
        super.handleInitError(e, astResults);
    }
    return astResults;
}
Also used : ClientType(com.checkmarx.sdk.dto.sca.ClientType) 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)

Example 4 with ClientType

use of com.checkmarx.sdk.dto.sca.ClientType in project checkmarx-spring-boot-java-sdk by checkmarx-ltd.

the class ClientTypeResolverTest method testDetermineClientType.

private void testDetermineClientType(String urlPropName) {
    ClientTypeResolver resolver = new ClientTypeResolver(new RestClientConfig());
    ClientType clientType = resolver.determineClientType(urlPropName);
    Assert.assertNotNull("Client type is null.", clientType);
    Assert.assertTrue("Client ID is empty.", StringUtils.isNotEmpty(clientType.getClientId()));
    Assert.assertTrue("Scopes are empty.", StringUtils.isNotEmpty(clientType.getScopes()));
}
Also used : ClientType(com.checkmarx.sdk.dto.sca.ClientType) ClientTypeResolver(com.checkmarx.sdk.utils.scanner.client.ClientTypeResolver) RestClientConfig(com.checkmarx.sdk.config.RestClientConfig)

Aggregations

ClientType (com.checkmarx.sdk.dto.sca.ClientType)4 ArrayList (java.util.ArrayList)2 UrlEncodedFormEntity (org.apache.http.client.entity.UrlEncodedFormEntity)2 BasicNameValuePair (org.apache.http.message.BasicNameValuePair)2 RestClientConfig (com.checkmarx.sdk.config.RestClientConfig)1 CheckmarxException (com.checkmarx.sdk.exception.CheckmarxException)1 CxHTTPClientException (com.checkmarx.sdk.exception.CxHTTPClientException)1 ScannerRuntimeException (com.checkmarx.sdk.exception.ScannerRuntimeException)1 ClientTypeResolver (com.checkmarx.sdk.utils.scanner.client.ClientTypeResolver)1 IOException (java.io.IOException)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 MalformedURLException (java.net.MalformedURLException)1 URISyntaxException (java.net.URISyntaxException)1 RestClientException (org.springframework.web.client.RestClientException)1