public void Remove(UserAccount instance, NodeVisit visit) { try { ValidateByRole(visit, SystemRoleType.Admin); if (!CanRemoveUser(instance.NaasAccount, visit)) { throw new InvalidOperationException(string.Format("The user \"{0}\" cannot be removed from the node", instance.NaasAccount)); } TransactionTemplate.Execute(delegate { _accountDao.Delete(instance); ActivityManager.LogAudit(NodeMethod.None, null, visit, "{0} removed account: {1}.", visit.Account.NaasAccount, instance.ToString()); return(null); }); } catch (Exception e) { ActivityManager.LogError(NodeMethod.None, null, e, visit, "{0} failed to remove user account: {1}.", visit.Account.NaasAccount, instance.ToString()); throw; } }
public UserAccount Get(string username, NodeVisit visit) { try { if (visit != null) { ValidateByRole(visit, SystemRoleType.Program); } UserAccount account = _accountDao.GetByName(username); if (account == null) { throw new ArgumentException(string.Format("The user \"{0}\" was not found in the database", username)); } ActivityManager.LogAudit(NodeMethod.None, null, visit, "{0} got user account: {1}.", (visit != null) ? visit.Account.NaasAccount : null, account.ToString()); return(account); } catch (Exception e) { ActivityManager.LogError(NodeMethod.None, null, e, visit, "{0} failed to get user account: {1}.", (visit != null) ? visit.Account.NaasAccount : null, username); throw; } }
public UserAccount GetByName(string username, NodeVisit visit) { try { ValidateByRole(visit, SystemRoleType.Admin); UserAccount account = EndpointUserDao.GetByName(username); ActivityManager.LogAudit(NodeMethod.None, null, visit, "{0} got user account: {1}.", visit.Account.NaasAccount, account.ToString()); return(account); } catch (Exception e) { ActivityManager.LogError(NodeMethod.None, null, e, visit, "{0} failed to get user account: {1}.", visit.Account.NaasAccount, username); throw; } }
public IList <UserAccount> Get(NodeVisit visit) { try { ValidateByRole(visit, SystemRoleType.Program); IList <UserAccount> accounts = _accountDao.Get(); ActivityManager.LogAudit(NodeMethod.None, null, visit, "{0} got all user accounts.", visit.Account.NaasAccount); return(accounts); } catch (Exception e) { ActivityManager.LogError(NodeMethod.None, null, e, visit, "{0} failed to get all user accounts.", visit.Account.NaasAccount); throw; } }
public UserAccount GetById(string id, NodeVisit visit) { try { ValidateByRole(visit, SystemRoleType.Program); UserAccount account = _accountDao.GetById(id); ActivityManager.LogAudit(NodeMethod.None, null, visit, "{0} got user account: {1}.", visit.Account.NaasAccount, account.ToString()); return(account); } catch (Exception e) { ActivityManager.LogError(NodeMethod.None, null, e, visit, "{0} failed to get user account: {1}.", visit.Account.NaasAccount, id); throw; } }
public UserAccount Save(UserAccount userAccount, IList <SimpleFlowNotification> notifications, NodeVisit visit) { try { ValidateByRole(visit, SystemRoleType.Program); _notificationDao.SaveNotifications(userAccount.Id, visit.Account.Id, notifications); ActivityManager.LogAudit(NodeMethod.None, null, visit, "{0} saved notifications for user: {1}.", visit.Account.NaasAccount, userAccount.NaasAccount); return(userAccount); } catch (Exception e) { ActivityManager.LogError(NodeMethod.None, null, e, visit, "{0} failed to save notifications for user: {1}.", visit.Account.NaasAccount, userAccount.NaasAccount); throw; } }
public UserAccount ResetPassword(string currentPassword, string newPassword, UserAccount instance, NodeVisit visit) { try { ValidateByRole(visit, SystemRoleType.Program); _naasManager.ChangePassword(instance.NaasAccount, currentPassword, newPassword); ActivityManager.LogAudit(NodeMethod.None, null, visit, "{0} reset password for user account: {1}.", visit.Account.NaasAccount, instance.ToString()); return(instance); } catch (Exception e) { ActivityManager.LogError(NodeMethod.None, null, e, visit, "{0} failed to reset password for user account: {1}.", visit.Account.NaasAccount, instance.ToString()); throw; } }
public UserAccount ResetPassword(UserAccount instance, NodeVisit visit) { try { ValidateByRole(visit, SystemRoleType.Admin); string newPassword = GenerateRandomPassword(); _naasManager.ResetPassword(instance.NaasAccount, newPassword); ActivityManager.LogAudit(NodeMethod.None, null, visit, "{0} reset password for user account: {1}.", visit.Account.NaasAccount, instance.ToString()); _notificationManager.DoChangePasswordNotifications(instance.NaasAccount, newPassword); return(instance); } catch (Exception e) { ActivityManager.LogError(NodeMethod.None, null, e, visit, "{0} failed to reset password for user account: {1}.", visit.Account.NaasAccount, instance.ToString()); throw; } }
public UserAccount Save(UserAccount instance, bool allowCreateInNaasIfNecessary, string naasCreatePassword, NodeVisit visit) { try { if ((instance == null) || string.IsNullOrEmpty(instance.NaasAccount)) { throw new ArgumentException("Input values are null."); } bool createInDB = string.IsNullOrEmpty(instance.Id); bool needToCreateInNAAS = !_naasManager.UserExists(instance.NaasAccount); if (needToCreateInNAAS && string.IsNullOrEmpty(naasCreatePassword)) { throw new ArgumentException("Password cannot be empty."); } if (needToCreateInNAAS && !allowCreateInNaasIfNecessary) { throw new ArgumentException(string.Format("The user \"{0}\" does not exist in NAAS and cannot be added to the node", instance.NaasAccount)); } string activityFormatString; if (createInDB) { if (needToCreateInNAAS) { activityFormatString = "{0} created user account on this local node and within NAAS: {1}."; } else { activityFormatString = "{0} created user account on this local node: {1}."; } } else { if (needToCreateInNAAS) { activityFormatString = "{0} saved user account on this local node and created account within NAAS: {1}."; } else { activityFormatString = "{0} saved user account on this local node: {1}."; } } instance.Policies = _accountPolicyManager.CleanseFlowPoliciesForUser(instance.Role, instance.Policies); string naasPassword = null; if (needToCreateInNAAS) { // First, attempt to create the user in NAAS naasPassword = _naasManager.CreateUser(instance.NaasAccount, naasCreatePassword, instance.Role); } instance.ModifiedById = visit.Account.Id; TransactionTemplate.Execute(delegate { _accountDao.Save(instance); ActivityManager.LogAudit(NodeMethod.None, null, visit, activityFormatString, visit.Account.NaasAccount, instance.ToString()); return(null); }); if (needToCreateInNAAS) { _notificationManager.DoNewNaasAccountNotifications(instance.NaasAccount, naasCreatePassword, (instance.Role == SystemRoleType.Authed)); } else if (createInDB) { _notificationManager.DoNewNodeAccountNotifications(instance.NaasAccount, (instance.Role == SystemRoleType.Authed)); } return(instance); } catch (Exception e) { ActivityManager.LogError(NodeMethod.None, null, e, visit, "{0} failed to save user account: {1}.", visit.Account.NaasAccount, instance.ToString()); throw; } }