/// <summary> /// Uses the given username and password to login to Checkmarx and establish a session. This method must /// be called before all others to ensure that the session is properly established. /// </summary> /// <param name="username">Checkmarx username. If you are using a domain login, remember to prepend the domain name to the username like so: DOMAIN\username.</param> /// <param name="password">Checkmarx password.</param> /// <returns>bool</returns> /// <example> /// using(CxWebService service = new CxWebService()) /// { /// Console.Write("Logging into Checkmarx as {0}: ", username); /// Console.WriteLine("{0}.", (service.Login(username, password) ? "OK" : "FAILED")); /// } //service.Logout() is automatically called. /// </example> public bool Login(string username, SecureString password) { CxSDKWebService.Credentials creds = new CxSDKWebService.Credentials(); creds.User = username; creds.Pass = StringUtils.GetUnsecureString(password); bool ok = false; try { CxSDKWebService.CxWSResponseLoginData response = CallCheckmarxApi(() => SoapClient.Login(creds, 1033)); _sessionId = response.SessionId; //cache the session ID log.Debug(String.Format("Successfully logged into Checkmarx WS at {0}: {1}", _endpoint.DnsSafeHost, _sessionId)); ok = true; } catch (ResponseException e) { log.Error(String.Format("Error, unable to logon to Checkmarx WS at {0}: {1}", _endpoint.DnsSafeHost, e.Message), e); }finally { creds = null; } return(ok); }
/// <summary> /// Login the given user. /// </summary> /// <param name="username"> /// The user name to login with. This cannot be null, empty or whitespace. /// </param> /// <param name="password"> /// The password to login with. This cannot be null, empty or whitespace. /// </param> /// <returns> /// The session ID. /// </returns> /// <exception cref="ArgumentNullException"> /// No argument can be null. <paramref name="username"/> and <paramref name="username"/> cannot be empty or whitespace. /// </exception> /// <exception cref="CommunicationException"> /// An error occurred communicating with the Checkmarx server. /// </exception> /// <exception cref="CheckmarxErrorException"> /// The Checkmarx API returned an unexpected error. /// </exception> private string Login(string username, string password) { if (string.IsNullOrWhiteSpace(username)) { throw new ArgumentNullException(nameof(username)); } if (string.IsNullOrWhiteSpace(password)) { throw new ArgumentNullException(nameof(password)); } CxSDKWebService.Credentials credentials; credentials = new CxSDKWebService.Credentials { User = username, Pass = password }; return(CallCheckmarxApi(() => SoapClient.Login(credentials, CheckmarxLocaleId)).SessionId); }
public bool getCredentials() { string user_name = _token.user_name; string credential = _token.credential; if ((String.IsNullOrEmpty(user_name)) || (String.IsNullOrEmpty(credential))) { secure secure = new secure(_token); _token = secure.decrypt_Credentials(); user_name = _token.user_name; credential = _token.credential; if ((String.IsNullOrEmpty(user_name)) || (String.IsNullOrEmpty(credential))) { Console.Error.WriteLine("Credentials not provided or stored, cannot continue."); return(false); } } _credentials = new CxSDKWebService.Credentials() { User = user_name, Pass = credential }; return(true); }