Search in sources :

Example 1 with CheckmarxLegacyException

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

the class CxLegacyService method login.

/**
 * Login to Cx using legacy SOAP WS
 * @param username
 * @param password
 * @return
 * @throws CheckmarxLegacyException
 */
public String login(String username, String password) throws CheckmarxLegacyException {
    LoginV2 request = new LoginV2();
    WebServiceTemplate wsInstance = ws;
    // If shards are enabled then fetch the current shard info for override.
    if (properties.getEnableShardManager()) {
        ShardSession shard = sessionTracker.getShardSession();
        wsInstance = shard.getShardWs();
        username = shard.getUsername();
        password = shard.getPassword();
    }
    request.setApplicationCredentials(new Credentials(username, password));
    if (properties.getVersion() >= 9.0) {
        return "-1";
    }
    LoginV2Response response = (LoginV2Response) wsInstance.marshalSendAndReceive(wsInstance.getDefaultUri(), request, new SoapActionCallback(CX_WS_LOGIN_URI));
    try {
        if (!response.getLoginV2Result().isIsSuccesfull())
            throw new CheckmarxLegacyException("Authentication Error");
        if (properties.getEnableShardManager()) {
            ShardSession shard = sessionTracker.getShardSession();
            shard.setSoapToken(response.getLoginV2Result().getSessionId());
        }
        return response.getLoginV2Result().getSessionId();
    } catch (NullPointerException e) {
        log.error("Authentication Error while logging into CX using SOAP WS");
        throw new CheckmarxLegacyException("Authentication Error");
    }
}
Also used : SoapActionCallback(org.springframework.ws.soap.client.core.SoapActionCallback) ShardSession(com.checkmarx.sdk.ShardManager.ShardSession) WebServiceTemplate(org.springframework.ws.client.core.WebServiceTemplate) CheckmarxLegacyException(com.checkmarx.sdk.exception.CheckmarxLegacyException)

Aggregations

ShardSession (com.checkmarx.sdk.ShardManager.ShardSession)1 CheckmarxLegacyException (com.checkmarx.sdk.exception.CheckmarxLegacyException)1 WebServiceTemplate (org.springframework.ws.client.core.WebServiceTemplate)1 SoapActionCallback (org.springframework.ws.soap.client.core.SoapActionCallback)1