private void ICredentialStoreTest(ICredentialStore credentialStore, string url, string username, string password) { try { TargetUri uri = new TargetUri(url); Credential writeCreds = new Credential(username, password); Credential readCreds = null; credentialStore.WriteCredentials(uri, writeCreds); if ((readCreds = credentialStore.ReadCredentials(uri)) != null) { Assert.AreEqual(writeCreds.Password, readCreds.Password, "Passwords did not match between written and read credentials"); Assert.AreEqual(writeCreds.Username, readCreds.Username, "Usernames did not match between written and read credentials"); } else { Assert.Fail("Failed to read credentials"); } credentialStore.DeleteCredentials(uri); Assert.IsNull(readCreds = credentialStore.ReadCredentials(uri), "Deleted credentials were read back"); } catch (Exception exception) { Assert.Fail(exception.Message); } }
/// <summary> /// Reads credentials for a target URI from the credential store /// </summary> /// <param name="targetUri">The URI of the target for which credentials are being read</param> /// <param name="credentials"></param> /// <returns>A <see cref="Credential"/> from the store is successful; otherwise <see langword="null"/>.</returns> public Credential ReadCredentials(TargetUri targetUri) { ValidateTargetUri(targetUri); string targetName = GetTargetName(targetUri); return(_credentialCache.ReadCredentials(targetUri) ?? ReadCredentials(targetName)); }
/// <summary> /// Reads credentials for a target URI from the credential store /// </summary> /// <param name="targetUri">The URI of the target for which credentials are being read</param> /// <param name="credentials"></param> /// <returns>A <see cref="Credential"/> from the store is successful; otherwise <see langword="null"/>.</returns> public async Task <Credential> ReadCredentials(TargetUri targetUri) { ValidateTargetUri(targetUri); string targetName = GetTargetName(targetUri); return(await _credentialCache.ReadCredentials(targetUri) ?? ReadCredentials(targetName)); }
public override async Task <Credential> GetCredentials(TargetUri targetUri) { if (targetUri is null) { throw new ArgumentNullException(nameof(targetUri)); } return(await _credentialStore.ReadCredentials(targetUri)); }
public void ChangePasswordForUsername(string username, string newPassword) { var matchedCredentials = _credentialStore.ReadCredentials() .Where(c => c.Username != null && c.Username.Equals(username, StringComparison.OrdinalIgnoreCase)); foreach (var credential in matchedCredentials) { credential.ChangePassword(newPassword); } }
public Credential ReadCredentials(TargetUri targetUri) { var storedCreds = store.ReadCredentials(targetUri); if (storedCreds != null && UserNameForTokenCredential.Equals(storedCreds.Username, StringComparison.OrdinalIgnoreCase)) { storedCreds = new Credential(storedCreds.Password); } return(storedCreds); }
public Credential ReadCredentials(TargetUri targetUri) { Credential storedCreds = null; LogWin32Exception("read", () => storedCreds = store.ReadCredentials(targetUri)); if (storedCreds != null && UserNameForTokenCredential.Equals(storedCreds.Username, StringComparison.OrdinalIgnoreCase)) { storedCreds = new Credential(storedCreds.Password); } return(storedCreds); }
public async Task <Credential> ReadCredentials(TargetUri targetUri) { if (targetUri is null) { throw new ArgumentNullException(nameof(targetUri)); } string targetName = GetTargetName(targetUri); return(await _credentialCache.ReadCredentials(targetUri) ?? ReadCredentials(targetName)); }
public void WriteSolution_NoCredentials_FileSavedOk() { // Arrange SetSolutionFilePath(@"c:\mysolutionfile.foo"); var expectedFilePath = @"c:\.sonarlint\mysolutionfile.sqconfig"; var boundProject = new BoundSonarQubeProject { ProjectKey = "mykey", ServerUri = new Uri("http://localhost:9000"), }; // Act var actualFilePath = testSubject.WriteSolutionBinding(boundProject); // Assert actualFilePath.Should().Be(expectedFilePath); fileMock.Verify(x => x.WriteAllText(expectedFilePath, It.IsAny <string>()), Times.Once); var savedCredentials = configurableStore.ReadCredentials(new Uri("http://localhost:9000")); savedCredentials.Should().BeNull(); }
public async Task <Credential> ReadCredentials(TargetUri targetUri) { #if DEBUG Trace.WriteLine($"targetUri: '{targetUri}': Key: '{GetKeyVaultKey(targetUri)}'"); #endif if (targetUri is null || string.IsNullOrEmpty(targetUri.Host)) { throw new ArgumentNullException(nameof(targetUri)); } return(await _credentialCache.ReadCredentials(targetUri) ?? await this.ReadKeyVaultCredentials(targetUri)); }
/// <summary> /// Reads credentials for a target URI from the credential store /// </summary> /// <param name="targetUri">The URI of the target for which credentials are being read</param> /// <param name="credentials"></param> /// <returns>A <see cref="Credential"/> from the store is successful; otherwise <see langword="null"/>.</returns> public Credential ReadCredentials(TargetUri targetUri) { ValidateTargetUri(targetUri); Credential credentials = null; string targetName = this.GetTargetName(targetUri); if ((credentials = _credentialCache.ReadCredentials(targetUri)) == null) { credentials = this.ReadCredentials(targetName); } return(credentials); }
/// <summary> /// Reads credentials for a target URI from the credential store /// </summary> /// <param name="targetUri">The URI of the target for which credentials are being read</param> /// <param name="credentials">The credentials from the store; <see langword="null"/> if failure</param> /// <returns><see langword="true"/> if success; <see langword="false"/> if failure</returns> public bool ReadCredentials(TargetUri targetUri, out Credential credentials) { ValidateTargetUri(targetUri); string targetName = this.GetTargetName(targetUri); Trace.WriteLine("CredentialStore::ReadCredentials"); if (!_credentialCache.ReadCredentials(targetUri, out credentials)) { credentials = this.ReadCredentials(targetName); } return(credentials != null); }
/// <summary> /// Gets `<see cref="Credential"/>` from the storage used by the authentication object. /// <para/> /// Returns a `<see cref="Credential"/>` if successful; otherwise `<see langword="null"/>`. /// </summary> /// <param name="targetUri">The uniform resource indicator used to uniquely identify the credentials.</param> public override Credential GetCredentials(TargetUri targetUri) { BaseSecureStore.ValidateTargetUri(targetUri); return(_credentialStore.ReadCredentials(targetUri)); }
private void ICredentialStoreTest(ICredentialStore credentialStore, string url, string username, string password) { try { Uri uri = new Uri(url, UriKind.Absolute); Credential writeCreds = new Credential(username, password); Credential readCreds = null; credentialStore.WriteCredentials(uri, writeCreds); if (credentialStore.ReadCredentials(uri, out readCreds)) { Assert.AreEqual(writeCreds.Password, readCreds.Password, "Passwords did not match between written and read credentials"); Assert.AreEqual(writeCreds.Username, readCreds.Username, "Usernames did not match between written and read credentials"); } else { Assert.Fail("Failed to read credentials"); } credentialStore.DeleteCredentials(uri); Assert.IsFalse(credentialStore.ReadCredentials(uri, out readCreds), "Deleted credentials were read back"); } catch (Exception exception) { Assert.Fail(exception.Message); } }
/// <summary> /// Gets `<see cref="Credential"/>` from the storage used by the authentication object. /// <para/> /// Returns a `<see cref="Credential"/>` if successful; otherwise `<see langword="null"/>`. /// </summary> /// <param name="targetUri">The uniform resource indicator used to uniquely identify the credentials.</param> public override async Task <Credential> GetCredentials(TargetUri targetUri) { BaseSecureStore.ValidateTargetUri(targetUri); return(await _credentialStore.ReadCredentials(targetUri)); }