internal void UpdateUser(User user, UserDetail detail, IPersistenceContext context) { // do not update user.UserName // do not update user.Password user.DisplayName = detail.DisplayName; user.ValidFrom = detail.ValidFrom; user.ValidUntil = detail.ValidUntil; user.Enabled = detail.Enabled; user.Password.ExpiryTime = detail.PasswordExpiryTime; user.EmailAddress = detail.EmailAddress; // process authority groups var authGroups = CollectionUtils.Map( detail.AuthorityGroups, (AuthorityGroupSummary group) => context.Load<AuthorityGroup>(group.AuthorityGroupRef, EntityLoadFlags.Proxy)); user.AuthorityGroups.Clear(); user.AuthorityGroups.AddAll(authGroups); }
public bool AddUser(UserRowData user) { bool success = false; using(var service = new UserManagement()) { try { var newUser = new UserDetail { UserName = user.UserName, DisplayName = user.DisplayName, Enabled = user.Enabled, CreationTime = Platform.Time, PasswordExpiryTime = Platform.Time, EmailAddress = user.EmailAddress, ResetPassword = true // TODO: Why do we need to reset password here? }; var groups = new List<AuthorityGroupSummary>(); foreach (UserGroup userGroup in user.UserGroups) { groups.Add(new AuthorityGroupSummary(new EntityRef(userGroup.UserGroupRef), userGroup.Name,userGroup.Name, false, false)); } newUser.AuthorityGroups = groups; service.AddUser(newUser); success = true; } catch (Exception ex) { Platform.Log(LogLevel.Error, ex, "Unexpected exception adding user: {0}", user.DisplayName); } } return success; }
private static void LogImportedUsers(UserDetail u, string source) { Platform.Log(LogLevel.Info, "Imported user {0} from {1}", u.UserName, source); }
public LoadUserForEditResponse(UserDetail userDetail) { UserDetail = userDetail; }
public void UpdateUserDetail(UserDetail user) { _service.UpdateUser(new UpdateUserRequest(user)); }
public void AddUser(UserDetail user) { _service.AddUser(new AddUserRequest(user)); }
public UpdateUserRequest(UserDetail userDetail) { UserDetail = userDetail; }
private static void CreateOrUpdateAccount(string accountName, SystemAccountCommandLine cmdLine) { StdOut(string.Format("Checking Enterprise Server for existing account '{0}'...", accountName), cmdLine); // update the enterprise server UserDetail accountDetail; if (GetExistingAccount(accountName, out accountDetail)) { StdOut(string.Format("Account '{0}' exists.", accountName), cmdLine); var updateRequest = new UpdateUserRequest(accountDetail); bool authGroupChange = false, passwordChange = false; // update auth group if specified if (!string.IsNullOrEmpty(cmdLine.AuthorityGroup)) { var authGroup = GetAuthorityGroup(cmdLine.AuthorityGroup); accountDetail.AuthorityGroups = new List<AuthorityGroupSummary> {authGroup}; authGroupChange = true; StdOut(string.Format("Authority group will be set to '{0}'.", authGroup.Name), cmdLine); } // update password if specified var changePassword = !string.IsNullOrEmpty(cmdLine.AccountPassword); if (changePassword) { updateRequest.Password = cmdLine.AccountPassword; passwordChange = true; StdOut(string.Format("Account password will be set to '{0}'.", updateRequest.Password), cmdLine); } else { // if password was not specified, generate password, and check if reset password flag was set // this distinction exists because in upgrade+distributed scenarios, it is possible that the account exists // but that the password may be explicitly specified by another (earlier) component install // so the installer needs a way to use generated password locally without effecting any changes to enterprise server updateRequest.Password = cmdLine.AccountPassword = GeneratePassword(accountName); if (cmdLine.ResetPassword) { // save generated password to both server and local passwordChange = changePassword = true; } else { // only save generated password locally StdOut(string.Format("Synchronizing password locally..."), cmdLine); LocalRegistryManager.SetAccountPassword(accountName, cmdLine.AccountPassword); } } if (passwordChange || authGroupChange) { StdOut(string.Format("Saving changes to Enterprise Server..."), cmdLine); Platform.GetService<IUserAdminService>( service => service.UpdateUser(updateRequest)); // update the local machine if (changePassword) { StdOut(string.Format("Saving password locally..."), cmdLine); LocalRegistryManager.SetAccountPassword(accountName, cmdLine.AccountPassword); } StdOut(string.Format("All changes saved."), cmdLine); } else { StdOut(string.Format("No changes to save."), cmdLine); } } else { StdOut(string.Format("Account '{0}' does not exist. It will be created.", accountName), cmdLine); if (string.IsNullOrEmpty(cmdLine.AccountPassword)) { // generate a password cmdLine.AccountPassword = GeneratePassword(accountName); } var authGroup = GetAuthorityGroup(cmdLine.AuthorityGroup ?? BuiltInAuthorityGroups.SystemAccounts.Name); var userDetail = new UserDetail { AccountType = new EnumValueInfo("S", null), UserName = accountName, DisplayName = accountName, Enabled = true, AuthorityGroups = new List<AuthorityGroupSummary> {authGroup} }; StdOut(string.Format("Creating account '{0}', authority group '{1}'.", accountName, authGroup.Name), cmdLine); StdOut(string.Format("Saving changes to Enterprise Server..."), cmdLine); Platform.GetService<IUserAdminService>( service => service.AddUser(new AddUserRequest(userDetail) {Password = cmdLine.AccountPassword})); // save password locally StdOut(string.Format("Saving password locally..."), cmdLine); LocalRegistryManager.SetAccountPassword(accountName, cmdLine.AccountPassword); StdOut(string.Format("All changes saved."), cmdLine); } }
private static void CreateOrUpdateAccount(string accountName, SystemAccountCommandLine cmdLine) { StdOut(string.Format("Checking Enterprise Server for existing account '{0}'...", accountName), cmdLine); // update the enterprise server UserDetail accountDetail; if (GetExistingAccount(accountName, out accountDetail)) { StdOut(string.Format("Account '{0}' exists.", accountName), cmdLine); var updateRequest = new UpdateUserRequest(accountDetail); bool authGroupChange = false, passwordChange = false; // update auth group if specified if (!string.IsNullOrEmpty(cmdLine.AuthorityGroup)) { var authGroup = GetAuthorityGroup(cmdLine.AuthorityGroup); accountDetail.AuthorityGroups = new List<AuthorityGroupSummary> { authGroup }; authGroupChange = true; StdOut(string.Format("Authority group will be set to '{0}'.", authGroup.Name), cmdLine); } // update password if specified var changePassword = !string.IsNullOrEmpty(cmdLine.AccountPassword); if (changePassword) { updateRequest.Password = cmdLine.AccountPassword; passwordChange = true; StdOut(string.Format("Account password will be set to '{0}'.", updateRequest.Password), cmdLine); } if(passwordChange || authGroupChange) { StdOut(string.Format("Saving changes to Enterprise Server..."), cmdLine); Platform.GetService<IUserAdminService>( service => service.UpdateUser(updateRequest)); // update the local machine if (changePassword) { StdOut(string.Format("Saving password locally..."), cmdLine); LocalRegistryManager.SetAccountPassword(accountName, cmdLine.AccountPassword); } StdOut(string.Format("All changes saved."), cmdLine); } else { StdOut(string.Format("No changes to save."), cmdLine); } } else { StdOut(string.Format("Account '{0}' does not exist. It will be created.", accountName), cmdLine); if (string.IsNullOrEmpty(cmdLine.AccountPassword)) { // generate a password cmdLine.AccountPassword = GeneratePassword(); } var authGroup = GetAuthorityGroup(cmdLine.AuthorityGroup ?? BuiltInAuthorityGroups.SystemAccounts.Name); var userDetail = new UserDetail { AccountType = new EnumValueInfo("S", null), UserName = accountName, DisplayName = accountName, Enabled = true, AuthorityGroups = new List<AuthorityGroupSummary> { authGroup } }; StdOut(string.Format("Creating account '{0}', password '{1}', authority group '{2}'.", accountName, cmdLine.AccountPassword, authGroup.Name), cmdLine); StdOut(string.Format("Saving changes to Enterprise Server..."), cmdLine); Platform.GetService<IUserAdminService>( service => service.AddUser(new AddUserRequest(userDetail) { Password = cmdLine.AccountPassword })); // save password locally StdOut(string.Format("Saving password locally..."), cmdLine); LocalRegistryManager.SetAccountPassword(accountName, cmdLine.AccountPassword); StdOut(string.Format("All changes saved."), cmdLine); } }
public LoadUserForEditResponse(UserDetail userDetail) { UserDetail = userDetail; }
public bool UpdateUser(UserRowData user) { bool success = false; using(UserManagement service = new UserManagement()) { try { UserDetail updateUser = new UserDetail { UserName = user.UserName, DisplayName = user.DisplayName, EmailAddress = user.EmailAddress, Enabled = user.Enabled }; List<AuthorityGroupSummary> groups = new List<AuthorityGroupSummary>(); foreach(UserGroup userGroup in user.UserGroups) { groups.Add(new AuthorityGroupSummary(new EntityRef(userGroup.UserGroupRef), userGroup.Name, userGroup.Name,false)); } updateUser.AuthorityGroups = groups; service.UpdateUserDetail(updateUser); success = true; } catch (Exception ex) { Platform.Log(LogLevel.Error, ex, "Unexpected exception updating user: {0}", user.DisplayName); } } return success; }
public UpdateUserRequest(UserDetail userDetail) { UserDetail = userDetail; }
public UserRowData(UserSummary summary, UserDetail details) { UserGroups = new List<UserGroup>(); UserName = summary.UserName; DisplayName = summary.DisplayName; Enabled = summary.Enabled; LastLoginTime = summary.LastLoginTime; EmailAddress = summary.EmailAddress; if (details!=null) { foreach (AuthorityGroupSummary authorityGroup in details.AuthorityGroups) { UserGroups.Add(new UserGroup( authorityGroup.AuthorityGroupRef.Serialize(), authorityGroup.Name)); } } }
public AddUserRequest(UserDetail userDetail) { UserDetail = userDetail; }
private static void ImportUsers(IEnumerable<UserDefinition> users, string source) { var existingUsers = new List<UserSummary>(); Platform.GetService<IUserReadService>( s => existingUsers = s.ListUsers(new ListUsersRequest()).Users); var authorityGroups = new List<AuthorityGroupSummary>(); Platform.GetService<IAuthorityGroupReadService>( s => authorityGroups = s.ListAuthorityGroups(new ListAuthorityGroupsRequest()).AuthorityGroups); var service = Platform.GetService<IUserAdminService>(); foreach (var user in users) { var userSummary = existingUsers.Find(u => u.UserName == user.UserName); if (userSummary == null) { var userDetail = new UserDetail { UserName = user.UserName, DisplayName = user.DisplayName, Enabled = user.Enabled, EmailAddress = user.EmailAddress, AuthorityGroups = user.AuthorityGroups.Select( newAGName => authorityGroups.Find(existingAG => newAGName == existingAG.Name)).ToList() }; service.AddUser(new AddUserRequest(userDetail)); LogImportedUsers(userDetail, source); } else { var userDetail = service.LoadUserForEdit(new LoadUserForEditRequest(user.UserName)).UserDetail; userDetail.DisplayName = user.DisplayName; userDetail.Enabled = user.Enabled; userDetail.EmailAddress = user.EmailAddress; userDetail.AuthorityGroups.Clear(); userDetail.AuthorityGroups = user.AuthorityGroups.Select( newAGName => authorityGroups.Find(existingAG => newAGName == existingAG.Name)).ToList(); service.UpdateUser(new UpdateUserRequest(userDetail)); LogImportedUsers(userDetail, source); } } }
public AddUserRequest(UserDetail userDetail) { UserDetail = userDetail; }
private static bool GetExistingAccount(string account, out UserDetail detail) { try { LoadUserForEditResponse response = null; Platform.GetService<IUserAdminService>( service => response = service.LoadUserForEdit(new LoadUserForEditRequest(account))); detail = response.UserDetail; return true; } catch (FaultException<RequestValidationException>) { detail = null; return false; } }