public string AcquireToken(string userLogin, string userPassword, Guid projectGuid) { var guidCheckResult = GuidUniquenessCheck(projectGuid); if (guidCheckResult != null) { return(guidCheckResult); } // policies check try { var projectId = _projectRepository.GetByGuid(projectGuid).Id; var policyTuples = _getPoliciesFromProjectFactory.Create().Invoke(projectId).WithTypes(PolicyType.LogIn); var user = _userRepository.FindBy(u => u.Login == userLogin).FirstOrDefault(); if (user != null) { var userId = user.Id; var userLastPasswordChange = user.LastPasswordChange; foreach (var policyTuple in policyTuples) { switch (policyTuple.Item1) { case Policy.AccountExpirationDate: var userConfiguration = (UserAccountExpirationDateConfiguration) userConfigurationOrDefaultFromProjectFactory.Create() .Invoke(userId, Policy.AccountExpirationDate, projectId); if ( !Check.AccountExpirationDate( (AccountExpirationDateConfiguration)policyTuple.Item2, userConfiguration)) { return new JsonObject { Result = JsonValues.AccountExpired } } .ToJson(); break; case Policy.PasswordExpirationDate: if ( !Check.PasswordExpirationDate( (PasswordExpirationDateConfiguration)policyTuple.Item2, userLastPasswordChange)) { return new JsonObject { Result = JsonValues.PasswordExpired } }
public void AccountExpirationDateCheckShouldReturnTrueBecauseUserAccountExpirationDateIsNotSet() { // arrange var configuration = new AccountExpirationDateConfiguration { IsEnabled = true }; var userConfiguration = new UserAccountExpirationDateConfiguration { ExpirationDate = default(DateTime) }; // act var checkResult = Check.AccountExpirationDate(configuration, userConfiguration); // assert Assert.True(checkResult); }
public void AccountExpirationDateCheckShouldReturnTrueBecauseOfNotEnabled() { // arrange var configuration = new AccountExpirationDateConfiguration { IsEnabled = false }; var userConfiguration = new UserAccountExpirationDateConfiguration { ExpirationDate = DateTime.Now.AddDays(1) }; // act var checkResult = Check.AccountExpirationDate(configuration, userConfiguration); // assert Assert.True(checkResult); }