public void WithoutLegacyFallbackInvalidTokenShouldNotAllowLogin() { var rockContext = new RockContext(); var personTokenService = new PersonTokenService(rockContext); var token = "TokenProhibited"; GlobalAttributesCache globalAttributes = GlobalAttributesCache.Get(); globalAttributes.SetValue("core.PersonTokenUseLegacyFallback", "false", false); var personFromToken = personTokenService.GetByImpersonationToken(token); Assert.That.IsNull(personFromToken); }
public void WithoutLegacyFallbackValidTokenShouldAllowLogin() { var rockContext = new RockContext(); var personService = new PersonService(rockContext); var personTokenService = new PersonTokenService(rockContext); var personWithLowAccountProtectionProfile = personService.Get(PersonGuid.PersonWithLowAccountProtectionProfileGuid.AsGuid()); GlobalAttributesCache globalAttributes = GlobalAttributesCache.Get(); globalAttributes.SetValue("core.PersonTokenUseLegacyFallback", "false", false); var token = personWithLowAccountProtectionProfile.GetImpersonationToken(); Assert.That.IsNotNull(token); var personFromToken = personTokenService.GetByImpersonationToken(token); Assert.That.Equal(PersonGuid.PersonWithLowAccountProtectionProfileGuid.AsGuid(), personFromToken.PersonAlias.Person.Guid); }
/// <summary> /// Cleanups the person tokens. /// </summary> /// <param name="dataMap">The data map.</param> /// <returns></returns> private int CleanupPersonTokens(JobDataMap dataMap) { int totalRowsDeleted = 0; int?batchAmount = dataMap.GetString("BatchCleanupAmount").AsIntegerOrNull() ?? 1000; // Cleanup PersonTokens records that are expired using (RockContext rockContext = new RockContext()) { PersonTokenService personTokenService = new PersonTokenService(rockContext); // delete in chunks (see http://dba.stackexchange.com/questions/1750/methods-of-speeding-up-a-huge-delete-from-table-with-no-clauses) bool keepDeleting = true; while (keepDeleting) { var dbTransaction = rockContext.Database.BeginTransaction(); try { string sqlCommand = @" DELETE TOP (@batchAmount) FROM [PersonToken] WHERE ExpireDateTime IS NOT NULL AND ExpireDateTime < GetDate() "; int rowsDeleted = rockContext.Database.ExecuteSqlCommand(sqlCommand, new SqlParameter("batchAmount", batchAmount)); keepDeleting = rowsDeleted > 0; totalRowsDeleted += rowsDeleted; } finally { dbTransaction.Commit(); } } } return(totalRowsDeleted); }