Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Purge Expired JWT tokens task #4126

Merged
merged 1 commit into from
Sep 24, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Purge Expired JWT tokens task
  • Loading branch information
donker committed Sep 24, 2020

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
commit a56cf00b486ef88fc346a43f2bd783264290bf7f
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);
}
}
}
}
2 changes: 1 addition & 1 deletion DNN Platform/Dnn.AuthServices.Jwt/Data/DataService.cs
Original file line number Diff line number Diff line change
@@ -72,7 +72,7 @@ public virtual void DeleteUserTokens(int userId)

public virtual void DeleteExpiredTokens()
{
// don't worry aabout caching; these will already be invalidated by cache manager
// don't worry about caching; these will already be invalidated by cache manager
this._dataProvider.ExecuteNonQuery("JsonWebTokens_DeleteExpired");
}

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

Original file line number Diff line number Diff line change
@@ -42,6 +42,9 @@ IF OBJECT_ID(N'{databaseOwner}{objectQualifier}JsonWebTokens', N'U') IS NOT NULL
DROP TABLE {databaseOwner}[{objectQualifier}JsonWebTokens]
GO

DELETE FROM {databaseOwner}{objectQualifier}Schedule WHERE TypeFullName = 'Dnn.AuthServices.Jwt.Components.Schedule.PurgeExpiredTokensTask, Dnn.AuthServices.Jwt'
GO

/************************************************************/
/***** SqlDataProvider *****/
/************************************************************/
2 changes: 2 additions & 0 deletions DNN Platform/Dnn.AuthServices.Jwt/Dnn.AuthServices.Jwt.csproj
Original file line number Diff line number Diff line change
@@ -73,6 +73,7 @@
<Compile Include="Components\Entity\LoginData.cs" />
<Compile Include="Components\Entity\PersistedToken.cs" />
<Compile Include="Components\Entity\RenewalDto.cs" />
<Compile Include="Components\Schedule\PurgeExpiredTokensTask.cs" />
<Compile Include="Data\IDataService.cs" />
<Compile Include="Data\DataService.cs" />
<Compile Include="Components\Entity\LoginResultData.cs" />
@@ -84,6 +85,7 @@
<AdditionalFiles Include="..\..\stylecop.json">
<Link>stylecop.json</Link>
</AdditionalFiles>
<Content Include="Data\Scripts\09.08.00.SqlDataProvider" />
<None Include="Dnn.Jwt.dnn">
<SubType>Designer</SubType>
</None>
7 changes: 6 additions & 1 deletion DNN Platform/Dnn.AuthServices.Jwt/Dnn.Jwt.dnn
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<dotnetnuke type="Package" version="5.0">
<packages>
<package name="DNNJWT" type="Provider" version="09.07.02">
<package name="DNNJWT" type="Provider" version="09.08.00">
<friendlyName>DNN JWT Auth Handler</friendlyName>
<description>DNN Json Web Token Authentication (JWT) library for cookie-less Mobile authentication clients</description>
<dependencies/>
@@ -37,6 +37,11 @@
<name>01.00.00.SqlDataProvider</name>
<version>01.00.00</version>
</script>
<script type="Install">
<path>Data\Scripts</path>
<name>09.08.00.SqlDataProvider</name>
<version>09.08.00</version>
</script>
<script type="UnInstall">
<path>Data\Scripts</path>
<name>Uninstall.SqlDataProvider</name>