示例#1
0
 public LoginCollection FetchAll()
 {
     LoginCollection coll = new LoginCollection();
     Query qry = new Query(Login.Schema);
     coll.LoadAndCloseReader(qry.ExecuteReader());
     return coll;
 }
示例#2
0
        public override int GetPasswordFailuresSinceLastSuccess(string userName)
        {
            User user = User.GetByUserName(userName);

            if (user == null)
            {
                return(-1);
            }

            OrderBy <LoginColumns>    ob          = new OrderBy <LoginColumns>(c => c.DateTime, SortOrder.Descending);
            LoginCollection           latestLogin = Login.Where(c => c.UserId == user.Id, ob);
            PasswordFailureCollection failures    = PasswordFailure.Where(c => c.UserId == user.Id);
            List <PasswordFailure>    sinceLast   = new List <PasswordFailure>();

            if (latestLogin.Count > 0)
            {
                DateTime since = latestLogin[0].DateTime.Value;
                foreach (PasswordFailure failure in failures)
                {
                    if (failure.DateTime > since)
                    {
                        sinceLast.Add(failure);
                    }
                }
            }

            return(sinceLast.Count);
        }
示例#3
0
        public LoginDevicesViewModel(IPpsClientViewModel ppsClientViewModel)
        {
            _ppsClientViewModel = ppsClientViewModel;
            _ppsClientViewModel.OnEmbeddedCollectionRefreshed += _ppsClientViewModel_OnEmbeddedCollectionRefreshed;
            SaveLoginDevicesCmd = new RelayCommand(SaveLoginDevices);
            GetLoginIdAndDeviceIdDct();
            UpdateLoginDeviceCollection();

            if (LoginCollection != null && LoginCollection.Any())
            {
                SelectedLogin = LoginCollection.FirstOrDefault();
            }
        }
示例#4
0
 public ActionResult Save(Bam.Net.UserAccounts.Data.Login[] values)
 {
     try
     {
         LoginCollection saver = new LoginCollection();
         saver.AddRange(values);
         saver.Save();
         return(Json(new { Success = true, Message = "", Dao = "" }));
     }
     catch (Exception ex)
     {
         return(GetErrorResult(ex));
     }
 }
示例#5
0
        public PolicySetViewModel(IPpsClientViewModel ppsClientViewModel)
        {
            _ppsClientViewModel = ppsClientViewModel;
            _ppsClientViewModel.OnEmbeddedCollectionRefreshed += _ppsClientViewModel_OnEmbeddedCollectionRefreshed;
            SavePolicySetCmd = new RelayCommand(SavePolicySet);
            GetGroupIdAndPolicyIdDct();
            UpdateSelectedPolicyCollection();
            IsUserPolicySet = true;

            if (LoginCollection != null && LoginCollection.Any())
            {
                SelectedLogin = LoginCollection.FirstOrDefault();
            }
        }
示例#6
0
        public override bool DeleteUser(string username, bool deleteAllRelatedData)
        {
            User user   = User.GetByUserName(username);
            bool result = false;

            try
            {
                if (user != null)
                {
                    user.IsDeleted  = true;
                    user.IsApproved = false;
                    user.Save();
                    if (deleteAllRelatedData)
                    {
                        UserRoleCollection         roles     = UserRole.Where(c => c.UserId == user.Id);
                        AccountCollection          accounts  = Account.Where(c => c.UserId == user.Id);
                        PasswordCollection         passwords = Password.Where(c => c.UserId == user.Id);
                        PasswordResetCollection    resets    = PasswordReset.Where(c => c.UserId == user.Id);
                        PasswordFailureCollection  failures  = PasswordFailure.Where(c => c.UserId == user.Id);
                        LockOutCollection          lockouts  = LockOut.Where(c => c.UserId == user.Id);
                        LoginCollection            logins    = Login.Where(c => c.UserId == user.Id);
                        PasswordQuestionCollection questions = PasswordQuestion.Where(c => c.UserId == user.Id);
                        SettingCollection          settings  = Setting.Where(c => c.UserId == user.Id);

                        SessionCollection session = Session.Where(c => c.UserId == user.Id);

                        Database         db  = Db.For <User>();
                        SqlStringBuilder sql = db.ServiceProvider.Get <SqlStringBuilder>();
                        roles.WriteDelete(sql);
                        accounts.WriteDelete(sql);
                        passwords.WriteDelete(sql);
                        resets.WriteDelete(sql);
                        failures.WriteDelete(sql);
                        lockouts.WriteDelete(sql);
                        logins.WriteDelete(sql);
                        questions.WriteDelete(sql);
                        settings.WriteDelete(sql);
                        session.WriteDelete(sql);

                        sql.Execute(db);
                    }
                }
            }
            catch (Exception ex)
            {
                result = false;
                Log.AddEntry("{0}.{1}::{2}", ex, this.GetType().Name, MethodBase.GetCurrentMethod().Name, ex.Message);
            }
            return(result);
        }
示例#7
0
        private LoginCollection InitializeCollection(DataTable dt)
        {
            LoginCollection retval = null;

            if (dt != null && dt.Columns.Count > 0)
            {
                retval = new LoginCollection();
                foreach (DataRow row in dt.Rows)
                {
                    Login item = InitializeObject(row);
                    retval.Add(item);
                }
            }
            return(retval);
        }
示例#8
0
        /// <summary>
        /// Script the Server Logins
        /// </summary>
        /// <param name="l">LoginCollection</param>
        private void ScriptLogins(LoginCollection l)
        {
            string path  = String.Format(@"{0}\Logins", m_Server);
            int    files = 0;

            if (l.Count > 0)
            {
                if (Directory.Exists(path) == false)
                {
                    Directory.CreateDirectory(path);
                }
                else
                {
                    DeleteAllSQLFiles(path);
                }

                //
                // Loop over all the SQL Agent jobs
                //
                foreach (Login login in l)
                {
                    //
                    // Create the script
                    //
                    m_ScriptingOptions.FileName = Path.Combine(path, ConvertToFileName(login.Name.ToString()));
                    SendLogMessage(null, login.Name, m_ScriptingOptions.FileName, SQLServerScripterType.Login);
                    login.Script(m_ScriptingOptions);
                    Login_FixupRandomPassword(m_ScriptingOptions.FileName);
                    files++;
                }
            }
            if (files == 0 && Directory.Exists(path))
            {
                Directory.Delete(path, true);
            }
        }
