public AddUserResponse AddUser(AddUserRequest request) { Platform.CheckForNullReference(request, "request"); Platform.CheckMemberIsSet(request.UserDetail, "UserDetail"); var userDetail = request.UserDetail; var settings = new AuthenticationSettings(); // create new user var userInfo = new UserInfo(userDetail.UserName, userDetail.DisplayName, userDetail.EmailAddress, userDetail.ValidFrom, userDetail.ValidUntil); var user = User.CreateNewUser(userInfo, settings.DefaultTemporaryPassword); // copy other info such as authority groups from request var assembler = new UserAssembler(); assembler.UpdateUser(user, request.UserDetail, PersistenceContext); // save PersistenceContext.Lock(user, DirtyState.New); PersistenceContext.SynchState(); return(new AddUserResponse(user.GetRef(), assembler.GetUserSummary(user))); }
public UpdateUserResponse UpdateUser(UpdateUserRequest request) { var user = FindUserByName(request.UserDetail.UserName); EnsureCurrentUserAuthorizedToManage(user.AccountType); // update user account info var assembler = new UserAssembler(); assembler.UpdateUser(user, request.UserDetail, PersistenceContext); // for user accounts, reset password if requested if (request.UserDetail.ResetPassword) { if (user.AccountType != UserAccountType.U) { throw new RequestValidationException(SR.MessageAccountTypeDoesNotSupportPasswordReset); } var settings = new AuthenticationSettings(); user.ResetPassword(settings.DefaultTemporaryPassword); } // for system accounts, update the password if specified if (!string.IsNullOrEmpty(request.Password) && user.AccountType == UserAccountType.S) { PasswordPolicy.CheckPasswordCandidate(user.AccountType, request.Password, new AuthenticationSettings()); user.ChangePassword(request.Password, null); } PersistenceContext.SynchState(); return(new UpdateUserResponse(assembler.GetUserSummary(user))); }
public ListUsersResponse ListUsers(ListUsersRequest request) { var criteria = new UserSearchCriteria(); criteria.UserName.SortAsc(0); // create the criteria, depending on whether matches should be "exact" or "like" if (request.ExactMatchOnly) { if (!string.IsNullOrEmpty(request.UserName)) criteria.UserName.EqualTo(request.UserName); if (!string.IsNullOrEmpty(request.DisplayName)) criteria.DisplayName.EqualTo(request.DisplayName); } else { if (!string.IsNullOrEmpty(request.UserName)) criteria.UserName.StartsWith(request.UserName); if (!string.IsNullOrEmpty(request.DisplayName)) criteria.DisplayName.Like(string.Format("%{0}%", request.DisplayName)); } var assembler = new UserAssembler(); var userSummaries = CollectionUtils.Map( PersistenceContext.GetBroker<IUserBroker>().Find(criteria, request.Page), (User user) => assembler.GetUserSummary(user)); return new ListUsersResponse(userSummaries); }
public ResetUserPasswordResponse ResetUserPassword(ResetUserPasswordRequest request) { Platform.CheckForNullReference(request, "request"); Platform.CheckMemberIsSet(request.UserName, "UserName"); var user = FindUserByName(request.UserName); var settings = new AuthenticationSettings(); user.ResetPassword(settings.DefaultTemporaryPassword); var assembler = new UserAssembler(); return(new ResetUserPasswordResponse(assembler.GetUserSummary(user))); }
public ListUsersResponse ListUsers(ListUsersRequest request) { // establish which account types this user is entitled to see var visibleAccountTypes = GetAccountTypesAuthorizedToManage(request.IncludeGroupAccounts, request.IncludeSystemAccounts).ToList(); if (!visibleAccountTypes.Any()) { throw new SecurityException(SR.MessageUserNotAuthorized); } var criteria = new UserSearchCriteria(); criteria.AccountType.In(visibleAccountTypes); criteria.UserName.SortAsc(0); // create the criteria, depending on whether matches should be "exact" or "like" if (request.ExactMatchOnly) { if (!string.IsNullOrEmpty(request.UserName)) { criteria.UserName.EqualTo(request.UserName); } if (!string.IsNullOrEmpty(request.DisplayName)) { criteria.DisplayName.EqualTo(request.DisplayName); } } else { if (!string.IsNullOrEmpty(request.UserName)) { criteria.UserName.StartsWith(request.UserName); } if (!string.IsNullOrEmpty(request.DisplayName)) { criteria.DisplayName.Like(string.Format("%{0}%", request.DisplayName)); } } var broker = PersistenceContext.GetBroker <IUserBroker>(); var assembler = new UserAssembler(); var userSummaries = CollectionUtils.Map( broker.Find(criteria, request.Page), (User user) => assembler.GetUserSummary(user)); var total = broker.Count(criteria); return(new ListUsersResponse(userSummaries, (int)total)); }
public UpdateUserResponse UpdateUser(UpdateUserRequest request) { var user = FindUserByName(request.UserDetail.UserName); // update user account info var assembler = new UserAssembler(); assembler.UpdateUser(user, request.UserDetail, PersistenceContext); // reset password if requested if (request.UserDetail.ResetPassword) { var settings = new AuthenticationSettings(); user.ResetPassword(settings.DefaultTemporaryPassword); } PersistenceContext.SynchState(); return(new UpdateUserResponse(assembler.GetUserSummary(user))); }
public AddUserResponse AddUser(AddUserRequest request) { Platform.CheckForNullReference(request, "request"); Platform.CheckMemberIsSet(request.UserDetail, "UserDetail"); var userDetail = request.UserDetail; var accountType = (userDetail.AccountType != null) ? EnumUtils.GetEnumValue <UserAccountType>(userDetail.AccountType) : UserAccountType.U; // default account type is U if not specified // is the current user authorized to create user accounts of this type? EnsureCurrentUserAuthorizedToManage(accountType); if (!UserName.IsLegalUserName(userDetail.UserName)) { throw new RequestValidationException("Illegal account name."); } // create new user var userInfo = new UserInfo( accountType, userDetail.UserName, userDetail.DisplayName, userDetail.EmailAddress, userDetail.ValidFrom, userDetail.ValidUntil); var password = GetNewAccountPassword(accountType, request.Password); var user = User.CreateNewUser(userInfo, password, new HashedSet <AuthorityGroup>()); // copy other info such as authority groups from request var assembler = new UserAssembler(); assembler.UpdateUser(user, request.UserDetail, PersistenceContext); // save PersistenceContext.Lock(user, DirtyState.New); PersistenceContext.SynchState(); return(new AddUserResponse(user.GetRef(), assembler.GetUserSummary(user))); }
public ResetUserPasswordResponse ResetUserPassword(ResetUserPasswordRequest request) { Platform.CheckForNullReference(request, "request"); Platform.CheckMemberIsSet(request.UserName, "UserName"); var user = FindUserByName(request.UserName); EnsureCurrentUserAuthorizedToManage(user.AccountType); if (user.AccountType != UserAccountType.U) { throw new RequestValidationException(SR.MessageAccountTypeDoesNotSupportPasswordReset); } var settings = new AuthenticationSettings(); user.ResetPassword(settings.DefaultTemporaryPassword); var assembler = new UserAssembler(); return(new ResetUserPasswordResponse(assembler.GetUserSummary(user))); }
public ListUsersResponse ListUsers(ListUsersRequest request) { var criteria = new UserSearchCriteria(); criteria.UserName.SortAsc(0); // create the criteria, depending on whether matches should be "exact" or "like" if (request.ExactMatchOnly) { if (!string.IsNullOrEmpty(request.UserName)) { criteria.UserName.EqualTo(request.UserName); } if (!string.IsNullOrEmpty(request.DisplayName)) { criteria.DisplayName.EqualTo(request.DisplayName); } } else { if (!string.IsNullOrEmpty(request.UserName)) { criteria.UserName.StartsWith(request.UserName); } if (!string.IsNullOrEmpty(request.DisplayName)) { criteria.DisplayName.Like(string.Format("%{0}%", request.DisplayName)); } } var assembler = new UserAssembler(); var userSummaries = CollectionUtils.Map( PersistenceContext.GetBroker <IUserBroker>().Find(criteria, request.Page), (User user) => assembler.GetUserSummary(user)); return(new ListUsersResponse(userSummaries)); }
public ListUsersResponse ListUsers(ListUsersRequest request) { // establish which account types this user is entitled to see var visibleAccountTypes = GetAccountTypesAuthorizedToManage(request.IncludeGroupAccounts, request.IncludeSystemAccounts).ToList(); if (!visibleAccountTypes.Any()) throw new SecurityException(SR.MessageUserNotAuthorized); var criteria = new UserSearchCriteria(); criteria.AccountType.In(visibleAccountTypes); criteria.UserName.SortAsc(0); // create the criteria, depending on whether matches should be "exact" or "like" if (request.ExactMatchOnly) { if (!string.IsNullOrEmpty(request.UserName)) criteria.UserName.EqualTo(request.UserName); if (!string.IsNullOrEmpty(request.DisplayName)) criteria.DisplayName.EqualTo(request.DisplayName); } else { if (!string.IsNullOrEmpty(request.UserName)) criteria.UserName.StartsWith(request.UserName); if (!string.IsNullOrEmpty(request.DisplayName)) criteria.DisplayName.Like(string.Format("%{0}%", request.DisplayName)); } var broker = PersistenceContext.GetBroker<IUserBroker>(); var assembler = new UserAssembler(); var userSummaries = CollectionUtils.Map( broker.Find(criteria, request.Page), (User user) => assembler.GetUserSummary(user)); var total = broker.Count(criteria); return new ListUsersResponse(userSummaries, (int)total); }
public AddUserResponse AddUser(AddUserRequest request) { Platform.CheckForNullReference(request, "request"); Platform.CheckMemberIsSet(request.UserDetail, "UserDetail"); var userDetail = request.UserDetail; var accountType = (userDetail.AccountType != null) ? EnumUtils.GetEnumValue<UserAccountType>(userDetail.AccountType) : UserAccountType.U; // default account type is U if not specified // is the current user authorized to create user accounts of this type? EnsureCurrentUserAuthorizedToManage(accountType); if(!UserName.IsLegalUserName(userDetail.UserName)) throw new RequestValidationException("Illegal account name."); // create new user var userInfo = new UserInfo( accountType, userDetail.UserName, userDetail.DisplayName, userDetail.EmailAddress, userDetail.ValidFrom, userDetail.ValidUntil); var password = GetNewAccountPassword(accountType, request.Password); var user = User.CreateNewUser(userInfo, password, new HashedSet<AuthorityGroup>()); // copy other info such as authority groups from request var assembler = new UserAssembler(); assembler.UpdateUser(user, request.UserDetail, PersistenceContext); // save PersistenceContext.Lock(user, DirtyState.New); PersistenceContext.SynchState(); return new AddUserResponse(user.GetRef(), assembler.GetUserSummary(user)); }
public ResetUserPasswordResponse ResetUserPassword(ResetUserPasswordRequest request) { Platform.CheckForNullReference(request, "request"); Platform.CheckMemberIsSet(request.UserName, "UserName"); var user = FindUserByName(request.UserName); EnsureCurrentUserAuthorizedToManage(user.AccountType); if (user.AccountType != UserAccountType.U) throw new RequestValidationException(SR.MessageAccountTypeDoesNotSupportPasswordReset); var settings = new AuthenticationSettings(); user.ResetPassword(settings.DefaultTemporaryPassword); var assembler = new UserAssembler(); return new ResetUserPasswordResponse(assembler.GetUserSummary(user)); }
public UpdateUserResponse UpdateUser(UpdateUserRequest request) { var user = FindUserByName(request.UserDetail.UserName); EnsureCurrentUserAuthorizedToManage(user.AccountType); // update user account info var assembler = new UserAssembler(); assembler.UpdateUser(user, request.UserDetail, PersistenceContext); // for user accounts, reset password if requested if (request.UserDetail.ResetPassword) { if(user.AccountType != UserAccountType.U) throw new RequestValidationException(SR.MessageAccountTypeDoesNotSupportPasswordReset); var settings = new AuthenticationSettings(); user.ResetPassword(settings.DefaultTemporaryPassword); } // for system accounts, update the password if specified if(!string.IsNullOrEmpty(request.Password) && user.AccountType == UserAccountType.S) { PasswordPolicy.CheckPasswordCandidate(request.Password, new AuthenticationSettings()); user.ChangePassword(request.Password, null); } PersistenceContext.SynchState(); return new UpdateUserResponse(assembler.GetUserSummary(user)); }
public AddUserResponse AddUser(AddUserRequest request) { Platform.CheckForNullReference(request, "request"); Platform.CheckMemberIsSet(request.UserDetail, "UserDetail"); var userDetail = request.UserDetail; var settings = new AuthenticationSettings(); // create new user var userInfo = new UserInfo(userDetail.UserName, userDetail.DisplayName, userDetail.EmailAddress, userDetail.ValidFrom, userDetail.ValidUntil); var user = User.CreateNewUser(userInfo, settings.DefaultTemporaryPassword); // copy other info such as authority groups from request var assembler = new UserAssembler(); assembler.UpdateUser(user, request.UserDetail, PersistenceContext); // save PersistenceContext.Lock(user, DirtyState.New); PersistenceContext.SynchState(); return new AddUserResponse(user.GetRef(), assembler.GetUserSummary(user)); }
public ResetUserPasswordResponse ResetUserPassword(ResetUserPasswordRequest request) { Platform.CheckForNullReference(request, "request"); Platform.CheckMemberIsSet(request.UserName, "UserName"); var user = FindUserByName(request.UserName); var settings = new AuthenticationSettings(); user.ResetPassword(settings.DefaultTemporaryPassword); var assembler = new UserAssembler(); return new ResetUserPasswordResponse(assembler.GetUserSummary(user)); }
public UpdateUserResponse UpdateUser(UpdateUserRequest request) { var user = FindUserByName(request.UserDetail.UserName); // update user account info var assembler = new UserAssembler(); assembler.UpdateUser(user, request.UserDetail, PersistenceContext); // reset password if requested if (request.UserDetail.ResetPassword) { var settings = new AuthenticationSettings(); user.ResetPassword(settings.DefaultTemporaryPassword); } PersistenceContext.SynchState(); return new UpdateUserResponse(assembler.GetUserSummary(user)); }