diff --git a/src/Umbraco.Core/Auditing/IdentityAuditEventArgs.cs b/src/Umbraco.Core/Auditing/IdentityAuditEventArgs.cs
index 55d8386d21..dc91bb77b0 100644
--- a/src/Umbraco.Core/Auditing/IdentityAuditEventArgs.cs
+++ b/src/Umbraco.Core/Auditing/IdentityAuditEventArgs.cs
@@ -5,13 +5,39 @@ using Umbraco.Core.Security;
namespace Umbraco.Core.Auditing
{
+ ///
+ /// This class is used by events raised from hthe BackofficeUserManager
+ ///
public class IdentityAuditEventArgs : EventArgs
{
+ ///
+ /// The action that got triggered from the audit event
+ ///
public AuditEvent Action { get; set; }
+
+ ///
+ /// Current data/time in UTC format
+ ///
public DateTime DateTimeUtc { get; private set; }
+
+ ///
+ /// The source IP address of the user performing the action
+ ///
public string IpAddress { get; set; }
+
+ ///
+ /// The user affected by the event raised
+ ///
public int AffectedUser { get; set; }
+
+ ///
+ /// If a user is perfoming an action on a different user then this will be set, otherwise it will be -1
+ ///
public int PerformingUser { get; set; }
+
+ ///
+ /// An optional comment about the action being logged
+ ///
public string Comment { get; set; }
///
@@ -19,6 +45,12 @@ namespace Umbraco.Core.Auditing
///
public string Username { get; set; }
+ ///
+ /// Sets the properties on the event being raised, all parameters are optional except for the action being performed
+ ///
+ /// An action based on the AuditEvent enum
+ /// The client's IP address. This is usually automatically set but could be overridden is necessary
+ /// The Id of the user performing the action (if different from the user affected by the action)
public IdentityAuditEventArgs(AuditEvent action, string ipAddress = "", int performingUser = -1)
{
DateTimeUtc = DateTime.UtcNow;
diff --git a/src/Umbraco.Core/Security/BackOfficeUserManager.cs b/src/Umbraco.Core/Security/BackOfficeUserManager.cs
index bec2b657b2..3f96b5b3b1 100644
--- a/src/Umbraco.Core/Security/BackOfficeUserManager.cs
+++ b/src/Umbraco.Core/Security/BackOfficeUserManager.cs
@@ -244,15 +244,9 @@ namespace Umbraco.Core.Security
// The way we unlock is by setting the lockoutEnd date to the current datetime
if (result.Result.Succeeded && lockoutEnd >= DateTimeOffset.UtcNow)
- OnAccountLocked(new IdentityAuditEventArgs(AuditEvent.AccountLocked)
- {
- AffectedUser = userId
- });
+ RaiseAccountLockedEvent(userId);
else
- OnAccountUnlocked(new IdentityAuditEventArgs(AuditEvent.AccountUnlocked)
- {
- AffectedUser = userId
- });
+ RaiseAccountUnlockedEvent(userId);
return result;
}
@@ -262,10 +256,9 @@ namespace Umbraco.Core.Security
var result = base.AccessFailedAsync(userId);
if (result.Result.Succeeded)
- OnLoginFailed(new IdentityAuditEventArgs(AuditEvent.LoginFailed)
- {
- AffectedUser = userId
- });
+ RaiseLoginSuccessEvent(userId);
+ else
+ RaiseLoginFailedEvent(userId);
return result;
}
@@ -275,10 +268,7 @@ namespace Umbraco.Core.Security
var result = base.ChangePasswordAsync(userId, currentPassword, newPassword);
if (result.Result.Succeeded)
- OnPasswordChanged(new IdentityAuditEventArgs(AuditEvent.PasswordChanged)
- {
- AffectedUser = userId
- });
+ RaisePasswordChangedEvent(userId);
return result;
}
@@ -296,105 +286,12 @@ namespace Umbraco.Core.Security
{
user.FailedPasswordAttempts = 0;
ApplicationContext.Current.Services.UserService.Save(user);
-
- OnResetAccessFailedCount(new IdentityAuditEventArgs(AuditEvent.ResetAccessFailedCount)
- {
- AffectedUser = userId
- });
+ RaiseResetAccessFailedCountEvent(userId);
}
return await Task.FromResult(IdentityResult.Success);
}
- internal void RaisePasswordChangedEvent(int userId)
- {
- OnPasswordChanged(new IdentityAuditEventArgs(AuditEvent.PasswordChanged)
- {
- AffectedUser = userId
- });
- }
-
- internal void RaisePasswordResetEvent(int userId)
- {
- OnPasswordReset(new IdentityAuditEventArgs(AuditEvent.PasswordReset)
- {
- AffectedUser = userId
- });
- }
-
- internal void RaiseAccountLockedEvent(int userId)
- {
- OnAccountLocked(new IdentityAuditEventArgs(AuditEvent.AccountLocked)
- {
- AffectedUser = userId
- });
- }
-
- internal void RaiseAccountUnlockedEvent(int userId)
- {
- OnAccountUnlocked(new IdentityAuditEventArgs(AuditEvent.AccountUnlocked)
- {
- AffectedUser = userId
- });
- }
-
- internal void RaiseResetAccessFailedCountEvent(int userId)
- {
- OnResetAccessFailedCount(new IdentityAuditEventArgs(AuditEvent.ResetAccessFailedCount)
- {
- AffectedUser = userId
- });
- }
-
- internal void RaiseLoginSuccessEvent(int userId)
- {
- OnLoginSuccess(new IdentityAuditEventArgs(AuditEvent.LoginSucces)
- {
- AffectedUser = userId
- });
- }
-
- internal void RaiseLogoutSuccessEvent(int userId)
- {
- OnLogoutSuccess(new IdentityAuditEventArgs(AuditEvent.LogoutSuccess)
- {
- AffectedUser = userId
- });
- }
-
- internal void RaiseLoginRequiresVerificationEvent(int userId)
- {
- OnLoginRequiresVerification(new IdentityAuditEventArgs(AuditEvent.LoginRequiresVerification)
- {
- AffectedUser = userId
- });
- }
-
- internal void RaiseForgotPasswordRequestedEvent(int userId)
- {
- OnForgotPasswordRequested(new IdentityAuditEventArgs(AuditEvent.ForgotPasswordRequested)
- {
- AffectedUser = userId
- });
- }
-
- internal void RaiseForgotPasswordChangedSuccessEvent(int userId)
- {
- OnForgotPasswordChangedSuccess(new IdentityAuditEventArgs(AuditEvent.ForgotPasswordChangedSuccess)
- {
- AffectedUser = userId
- });
- }
-
- public void RaiseInvalidLoginAttemptEvent(string username)
- {
- OnLoginFailed(new IdentityAuditEventArgs(AuditEvent.LoginFailed)
- {
- Username = username,
- Comment = string.Format("Attempted login for username '{0}' failed", username)
- });
- }
-
///
/// Clears a lock so that the membership user can be validated.
///
@@ -419,14 +316,106 @@ namespace Umbraco.Core.Security
ApplicationContext.Current.Services.UserService.Save(user);
- OnAccountUnlocked(new IdentityAuditEventArgs(AuditEvent.AccountUnlocked)
- {
- AffectedUser = user.Id
- });
+ RaiseAccountUnlockedEvent(user.Id);
return true;
}
+ internal void RaiseAccountLockedEvent(int userId)
+ {
+ OnAccountLocked(new IdentityAuditEventArgs(AuditEvent.AccountLocked)
+ {
+ AffectedUser = userId
+ });
+ }
+
+ internal void RaiseAccountUnlockedEvent(int userId)
+ {
+ OnAccountUnlocked(new IdentityAuditEventArgs(AuditEvent.AccountUnlocked)
+ {
+ AffectedUser = userId
+ });
+ }
+
+ internal void RaiseForgotPasswordRequestedEvent(int userId)
+ {
+ OnForgotPasswordRequested(new IdentityAuditEventArgs(AuditEvent.ForgotPasswordRequested)
+ {
+ AffectedUser = userId
+ });
+ }
+
+ internal void RaiseForgotPasswordChangedSuccessEvent(int userId)
+ {
+ OnForgotPasswordChangedSuccess(new IdentityAuditEventArgs(AuditEvent.ForgotPasswordChangedSuccess)
+ {
+ AffectedUser = userId
+ });
+ }
+
+ public void RaiseLoginFailedEvent(int userId)
+ {
+ OnLoginFailed(new IdentityAuditEventArgs(AuditEvent.LoginFailed)
+ {
+ AffectedUser = userId
+ });
+ }
+
+ public void RaiseInvalidLoginAttemptEvent(string username)
+ {
+ OnLoginFailed(new IdentityAuditEventArgs(AuditEvent.LoginFailed)
+ {
+ Username = username,
+ Comment = string.Format("Attempted login for username '{0}' failed", username)
+ });
+ }
+
+ internal void RaiseLoginRequiresVerificationEvent(int userId)
+ {
+ OnLoginRequiresVerification(new IdentityAuditEventArgs(AuditEvent.LoginRequiresVerification)
+ {
+ AffectedUser = userId
+ });
+ }
+
+ internal void RaiseLoginSuccessEvent(int userId)
+ {
+ OnLoginSuccess(new IdentityAuditEventArgs(AuditEvent.LoginSucces)
+ {
+ AffectedUser = userId
+ });
+ }
+
+ internal void RaiseLogoutSuccessEvent(int userId)
+ {
+ OnLogoutSuccess(new IdentityAuditEventArgs(AuditEvent.LogoutSuccess)
+ {
+ AffectedUser = userId
+ });
+ }
+
+ internal void RaisePasswordChangedEvent(int userId)
+ {
+ OnPasswordChanged(new IdentityAuditEventArgs(AuditEvent.PasswordChanged)
+ {
+ AffectedUser = userId
+ });
+ }
+
+ internal void RaisePasswordResetEvent(int userId)
+ {
+ OnPasswordReset(new IdentityAuditEventArgs(AuditEvent.PasswordReset)
+ {
+ AffectedUser = userId
+ });
+ }
+ internal void RaiseResetAccessFailedCountEvent(int userId)
+ {
+ OnResetAccessFailedCount(new IdentityAuditEventArgs(AuditEvent.ResetAccessFailedCount)
+ {
+ AffectedUser = userId
+ });
+ }
public static event EventHandler AccountLocked;
public static event EventHandler AccountUnlocked;
public static event EventHandler ForgotPasswordRequested;