From ecca480334bf5dac1e937848d1ba86ccec7e5552 Mon Sep 17 00:00:00 2001 From: Sebastiaan Janssen Date: Sat, 29 Apr 2017 12:24:10 +0200 Subject: [PATCH] Get backoffice identity from cookie instead of grabbing it from database --- .../Auditing/IdentityAuditEventArgs.cs | 22 +++++++++---------- src/Umbraco.Core/Umbraco.Core.csproj | 3 +++ src/Umbraco.Core/packages.config | 1 + 3 files changed, 14 insertions(+), 12 deletions(-) diff --git a/src/Umbraco.Core/Auditing/IdentityAuditEventArgs.cs b/src/Umbraco.Core/Auditing/IdentityAuditEventArgs.cs index 7fb01791ba..27e6dc69c3 100644 --- a/src/Umbraco.Core/Auditing/IdentityAuditEventArgs.cs +++ b/src/Umbraco.Core/Auditing/IdentityAuditEventArgs.cs @@ -1,5 +1,7 @@ using System; using System.Web; +using Microsoft.AspNet.Identity; +using Microsoft.AspNet.Identity.Owin; using Umbraco.Core.Security; namespace Umbraco.Core.Auditing @@ -43,18 +45,14 @@ namespace Umbraco.Core.Auditing /// protected int GetCurrentRequestBackofficeUserId() { - if (HttpContext.Current == null) return 0; - - var authenticationTicket = new HttpContextWrapper(HttpContext.Current).GetUmbracoAuthTicket(); - if (authenticationTicket != null) - { - var currentBackofficeUser = ApplicationContext.Current.Services.UserService.GetByUsername(authenticationTicket.Name); - if (currentBackofficeUser != null) - return currentBackofficeUser.Id; - } - - // couldn't get auth ticket or current user, return default user (0) - return 0; + var userId = 0; + if (HttpContext.Current == null) return userId; + var owinContext = HttpContext.Current.GetOwinContext(); + if (owinContext == null) return userId; + var backOfficeIdentity = owinContext.Authentication.User.GetUmbracoIdentity(); + if (backOfficeIdentity != null) + int.TryParse(backOfficeIdentity.Id.ToString(), out userId); + return userId; } } diff --git a/src/Umbraco.Core/Umbraco.Core.csproj b/src/Umbraco.Core/Umbraco.Core.csproj index 9603415025..8b785e1a2b 100644 --- a/src/Umbraco.Core/Umbraco.Core.csproj +++ b/src/Umbraco.Core/Umbraco.Core.csproj @@ -74,6 +74,9 @@ ..\packages\Microsoft.Owin.3.0.1\lib\net45\Microsoft.Owin.dll True + + ..\packages\Microsoft.Owin.Host.SystemWeb.3.0.1\lib\net45\Microsoft.Owin.Host.SystemWeb.dll + ..\packages\Microsoft.Owin.Security.3.0.1\lib\net45\Microsoft.Owin.Security.dll True diff --git a/src/Umbraco.Core/packages.config b/src/Umbraco.Core/packages.config index 191eb11c01..9268232097 100644 --- a/src/Umbraco.Core/packages.config +++ b/src/Umbraco.Core/packages.config @@ -8,6 +8,7 @@ +