示例#9
0
        private void SavePolicySet(object parameter)
        {
            var loginListToUpdate = new List <long>();

            try
            {
                if (IsUserPolicySet && SelectedLogin == null)
                {
                    throw new Exception("Пользователь не выбран");
                }

                if (IsGroupPolicySet && SelectedGroup == null)
                {
                    throw new Exception("Группа не выбрана");
                }

                using (var policySetService =
                           _ppsClientViewModel.ServiceProxy.GetPpsChannelFactory <IPolicySetService>())
                {
                    var             channel        = policySetService.CreateChannel();
                    var             groupId        = IsGroupPolicySet ? SelectedGroup.GroupId : SelectedLogin.GroupId;
                    var             groupPolicySet = channel.GetPolicySetForGroup(groupId).SomeResult;
                    Result <object> res            = null;

                    if (IsGroupPolicySet)
                    {
                        loginListToUpdate =
                            LoginCollection.Where(x => x.GroupId == groupId).Select(x => x.LoginId).ToList();

                        foreach (var selectedPolicy in PolicyCollection)
                        {
                            res = null;
                            var containedGroup =
                                groupPolicySet.FirstOrDefault(x => x.PolicyId == selectedPolicy.PolicyId);

                            if (selectedPolicy.IsSelected)
                            {
                                if (containedGroup == null)
                                {
                                    res = channel.AddPolicySet(new PolicySetDataContract
                                    {
                                        PolicyId    = selectedPolicy.PolicyId,
                                        GroupId     = groupId,
                                        PolicyParam = selectedPolicy.PolicyParam
                                    });
                                }
                                else
                                {
                                    res =
                                        channel.UpdatePolicySet(
                                            new PolicySetDataContract {
                                        PolicySetId = containedGroup.PolicySetId
                                    },
                                            new PolicySetDataContract
                                    {
                                        PolicyId    = selectedPolicy.PolicyId,
                                        GroupId     = groupId,
                                        PolicyParam = selectedPolicy.PolicyParam
                                    });
                                }
                            }
                            else
                            {
                                if (containedGroup != null)
                                {
                                    res = channel.DeletePolicySet(new PolicySetDataContract
                                    {
                                        PolicySetId = containedGroup.PolicySetId,
                                        PolicyId    = selectedPolicy.PolicyId,
                                        GroupId     = groupId
                                    });
                                }
                            }

                            if (res != null && !res.BoolRes)
                            {
                                _ppsClientViewModel.WriteLogMessage(
                                    string.Concat("Не удалось сохранить набор политик - ", res.ErrorRes));
                            }
                        }

                        GetGroupIdAndPolicyIdDct();
                        _ppsClientViewModel.AddEvent(EventConstants.EVENT_ASSIGN_lOGIN_POLICY,
                                                     string.Concat("Для группы ", SelectedGroup.GroupName));
                    }
                    else
                    {
                        loginListToUpdate.Add(SelectedLogin.LoginId);
                        var policySetForLoginInTbl =
                            channel.GetPolicySet(new PolicySetDataContract {
                            LoginId = SelectedLogin.LoginId
                        }).SomeResult;

                        foreach (var selectedPolicy in PolicyCollection)
                        {
                            res = null;
                            var containedGroup =
                                groupPolicySet.FirstOrDefault(x => x.PolicyId == selectedPolicy.PolicyId);
                            var containedInTbl =
                                policySetForLoginInTbl.FirstOrDefault(x => x.PolicyId == selectedPolicy.PolicyId);

                            if (selectedPolicy.IsSelected)
                            {
                                if (containedGroup == null)
                                {
                                    if (containedInTbl != null)
                                    {
                                        res = channel.UpdatePolicySet(new PolicySetDataContract
                                        {
                                            PolicySetId = containedInTbl.PolicySetId
                                        },
                                                                      new PolicySetDataContract
                                        {
                                            PolicySetId = containedInTbl.PolicySetId,
                                            PolicyId    = selectedPolicy.PolicyId,
                                            LoginId     = SelectedLogin.LoginId,
                                            Selected    = selectedPolicy.IsSelected,
                                            PolicyParam = selectedPolicy.PolicyParam
                                        }
                                                                      );
                                    }
                                    else
                                    {
                                        res = channel.AddPolicySet(new PolicySetDataContract
                                        {
                                            PolicyId    = selectedPolicy.PolicyId,
                                            LoginId     = SelectedLogin.LoginId,
                                            Selected    = selectedPolicy.IsSelected,
                                            PolicyParam = selectedPolicy.PolicyParam
                                        });
                                    }
                                }
                                else
                                {
                                    if (containedInTbl != null)
                                    {
                                        res = channel.DeletePolicySet(new PolicySetDataContract
                                        {
                                            PolicySetId = containedInTbl.PolicySetId
                                        });
                                    }
                                }
                            }
                            else
                            {
                                if (containedGroup == null)
                                {
                                    if (containedInTbl != null)
                                    {
                                        res = channel.DeletePolicySet(new PolicySetDataContract
                                        {
                                            PolicySetId = containedInTbl.PolicySetId
                                        });
                                    }
                                }
                                else
                                {
                                    if (containedInTbl != null)
                                    {
                                        res = channel.UpdatePolicySet(new PolicySetDataContract
                                        {
                                            PolicySetId = containedInTbl.PolicySetId
                                        },
                                                                      new PolicySetDataContract
                                        {
                                            PolicySetId = containedInTbl.PolicySetId,
                                            PolicyId    = selectedPolicy.PolicyId,
                                            LoginId     = SelectedLogin.LoginId,
                                            Selected    = selectedPolicy.IsSelected,
                                            PolicyParam = selectedPolicy.PolicyParam
                                        }
                                                                      );
                                    }
                                    else
                                    {
                                        res = channel.AddPolicySet(new PolicySetDataContract
                                        {
                                            PolicyId    = selectedPolicy.PolicyId,
                                            LoginId     = SelectedLogin.LoginId,
                                            Selected    = selectedPolicy.IsSelected,
                                            PolicyParam = selectedPolicy.PolicyParam
                                        });
                                    }
                                }
                            }

                            if (res != null && !res.BoolRes)
                            {
                                _ppsClientViewModel.WriteLogMessage(
                                    string.Concat("Не удалось сохранить набор политик - ", res.ErrorRes));
                            }
                        }

                        _ppsClientViewModel.AddEvent(EventConstants.EVENT_ASSIGN_lOGIN_POLICY,
                                                     string.Concat("Для логина ", SelectedLogin.Login));
                    }
                }
            }
            catch (Exception ex)
            {
                _ppsClientViewModel.WriteLogMessage(string.Concat("Не удалось сохранить набор политик - ", ex.Message));
            }
            finally
            {
                SetLoginDevicesForUpdate(loginListToUpdate);
            }
        }
示例#10
0
 public LoginCollection FetchByUserNameAndPassword(object pUser, object pPassword)
 {
     LoginCollection coll = new LoginCollection().Where("userName", pUser).Where("password", pPassword).Load();
     return coll;
 }
示例#11
0
 public LoginCollection FetchByQuery(Query qry)
 {
     LoginCollection coll = new LoginCollection();
     coll.LoadAndCloseReader(qry.ExecuteReader());
     return coll;
 }
示例#12
0
 public LoginCollection FetchByID(object LoginId)
 {
     LoginCollection coll = new LoginCollection().Where("loginId", LoginId).Load();
     return coll;
 }
        public static void DeleteAllLogins()
        {
            LoginCollection logins = Login.LoadAll();

            logins.Delete();
        }
示例#14
0
        public LoginCollection GetLogins()
        {
            LoginCollection logins = new LoginCollection();

            return(logins);
        }
 public LoginAuthenticator(IServiceProvider serviceProvider, LoginCollection loginCollection, ILogger <LoginAuthenticator> logger)
 {
     _serviceProvider = serviceProvider ?? throw new ArgumentNullException(nameof(serviceProvider));
     _loginCollection = loginCollection ?? throw new ArgumentNullException(nameof(loginCollection));
     _logger          = logger ?? throw new ArgumentNullException(nameof(logger));
 }