-
Notifications
You must be signed in to change notification settings - Fork 754
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Purge Expired JWT tokens task (#4126)
- Loading branch information
Showing
6 changed files
with
106 additions
and
2 deletions.
There are no files selected for viewing
52 changes: 52 additions & 0 deletions
52
DNN Platform/Dnn.AuthServices.Jwt/Components/Schedule/PurgeExpiredTokensTask.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information | ||
|
||
namespace Dnn.AuthServices.Jwt.Components.Schedule | ||
{ | ||
using System; | ||
|
||
using Dnn.AuthServices.Jwt.Data; | ||
using DotNetNuke.Instrumentation; | ||
using DotNetNuke.Services.Exceptions; | ||
using DotNetNuke.Services.Scheduling; | ||
|
||
/// <summary> | ||
/// Scheduled task to delete tokens that linger in the database after having expired | ||
/// </summary> | ||
public class PurgeExpiredTokensTask : SchedulerClient | ||
{ | ||
private static readonly ILog Logger = LoggerSource.Instance.GetLogger(typeof(PurgeExpiredTokensTask)); | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="PurgeExpiredTokensTask"/> class. | ||
/// </summary> | ||
/// <param name="objScheduleHistoryItem">The object used to record the results from this task</param> | ||
public PurgeExpiredTokensTask(ScheduleHistoryItem objScheduleHistoryItem) | ||
{ | ||
this.ScheduleHistoryItem = objScheduleHistoryItem; | ||
} | ||
|
||
/// <summary> | ||
/// Runs when the task is triggered by DNN. | ||
/// </summary> | ||
public override void DoWork() | ||
{ | ||
try | ||
{ | ||
Logger.Info("Starting PurgeExpiredTokensTask"); | ||
DataService.Instance.DeleteExpiredTokens(); | ||
Logger.Info("Finished PurgeExpiredTokensTask"); | ||
this.ScheduleHistoryItem.Succeeded = true; | ||
} | ||
catch (Exception exc) | ||
{ | ||
this.ScheduleHistoryItem.Succeeded = false; | ||
this.ScheduleHistoryItem.AddLogNote(string.Format("Purging expired tokens task failed: {0}.", exc.ToString())); | ||
this.Errored(ref exc); | ||
Logger.ErrorFormat("Error in PurgeExpiredTokensTask: {0}. {1}", exc.Message, exc.StackTrace); | ||
Exceptions.LogException(exc); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
DNN Platform/Dnn.AuthServices.Jwt/Data/Scripts/09.08.00.SqlDataProvider
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* Add Schedule Job */ | ||
/*************************************/ | ||
IF NOT EXISTS(SELECT 1 FROM {databaseOwner}{objectQualifier}Schedule WHERE TypeFullName = 'Dnn.AuthServices.Jwt.Components.Schedule.PurgeExpiredTokensTask, Dnn.AuthServices.Jwt') | ||
BEGIN | ||
INSERT INTO {databaseOwner}{objectQualifier}Schedule | ||
( [TypeFullName] | ||
,[TimeLapse] | ||
,[TimeLapseMeasurement] | ||
,[RetryTimeLapse] | ||
,[RetryTimeLapseMeasurement] | ||
,[RetainHistoryNum] | ||
,[AttachToEvent] | ||
,[CatchUpEnabled] | ||
,[Enabled] | ||
,[ObjectDependencies] | ||
,[Servers] | ||
,[CreatedByUserID] | ||
,[CreatedOnDate] | ||
,[LastModifiedByUserID] | ||
,[LastModifiedOnDate] | ||
,[FriendlyName] | ||
) VALUES | ||
( 'Dnn.AuthServices.Jwt.Components.Schedule.PurgeExpiredTokensTask, Dnn.AuthServices.Jwt' | ||
,1 | ||
,N'd' | ||
,6 | ||
,N'h' | ||
,10 | ||
,N'' | ||
,0 | ||
,1 | ||
,N'' | ||
,NULL | ||
,NULL | ||
,NULL | ||
,NULL | ||
,NULL | ||
,N'Purge Expired JWT Tokens' | ||
) | ||
END | ||
GO | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters