Skip to content

Commit

Permalink
Added IP addresses to audit entries
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris Jacobsen Work committed Oct 30, 2023
1 parent 8300f57 commit 2cd15e3
Show file tree
Hide file tree
Showing 10 changed files with 24 additions and 3 deletions.
2 changes: 1 addition & 1 deletion BLAZAM/BLAZAM.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<ImplicitUsings>enable</ImplicitUsings>
<ServerGarbageCollection>false</ServerGarbageCollection>
<AssemblyVersion>0.8.2</AssemblyVersion>
<Version>2023.10.27.1927</Version>
<Version>2023.10.30.1526</Version>
<RootNamespace>BLAZAM</RootNamespace>
<GenerateDocumentationFile>False</GenerateDocumentationFile>

Expand Down
2 changes: 2 additions & 0 deletions BLAZAM/Middleware/UserStateMiddleware.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using BLAZAM.Session.Interfaces;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Http;
using Org.BouncyCastle.Ocsp;
using System.Threading.Tasks;

namespace BLAZAM.Server.Middleware
Expand All @@ -21,6 +22,7 @@ public UserStateMiddleware(RequestDelegate next)
public Task Invoke(HttpContext httpContext,ICurrentUserStateService currentUserStateService,IApplicationUserStateService userStateService)
{
currentUserStateService.State = userStateService.GetUserState(httpContext.User);

return _next(httpContext);
}
}
Expand Down
9 changes: 8 additions & 1 deletion BLAZAM/Pages/Index.razor
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,13 @@

}
}
else
{
if (tester.AppReady == ServiceConnectionState.Up)
{
NavManager.NavigateTo("/install", true);
}
}
if (!waitingForLoadToComplete)
Task.Delay(1000).Wait();

Expand All @@ -101,7 +108,7 @@
{
if (newStatus == ServiceConnectionState.Up)

if (NavManager.ToBaseRelativePath(NavManager.Uri) == "")
if (ApplicationInfo.InstallationCompleted && NavManager.ToBaseRelativePath(NavManager.Uri) == "")
{
waitingForLoadToComplete = false;

Expand Down
2 changes: 2 additions & 0 deletions BLAZAMCommon/Data/LoginRequest.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.ComponentModel.DataAnnotations;
using System.Net;
using System.Security;
using System.Security.Claims;
using BLAZAM.Helpers;
Expand Down Expand Up @@ -28,5 +29,6 @@ public bool Valid

public bool Impersonation { get; set; } = false;
public ClaimsPrincipal? ImpersonatorClaims { get; set; }
public IPAddress IPAddress { get; set; }
}
}
1 change: 1 addition & 0 deletions BLAZAMGui/UI/Dev/DevTools.razor
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
<MudDataGrid Items="@UserStateService.UserStates">
<Columns>
<PropertyColumn Title="Username" Property="x => x.User.Identity==null?null:x.User.Identity.Name" />
<PropertyColumn Title="IP Address" Property="x => x.IPAddress==null?null:x.IPAddress.ToString()" />

<PropertyColumn Title="Auth Type" Property="x => x.User.Identity==null || x.User.Identity.AuthenticationType==null?null:x.User.Identity.AuthenticationType.ToString()" />
<PropertyColumn Title="Authenticated" Property="x => x.User.Identity==null?null:x.User.Identity.IsAuthenticated.ToString()" />
Expand Down
1 change: 1 addition & 0 deletions BLAZAMServices/AppAuthenticationStateProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ public async Task<LoginResult> Login(LoginRequest loginReq)
{
LoginResult loginResult = new();
var newUserState = _userStateService.CreateUserState(null);
newUserState.IPAddress = loginReq.IPAddress;


AuthenticationState? result = null;
Expand Down
3 changes: 2 additions & 1 deletion BLAZAMServices/AuditLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,8 @@ protected virtual async Task<bool> Log<T>(
Sid = relatedEntry.SID.ToSidString(),
BeforeAction = beforeAction,
AfterAction = afterAction,
Username = CurrentUser.AuditUsername
Username = CurrentUser.AuditUsername,
IpAddress = CurrentUser.IPAddress?.ToString(),
};
table.Add(auditEntry);
context.SaveChanges();
Expand Down
3 changes: 3 additions & 0 deletions BLAZAMSession/ApplicationUserState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using Microsoft.AspNetCore.Authentication;
using Microsoft.EntityFrameworkCore;
using System;
using System.Net;
using System.Security.Claims;
using System.Xml;

Expand Down Expand Up @@ -43,6 +44,8 @@ public class ApplicationUserState : IApplicationUserState
public DateTime LastAccessed { get; set; } = DateTime.UtcNow;


public IPAddress IPAddress { get; set; }



public IList<UserNotification>? Notifications
Expand Down
2 changes: 2 additions & 0 deletions BLAZAMSession/CurentUserStateService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ public CurrentUserStateService(IApplicationUserStateService applicationUserState
{
_retryTimer = new Timer(RetryGetCurrentUserState, null, 500, 500);
}
if (State.IsAuthenticated)
State.IPAddress = _httpContextAccessor.HttpContext.Connection.RemoteIpAddress;
}

private void RetryGetCurrentUserState(object? state = null)
Expand Down
2 changes: 2 additions & 0 deletions BLAZAMSession/Interfaces/IApplicationUserState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using BLAZAM.Database.Models.User;
using BLAZAM.Server.Data;
using Microsoft.AspNetCore.Authentication;
using System.Net;
using System.Security.Claims;

namespace BLAZAM.Session.Interfaces
Expand Down Expand Up @@ -62,6 +63,7 @@ public interface IApplicationUserState
IList<UserNotification>? Notifications { get; }
IApplicationUserSessionCache Cache { get; set; }

IPAddress IPAddress { get; set; }

string LastUri { get; set; }
bool IsAuthenticated { get; }
Expand Down

0 comments on commit 2cd15e3

Please sign in to comment.