Search in sources :

Example 1 with TokenLoginResponse

use of com.checkmarx.sdk.dto.TokenLoginResponse 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);
    }
}
Also used : TokenLoginResponse(com.checkmarx.sdk.dto.TokenLoginResponse) UrlEncodedFormEntity(org.apache.http.client.entity.UrlEncodedFormEntity) ScannerRuntimeException(com.checkmarx.sdk.exception.ScannerRuntimeException)

Aggregations

TokenLoginResponse (com.checkmarx.sdk.dto.TokenLoginResponse)1 ScannerRuntimeException (com.checkmarx.sdk.exception.ScannerRuntimeException)1 UrlEncodedFormEntity (org.apache.http.client.entity.UrlEncodedFormEntity)1