/// <summary> /// Validation of user credentials /// </summary> /// <param name="validationResult">string with detailed validation result</param> /// <returns>true, if user successfully logged to Dexter server</returns> public bool ValidateUserCredentials(DexterInfo dexterInfo, out string validationResult) { var uriString = string.Format("http://{0}:{1}/api/accounts/userId", dexterInfo.dexterServerIp, dexterInfo.dexterServerPort); Uri uri; bool uriValid = Uri.TryCreate(uriString, UriKind.Absolute, out uri); if (!uriValid) { return handleWrongServerAddress(out validationResult); } WebRequest request = WebRequest.Create(uri); string encoded = Convert.ToBase64String(System.Text.Encoding.GetEncoding("ISO-8859-1").GetBytes(dexterInfo.userName + ":" + dexterInfo.userPassword)); request.Headers.Add("Authorization", "Basic " + encoded); HttpWebResponse response; try { response = (HttpWebResponse)request.GetResponse(); } catch (WebException e) { return handleWebException(e, out validationResult); } return handleServerOk(out validationResult); }
/// <summary> /// Saves DexterInfo to Settings Store /// </summary> /// <param name="dexterInfo">DexterInfo to save</param> public void Save(DexterInfo dexterInfo) { if (!settingsStore.CollectionExists(DexterStoreName)) { settingsStore.CreateCollection(DexterStoreName); } settingsStore.SetString(DexterStoreName, "dexterHome", dexterInfo.dexterHome); settingsStore.SetString(DexterStoreName, "dexterServerIp", dexterInfo.dexterServerIp); settingsStore.SetInt32(DexterStoreName, "dexterServerPort", dexterInfo.dexterServerPort); settingsStore.SetString(DexterStoreName, "userName", dexterInfo.userName); settingsStore.SetString(DexterStoreName, "userPassword", dexterInfo.userPassword); settingsStore.SetBoolean(DexterStoreName, "standalone", dexterInfo.standalone); }
/// <summary> /// Server settings validation /// </summary> /// <param name="validationResult">string with detailed validation result</param> /// <returns>true, if successfully connected to Dexter server</returns> public bool ValidateServerConnection(DexterInfo dexterInfo, out string validationResult) { var uriString = string.Format("http://{0}:{1}/api/isServerAlive", dexterInfo.dexterServerIp, dexterInfo.dexterServerPort); Uri uri; bool uriValid = Uri.TryCreate(uriString, UriKind.Absolute, out uri); if (!uriValid) { return handleWrongServerAddress(out validationResult); } WebRequest request = WebRequest.Create(uri); request.Timeout = 5000; HttpWebResponse response; try { response = (HttpWebResponse)request.GetResponse(); } catch (WebException e) { return handleWebException(e, out validationResult); } if (response.StatusCode != HttpStatusCode.OK) { return handleWrongServerResponse(response, out validationResult); } string html = string.Empty; using (StreamReader reader = new StreamReader(response.GetResponseStream())) { html = reader.ReadToEnd(); } if (html == "ok") { return handleServerOk(out validationResult); } else { return handleWrongServerMessage(html, out validationResult); } }
/// <summary> /// Validates Dexter configuration /// </summary> /// <param name="config">configuration</param> /// <returns>true, if validation was successfull </returns> private bool ValidateConfiguration(Configuration config) { DexterInfo dexterInfo = DexterInfo.fromConfiguration(config); string validationResult; if (!dexterInfoValidator.ValidateDexterPath(dexterInfo)) { MessageBox.Show("Dexter wasn't found in given path. You cannot perform analysis until you set a proper path.", "Dexter error", MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } if (!config.standalone && !dexterInfoValidator.ValidateServerConnection(dexterInfo, out validationResult)) { DialogResult result = MessageBox.Show("Couldn't connect to Dexter server. Please check server address in Dexter/Settings window. Continue in standalone mode?", "Dexter warning", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning); if (result == DialogResult.OK) { config.standalone = true; return(true); } else { return(false); } } else { if (!config.standalone && !dexterInfoValidator.ValidateUserCredentials(dexterInfo, out validationResult)) { DialogResult result = MessageBox.Show("Couldn't login to Dexter server. Please check user credentials in Dexter/Settings window. Continue in standalone mode?", "Dexter warning", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning); if (result == DialogResult.OK) { config.standalone = true; return(true); } else { return(false); } } } return(true); }
private void createUser() { DexterInfo dexterInfo = GetDexterInfoFromSettings(); var result = ""; if (!validator.ValidateServerConnection(dexterInfo, out result)) { MessageBox.Show("Couldn't connect to Dexter server. Setting analysis mode to standalone", "Dexter warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); standaloneCheckBox.Checked = true; dexterInfo.standalone = true; Save(dexterInfo); } else if (validator.ValidateUserCredentials(dexterInfo, out result)) { MessageBox.Show($"Couldn't create user: user {dexterInfo.userName} already exists", "Dexter warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); } else { Save(dexterInfo); var dexterClient = new DexterClient(new DexterHttpClientWrapper(dexterInfoProvider)); var creationTask = dexterClient.AddAccount(dexterInfo.userName, dexterInfo.userPassword, false); creationTask.ContinueWith(r => { var response = r.Result; if (response.IsSuccessStatusCode) { MessageBox.Show($"Created new user {dexterInfo.userName}", "Dexter info", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show($"Creating new user {dexterInfo.userName} failed: {response.Content}", "Dexter error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }); } }
public void Save(DexterInfo dexterInfo) { dexterInfoProvider.Save(dexterInfo); }
public void Save(DexterInfo dexterInfo) { Configuration configuration = new Configuration(new ProjectInfo(), dexterInfo); configuration.Save(Path); }
/// <summary> /// Dexter path validation /// </summary> /// <returns>true, if dexter was found in given path</returns> public bool ValidateDexterPath(DexterInfo dexterInfo) { return(dexterInfo.IsDexterFound); }
private string getDashboardUri() { DexterInfo dexterInfo = dexterInfoProvider.Load(); return(string.Format("http://{0}:{1}/defect/", dexterInfo.dexterServerIp, dexterInfo.dexterServerPort)); }
/// <summary> /// Dexter path validation /// </summary> /// <returns>true, if dexter was found in given path</returns> public bool ValidateDexterPath(DexterInfo dexterInfo) { return dexterInfo.IsDexterFound; }