コード例 #1
0
        /// <summary>
        /// Create the user with the information we've collected.
        /// </summary>
        /// <param name="email">The identity or login name of the user.</param>
        /// <param name="name">The user's real name name.</param>
        /// <param name="description">A description of the user.</param>
        /// <param name="groupId">The user's initial group.</param>
        /// <param name="organization">The organization the user belongs to.</param>
        private void Create(string email, string name, string description, Guid groupId, Guid organization)
        {
            try
            {
                AdminSupportClient         client = new AdminSupportClient(Guardian.Properties.Settings.Default.AdminSupportEndpoint);
                AdminSupportReference.User record = new AdminSupportReference.User();

                record.FullName     = name;
                record.EmailAddress = email;
                record.Description  = description;
                record.LookupId     = email;
                record.Organization = organization;
                record.GroupId      = groupId;

                MethodResponseguid response = client.CreateUser(record, null);

                client.Close();

                if (!response.IsSuccessful)
                {
                    this.Dispatcher.BeginInvoke(new Action(() =>
                                                           MessageBox.Show(this, String.Format(Properties.Resources.CreateUserFailed, name), this.Title)));
                }
            }
            catch (Exception exception)
            {
                // Any issues trying to communicate to the server are logged.
                EventLog.Error("{0}, {1}", exception.Message, exception.StackTrace);
                this.Dispatcher.BeginInvoke(new Action(() =>
                                                       MessageBox.Show(this, String.Format(Properties.Resources.CreateUserFailed, name), this.Title)));
            }
        }
コード例 #2
0
ファイル: User.cs プロジェクト: radtek/credit-card-exchange
        /// <summary>
        /// Retrieve "extra" information from the server.
        /// </summary>
        /// <param name="identityName">The identity of the user.</param>
        private void LoadAdInformation(String identityName)
        {
            try
            {
                AdminSupportClient            client   = new AdminSupportClient(Settings.Default.AdminSupportEndpoint);
                MethodResponseUserContextData response = client.FindUserByName(this.identityName);

                if (response.IsSuccessful)
                {
                    Application.Current.Dispatcher.BeginInvoke(
                        new SetAdInformationDelegate(this.SetAdInformation),
                        DispatcherPriority.Normal,
                        response.Result.AccountDisabled,
                        response.Result.EmailAddress,
                        response.Result.IsPasswordExpired,
                        response.Result.PasswordExpires);
                }

                client.Close();
            }
            catch (Exception exception)
            {
                EventLog.Information("{0}: {1}\n{2}", exception.GetType(), exception.Message, exception.StackTrace);
            }
        }
コード例 #3
0
        private void Create(String name, Guid typeId)
        {
            AdminSupportClient adminClient = new AdminSupportClient(Properties.Settings.Default.AdminSupportEndpoint);
            Guid organizationId            = Guid.Empty;

            try
            {
                AdminSupportReference.MethodResponseguid response;
                String currentOrganization;

                lock (DataModel.SyncRoot)
                    currentOrganization = DataModel.User.UserKey.Find(UserContext.Instance.UserId).TenantRow.ExternalId0;

                response = adminClient.AddOrganization(name, currentOrganization);
                adminClient.Close();

                if (!response.IsSuccessful)
                {
                    if (response.Errors.Length > 0)
                    {
                        GuardianObject.ThrowErrorInfo(response.Errors[0]);
                    }
                    else
                    {
                        throw new Exception("Unknown error occured");
                    }
                }
                else
                {
                    organizationId = response.Result;
                }
            }
            catch
            {
                MessageBox.Show(Properties.Resources.OperationFailed);
                return;
            }

            try
            {
                Guid parentId;

                lock (DataModel.SyncRoot)
                    parentId = FindUserFolder();

                Guid entityId = Entity.Create(typeId, parentId, organizationId);
                TradingSupportReference.TradingSupportClient client = new TradingSupportReference.TradingSupportClient(Properties.Settings.Default.TradingSupportEndpoint);
                client.UpdateEntity(new TradingSupportReference.Entity[] { new TradingSupportReference.Entity()
                                                                           {
                                                                               RowId = entityId, Name = name
                                                                           } });
            }
            catch
            {
                MessageBox.Show(Properties.Resources.OperationFailed);
                return;
            }
        }
コード例 #4
0
        /// <summary>
        /// Remove a user.
        /// </summary>
        /// <param name="user">The user to remove.</param>
        private void RemoveUser(User user)
        {
            try
            {
                AdminSupportClient adminSupportClient = new AdminSupportClient(Guardian.Properties.Settings.Default.AdminSupportEndpoint);

                adminSupportClient.DisableUserAccount(user.IdentityName);
                adminSupportClient.Close();
            }
            catch (Exception exception)
            {
                // Any issues trying to communicate to the server are logged.
                EventLog.Error("{0}: {1}\n{2}", exception.GetType(), exception.Message, exception.StackTrace);
                this.Dispatcher.BeginInvoke(new Action(() =>
                                                       MessageBox.Show(this, String.Format(Properties.Resources.DeleteUserFailed, user), this.Title)));
            }
        }
