/// <summary> /// Authenticate using the authentication provider /// </summary> internal bool Authenticate(IIdentityProviderService authenticationProvider, IRestClient context) { bool retVal = false; while (!retVal) { Console.WriteLine("Access denied, authentication required."); if (String.IsNullOrEmpty(this.m_configuration.User)) { Console.Write("Username:"******"Username:{0}", this.m_configuration.User); } if (String.IsNullOrEmpty(this.m_configuration.Password)) { this.m_configuration.Password = DisplayUtil.PasswordPrompt("Password:"******"Password:{0}", new String('*', this.m_configuration.Password.Length * 2)); } // Now authenticate try { var principal = (authenticationProvider as OAuthIdentityProvider)?.Authenticate( new SanteDBClaimsPrincipal(new SanteDBClaimsIdentity(this.m_configuration.User, false, "OAUTH2")), this.m_configuration.Password) ?? authenticationProvider.Authenticate(this.m_configuration.User, this.m_configuration.Password); if (principal != null) { retVal = true; AuthenticationContext.Current = new AuthenticationContext(principal); } else { this.m_configuration.Password = null; } } catch (Exception e) { this.m_tracer.TraceError("Authentication error: {0}", e.Message); this.m_configuration.Password = null; } } return(retVal); }
internal static void SetPassword(UserPasswordParms parms) { if (parms.UserName == null) { throw new InvalidOperationException("Must specify a user"); } foreach (var un in parms.UserName) { var user = m_client.GetUsers(o => o.UserName == un).CollectionItem.FirstOrDefault() as SecurityUserInfo; if (user == null) { throw new KeyNotFoundException($"User {un} not found"); } if (String.IsNullOrEmpty(parms.Password)) { var passwd = DisplayUtil.PasswordPrompt($"NEW Password for {user.Entity.UserName}:"); if (String.IsNullOrEmpty(passwd)) { Console.WriteLine("Aborted"); continue; } else if (passwd != DisplayUtil.PasswordPrompt($"CONFIRM Password for {user.Entity.UserName}:")) { Console.WriteLine("Passwords do not match!"); continue; } user.Entity.Password = passwd; } else { user.Entity.Password = parms.Password; } user.PasswordOnly = true; m_client.UpdateUser(user.Entity.Key.Value, user); break; } }