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

Stale User widget added #669

Merged
merged 4 commits into from
Nov 27, 2024
Merged
Show file tree
Hide file tree
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
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>1.2.0</AssemblyVersion>
<Version>2024.11.26.2304</Version>
<Version>2024.11.27.2318</Version>
<IncludeSourceRevisionInInformationalVersion>false</IncludeSourceRevisionInInformationalVersion>
<RootNamespace>BLAZAM</RootNamespace>
<GenerateDocumentationFile>True</GenerateDocumentationFile>
Expand Down
8 changes: 8 additions & 0 deletions BLAZAM/Helpers/Helpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,14 @@ namespace BLAZAM.Helpers
{
public static class Helpers
{
/// <summary>
/// Processes a template given a <see cref="NewUserName"/>
/// </summary>
/// <param name="template">The template to be applied</param>
/// <param name="newUserName">The new user name</param>
/// <param name="directory">The directory to create the use under</param>
/// <returns></returns>
/// <exception cref="ApplicationException"></exception>
public static IADUser GenerateTemplateUser(this DirectoryTemplate template, NewUserName newUserName, IActiveDirectoryContext directory)
{
IADUser? newUser;
Expand Down
5 changes: 5 additions & 0 deletions BLAZAM/Middleware/HttpsRedirectionMiddleware.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@

namespace BLAZAM.Server.Middleware
{
/// <summary>
/// Redirects the request to HTTPS is the
/// request is HTTP if the database has
/// force HTTPS set to true
/// </summary>
public class HttpsRedirectionMiddleware
{
private readonly RequestDelegate _next;
Expand Down
23 changes: 23 additions & 0 deletions BLAZAM/Pages/API/v1/ApiController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@

namespace BLAZAM.Pages.API.v1
{
/// <summary>
/// Base class for all API controllers that contains common
/// shared elements that make the API work
/// </summary>
[Authorize(AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme, Roles = UserRoles.Login)]
[ApiController]
[Produces("application/json")]
Expand All @@ -19,10 +23,19 @@ public class ApiController : Controller
{
private DateTime _startTime = DateTime.Now;
protected Dictionary<string, object?> ResponseData = new();
/// <summary>
/// A factory for <see cref="IDatabaseContext"/> connections
/// </summary>
protected readonly IAppDatabaseFactory DbFactory;
/// <summary>
/// The API audit logger
/// </summary>
protected readonly AuditLogger AuditLogger;
protected readonly IApplicationUserStateService UserStateService;

/// <summary>
/// The current API user state
/// </summary>
protected IApplicationUserState? CurrentUserState { get; }

public ApiController(IApplicationUserStateService applicationUserStateService, AuditLogger audit, IAppDatabaseFactory appDatabaseFactory, IHttpContextAccessor httpContextAccessor, IActiveDirectoryContextFactory adFactory)
Expand All @@ -49,8 +62,18 @@ public ApiController(IApplicationUserStateService applicationUserStateService, A
// return new BadRequestResult();
//}
protected IActiveDirectoryContext Directory { get; }
/// <summary>
/// A unique ID for the execution of this controller
/// </summary>
protected Guid RequestId { get; }


/// <summary>
/// Returns a JSON response with the data and footer
/// fields appended
/// </summary>
/// <param name="data"></param>
/// <returns></returns>
protected IActionResult FormatData(dynamic data)
{
ResponseData.Add("Data", data);
Expand Down
5 changes: 5 additions & 0 deletions BLAZAM/Pages/Users/ConfirmNewUser.razor
Original file line number Diff line number Diff line change
Expand Up @@ -270,14 +270,19 @@ else
{
disableCreateUserButton = true;
await InvokeAsync(StateHasChanged);

IJob createUserJob = new Job(AppLocalization["Create User"]);
createUserJob.StopOnFailedStep = true;
createUserJob.ShowJobDetailsDialog(MessageService);

_username = User.SamAccountName;
_userPassword = User.NewPassword;

var result = await User.CommitChangesAsync(createUserJob);

disableCreateUserButton = false;
await InvokeAsync(StateHasChanged);

if (result.FailedSteps.Count == 0)
{
User = (IADUser)Directory.GetDirectoryEntryByDN(User.DN);
Expand Down
6 changes: 5 additions & 1 deletion BLAZAM/ProgramHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,11 @@ public static WebApplicationBuilder IntializeProperties(this WebApplicationBuild

return builder;
}

/// <summary>
/// Attempts to get the windows installation id
/// </summary>
/// <returns>A unique GUID for this machine</returns>
/// <exception cref="ApplicationException">Thrown when the running context does not have read permission for the Windows UUID</exception>
private static Guid GetInstallationId()
{
//Try and get os id
Expand Down
5 changes: 4 additions & 1 deletion BLAZAMActiveDirectory/Adapters/AccountDirectoryAdapter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,11 @@ public DateTime? LastLogonTime
List<DateTime?> times = new List<DateTime?>();
foreach (var c in coms)
{
if (c is DateTime)
if (c is DateTime dt)
{
times.Add(dt);
}
else {
times.Add(c.AdsValueToDateTime());
}
}
Expand Down
2 changes: 2 additions & 0 deletions BLAZAMActiveDirectory/Searchers/ADSearch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,8 @@ public async Task<List<IDirectoryEntryAdapter>> SearchAsync()
FilterQuery += $"(whenCreated>={Fields.Created.Value.ToString("yyyyMMddHHmmss.fZ")})";
if (!Fields.SamAccountName.IsNullOrEmpty())
FilterQuery += $"(samaccountname=*{Fields.SamAccountName}*)";
if (Fields.LastLogonTime != null)
FilterQuery += $"(lastLogonTimestamp<={Fields.LastLogonTime})(!(lastLogonTimestamp=0))";
if (Fields.LockoutTime != null)
FilterQuery += $"(lockoutTime>={Fields.LockoutTime})";
if (!Fields.DN.IsNullOrEmpty())
Expand Down
3 changes: 3 additions & 0 deletions BLAZAMActiveDirectory/Searchers/ADSearchFields.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ public class ADSearchFields
/// </remarks>
public long? LockoutTime { get; set; }


public long? LastLogonTime { get; set; }

public string? SID { get; set; }

public string? DN { get; set; }
Expand Down
20 changes: 20 additions & 0 deletions BLAZAMCommon/Data/ApplicationInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,11 @@ public class ApplicationInfo
/// A local store of the .Net web application Services
/// </summary>
public static IServiceProvider services;

/// <summary>
/// A symmetric key version of the encryption key
/// for use with API signing
/// </summary>
public static SymmetricSecurityKey tokenKey { get {

var keyString = configuration.GetValue<string>("EncryptionKey");
Expand Down Expand Up @@ -112,7 +117,15 @@ public static SymmetricSecurityKey tokenKey { get {
/// eg: C:\Users\user\appdata\temp\
/// </returns>
public SystemDirectory TempDirectory { get => tempDirectory; set => tempDirectory = value; }

/// <summary>
/// The running AppConfig configuration
/// </summary>
public Microsoft.Extensions.Configuration.ConfigurationManager Configuration { get => configuration; }

/// <summary>
/// The running AppConfig configuration
/// </summary>
public static Microsoft.Extensions.Configuration.ConfigurationManager configuration;

/// <summary>
Expand Down Expand Up @@ -156,7 +169,14 @@ public static bool installationCompleted
{
get; set;
}
/// <summary>
/// Unique ID for this machine
/// </summary>
public Guid InstallationId { get => installationId; set => installationId = value; }
/// <summary>
/// A symmetric key version of the encryption key
/// for use with API signing
/// </summary>
public SymmetricSecurityKey TokenKey { get => tokenKey; }

/// <summary>
Expand Down
5 changes: 4 additions & 1 deletion BLAZAMGui/Layouts/NotificationList.razor
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,10 @@
{
Task.Run(async () =>
{
LoadingData = true;
if(messages == null || messages.Count==0)
{
LoadingData = true;
}
await InvokeAsync(StateHasChanged);
var context = await DbFactory.CreateDbContextAsync();

Expand Down
7 changes: 5 additions & 2 deletions BLAZAMGui/UI/Dashboard/Widgets/StaleUsersWidget.razor
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,11 @@
await InvokeAsync(StateHasChanged);
var users= Directory.Users.FindUsersByString(null);
ADSearch searcher = new ADSearch(Directory);

StaleUsers = (await Directory.Users.FindNewUsersAsync(14, false)).Where(u => u.CanRead).OrderByDescending(u => u.Created).ToList();
searcher.Fields.LastLogonTime = (DateTime.UtcNow - TimeSpan.FromDays(180)).ToFileTimeUtc();
searcher.ObjectTypeFilter = ActiveDirectoryObjectType.User;
searcher.EnabledOnly = true;
var results = await searcher.SearchAsync();
StaleUsers = results.Where(u => u.CanRead).OrderByDescending(u => u.Created).Cast<IADUser>().ToList();
LoadingData = false;
await InvokeAsync(StateHasChanged);

Expand Down
4 changes: 2 additions & 2 deletions BLAZAMGui/UI/Search/SearchControls.razor
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
TransformOrigin=Origin.TopCenter
Color=Color.Tertiary
StartIcon="@Icons.Material.Filled.TypeSpecimen"
Label="@SearchService.SeachObjectType.ToString()">
Label="@AppLocalization[SearchService.SeachObjectType.ToString()]">
<CascadingAuthenticationState>

<MudMenuItem OnClick=@(()=>{ SearchService.SeachObjectType=ActiveDirectoryObjectType.All; })>
Expand Down Expand Up @@ -91,7 +91,7 @@
Style="max-width:550px;"
AdornmentIcon="@adornmentIcon"
Variant="Variant.Filled"
Label="Search Directory"
Label=@AppLocalization["Search Directory"]
SelectedResultChanged="@((result)=>{if(result!=null)SearchService.Search(SearchService.SearchTerm);})"
SearchObjectType="@SearchService.SeachObjectType"
SearchDisabled=@SearchService.IncludeDisabled
Expand Down
4 changes: 3 additions & 1 deletion BLAZAMUpdate/ApplicationUpdate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,9 @@ private string CommandArguments
}
}


/// <summary>
/// Called when download progress has changed
/// </summary>
public AppEvent<FileProgress?> DownloadPercentageChanged { get; set; }

private ApplicationVersion _runningVersion;
Expand Down