コード例 #5
0
        /// <summary>
        /// Set the user's password to the new password.
        /// </summary>
        /// <param name="user">The user to change.</param>
        /// <param name="oldPassword">The current password.</param>
        /// <param name="password">The new password.</param>
        private void ResetPassword(User user, string oldPassword, string password)
        {
            try
            {
                AdminSupportClient         adminSupportClient = new AdminSupportClient(Guardian.Properties.Settings.Default.AdminSupportEndpoint);
                AdminSupportReference.User userRecord         = new AdminSupportReference.User();
                MethodResponseErrorCode    response           = null;

                DataModel.IsReading = false;

                if (user.UserId == UserContext.Instance.UserId)
                {
                    response = adminSupportClient.ChangePassword(oldPassword, password);

                    if (response.IsSuccessful)
                    {
                        ChannelStatus.LoginEvent.Set();
                        ChannelStatus.IsPrompted = false;
                        ChannelStatus.Secret     = password;
                        ChannelStatus.LogggedInEvent.Set();
                    }
                }
                else
                {
                    response = adminSupportClient.ResetPassword(user.IdentityName, password);
                }

                if (!response.IsSuccessful)
                {
                    GuardianObject.ThrowErrorInfo(response.Errors[0]);
                }

                adminSupportClient.Close();
            }
            catch (FaultException <ArgumentFault> )
            {
                this.Dispatcher.BeginInvoke(new Action(() =>
                                                       MessageBox.Show(this, String.Format(Properties.Resources.ResetPasswordFailedPoorComplexity, user), this.Title)));
            }
            catch (SecurityAccessDeniedException)
            {
                this.Dispatcher.BeginInvoke(new Action(() =>
                                                       MessageBox.Show(this, String.Format(Properties.Resources.UserNotFound, user), this.Title)));
            }
            catch (FaultException <RecordNotFoundFault> )
            {
                this.Dispatcher.BeginInvoke(new Action(() =>
                                                       MessageBox.Show(this, String.Format(Properties.Resources.ResetPasswordFailedPermissionDenied, user), this.Title)));
            }
            catch (Exception exception)
            {
                // Any issues trying to communicate to the server are logged.
                EventLog.Error("{0}, {1}", exception.Message, exception.StackTrace);
                this.Dispatcher.BeginInvoke(new Action(() =>
                                                       MessageBox.Show(this, String.Format(Properties.Resources.ResetPasswordFailed, user.Name), this.Title)));
            }
            finally
            {
                DataModel.IsReading = true;
            }
        }
コード例 #6
0
ファイル: User.cs プロジェクト: radtek/credit-card-exchange
        /// <summary>
        /// Commit any changes to this user to the server.
        /// </summary>
        public override void Commit()
        {
            AdminSupportClient client = new AdminSupportClient(Guardian.Properties.Settings.Default.AdminSupportEndpoint);

            AdminSupportReference.User user = new AdminSupportReference.User();
            MethodResponseErrorCode    response;

            this.PopulateRecord(user);

            if (this.Deleted)
            {
                response = client.DeleteUserAccount(user.LookupId);

                if (this.GetFirstErrorCode(response) == ErrorCode.RecordNotFound)
                {
                    throw new UserNotFoundException(this, "User not found");
                }
            }
            else
            {
                response = client.UpdateUser(new AdminSupportReference.User[] { user });

                if (this.GetFirstErrorCode(response) == ErrorCode.RecordNotFound)
                {
                    throw new UserNotFoundException(this, "User not found");
                }

                if (response.IsSuccessful)
                {
                    if (this.AccountDisabled)
                    {
                        response = client.DisableUserAccount(this.IdentityName);
                    }
                }

                if (response.IsSuccessful)
                {
                    lock (DataModel.SyncRoot)
                    {
                        List <Group>    newGroups = this.Groups.ToList();
                        List <Guid>     add       = new List <Guid>();
                        List <Guid>     del       = new List <Guid>();
                        GroupUsersRow[] oldGroups = DataModel.User.UserKey.Find(this.UserId).GetGroupUsersRows();
                        ErrorCode       firstError;

                        foreach (GroupUsersRow groupUsersRow in oldGroups)
                        {
                            Group group = newGroups.FirstOrDefault(g => g.GroupId == groupUsersRow.GroupId);

                            if (group == null)
                            {
                                del.Add(groupUsersRow.GroupId);
                            }
                            else
                            {
                                if (group.Deleted)
                                {
                                    del.Add(group.GroupId);
                                }
                                newGroups.Remove(group);
                            }
                        }

                        foreach (Group group in newGroups)
                        {
                            response = client.AddUserToGroup(this.IdentityName, group.GroupId, this.TenantId);

                            firstError = this.GetFirstErrorCode(response);

                            if (firstError == ErrorCode.RecordNotFound)
                            {
                                throw new GroupNotFoundException(this.DefaultGroup, "Group not found");
                            }
                            else if (firstError != ErrorCode.Success)
                            {
                                break;
                            }
                        }

                        foreach (Guid group in del)
                        {
                            response = client.RemoveUserFromGroup(this.IdentityName, group);

                            firstError = this.GetFirstErrorCode(response);

                            if (firstError != ErrorCode.RecordNotFound && firstError != ErrorCode.Success)
                            {
                                break;
                            }
                        }
                    }
                }
            }

            if (!response.IsSuccessful)
            {
                GuardianObject.ThrowErrorInfo(response.Errors[0]);
            }

            client.Close();

            this.Modified = false;
        }