Skip to content

Commit

Permalink
Merge pull request #302 from Blazam-App/Beta-Nightly
Browse files Browse the repository at this point in the history
v0.9.1 update
  • Loading branch information
jacobsen9026 authored Apr 13, 2024
2 parents 3c2bf66 + a093bc3 commit 7e4529a
Show file tree
Hide file tree
Showing 21 changed files with 194 additions and 122 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.9.1</AssemblyVersion>
<Version>2024.04.12.2311</Version>
<Version>2024.04.13.2102</Version>
<IncludeSourceRevisionInInformationalVersion>false</IncludeSourceRevisionInInformationalVersion>
<RootNamespace>BLAZAM</RootNamespace>
<GenerateDocumentationFile>False</GenerateDocumentationFile>
Expand Down
37 changes: 0 additions & 37 deletions BLAZAM/Pages/Browse/Browse.razor

This file was deleted.

12 changes: 12 additions & 0 deletions BLAZAM/Pages/Configure/Settings.razor
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,18 @@


</MudTabPanel>
<MudTabPanel>
<ChildContent>
<UserActivity />

</ChildContent>
<TabContent>
@AppLocalization["User Activity"]
</TabContent>


</MudTabPanel>

<MudTabPanel>
<ChildContent>
<SystemSettings />
Expand Down
2 changes: 1 addition & 1 deletion BLAZAM/Pages/Configure/Templates.razor
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@


<MudStack Row=true>
<MudText Align="Align.Center">
<MudText Class="align-middle" Align="Align.Center">
@AppLocalization["Templates"]

</MudText>
Expand Down
11 changes: 10 additions & 1 deletion BLAZAM/Pages/SignIn.cshtml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,16 @@ public async Task<IActionResult> OnPost([FromFormAttribute] LoginRequest req)

await HttpContext.SignInAsync(result.AuthenticationState.User);
if (result.AuthenticationState.User.Identity?.IsAuthenticated == true)
await AuditLogger.Logon.Login(result.AuthenticationState.User, req.IPAddress);
if (result.Impersonation)
{
await AuditLogger.Logon.Impersonate(User, result.AuthenticationState.User, req.IPAddress);

}
else
{
await AuditLogger.Logon.Login(result.AuthenticationState.User, req.IPAddress);

}
req.AuthenticationState = null;
req.ImpersonatorClaims = null;
}
Expand Down
4 changes: 2 additions & 2 deletions BLAZAM/Pages/Users/CreateUser.razor
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
TData="object">
<MudCarouselItem Class="pa-5">
<FlexContainer>
@foreach (var category in TemplateCategories)
@foreach (var category in TemplateCategoriesUserCanUse)
{
<MudButton OnClick=@(()=>{SelectedCategory=category; _templateCarouselIndex=1;}) Variant="Variant.Filled" Color="Color.Primary" Size="Size.Large">@category</MudButton>
}
Expand All @@ -47,7 +47,7 @@
Color="Color.Primary" />
<FlexContainer>

@foreach (var template in Templates.Where(t => t.DeletedAt == null && t.Visible))
@foreach (var template in TemplatesUserCanUse.Where(t => t.DeletedAt == null && t.Visible))
{
<MudButton OnClick=@(async()=>{await SetTemplate(template);}) Variant="Variant.Filled" Color="Color.Primary" Size="Size.Large">@template.Name</MudButton>

Expand Down
9 changes: 9 additions & 0 deletions BLAZAMActiveDirectory/Adapters/ADOrganizationalUnit.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using BLAZAM.ActiveDirectory.Interfaces;
using BLAZAM.Common.Data;
using BLAZAM.Database.Models.Permissions;
using BLAZAM.Logger;
using Microsoft.EntityFrameworkCore;
Expand Down Expand Up @@ -140,6 +141,14 @@ public virtual bool CanReadInSubOus
);
}

}
public virtual bool CanCreateUser
{
get
{
return HasActionPermission(ObjectActions.Create,ActiveDirectoryObjectType.User);
}

}

/// <summary>
Expand Down
72 changes: 5 additions & 67 deletions BLAZAMActiveDirectory/Adapters/DirectoryEntryAdapter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -458,67 +458,14 @@ public virtual void MoveTo(IADOrganizationalUnit parentOUToMoveTo)
protected virtual bool HasPermission(Func<IEnumerable<PermissionMapping>, IEnumerable<PermissionMapping>> allowSelector, Func<IEnumerable<PermissionMapping>, IEnumerable<PermissionMapping>>? denySelector = null, bool nestedSearch = false)
{
if (CurrentUser == null) return false;

if (CurrentUser.IsSuperAdmin) return true;
if (DN == null)
{
Loggers.ActiveDirectryLogger.Error("The directory object " + ADSPath
+ " did not load a distinguished name." + " {@Error}", new ApplicationException());
return false;
}
IOrderedEnumerable<PermissionMapping>? baseSearch = null;
if (!nestedSearch)
{
baseSearch = CurrentUser.PermissionMappings
.Where(pm => DN.Contains(pm.OU)).OrderByDescending(pm => pm.OU.Length);

}
else
{
baseSearch = CurrentUser.PermissionMappings
.Where(pm => pm.OU.Contains(DN)).OrderByDescending(pm => pm.OU.Length);

}

if (baseSearch == null)
{
Loggers.ActiveDirectryLogger.Error("The active user state for " + DN + " could not" +
"be found in the application cache." + " {@Error}", new ApplicationException());
return false;
}
try
{
var possibleReads = allowSelector.Invoke(baseSearch).ToList();
if (denySelector != null)
{
var possibleDenys = denySelector.Invoke(baseSearch).ToList();

if (possibleReads != null && possibleReads.Count > 0)
{
if (possibleDenys != null && possibleDenys.Count > 0)
{
foreach (var d in possibleDenys)
{
if (d.OU.Length > possibleReads.OrderByDescending(r => r.OU.Length).First().OU.Length)
return false;
}
}
else
{
return true;
}
}
}
else
{
return possibleReads?.Count > 0;
}
}
catch (Exception ex)
{
Loggers.SystemLogger.Error(ex.Message);
}
return false;
return CurrentUser.HasPermission(DN,allowSelector, denySelector, nestedSearch);

}

public virtual bool CanRead
Expand Down Expand Up @@ -586,19 +533,10 @@ public virtual bool CanEdit
public virtual bool CanCreate { get => HasActionPermission(ObjectActions.Create); }


protected virtual bool HasActionPermission(ObjectAction action)
protected virtual bool HasActionPermission(ObjectAction action,ActiveDirectoryObjectType? objectType=null)
{
return HasPermission(p => p.Where(pm =>
pm.AccessLevels.Any(al => al.ActionMap.Any(am =>
am.AllowOrDeny && am.ObjectAction.Id == action.Id &&
am.ObjectType == ObjectType
))),
p => p.Where(pm =>
pm.AccessLevels.Any(al => al.ActionMap.Any(am =>
!am.AllowOrDeny && am.ObjectAction.Id == action.Id &&
am.ObjectType == ObjectType
)))
);
if (objectType == null) objectType = ObjectType;
return CurrentUser.HasActionPermission(DN,action, objectType.Value);
}

public virtual bool CanDelete { get => HasActionPermission(ObjectActions.Delete); }
Expand Down
1 change: 1 addition & 0 deletions BLAZAMActiveDirectory/Interfaces/IADOrganizationalUnit.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public interface IADOrganizationalUnit : IDirectoryEntryAdapter
HashSet<IADOrganizationalUnit> CachedTreeViewSubOUs { get;}
HashSet<IADOrganizationalUnit> TreeViewSubOUs { get; }
bool CanReadInSubOus { get; }
bool CanCreateUser { get; }

IADGroup CreateGroup(string containerName);
IADUser CreateUser(string containerName);
Expand Down
2 changes: 1 addition & 1 deletion BLAZAMGui/Layouts/AppUserButton.razor
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

</ActivatorContent>
<ChildContent>
<MudText Typo=Typo.body2 Color="Color.Dark" Align=Align.Center Class="py-3 w-100 " Style="text-align:center; background-color: var(--mud-palette-drawer-background);">
<MudText Typo=Typo.body2 Color="Color.Info" Align=Align.Center Class="py-3 w-100 " Style="text-align:center; background-color: var(--mud-palette-drawer-background);">
@CurrentUser.Username
</MudText>
<MudDivider/>
Expand Down
2 changes: 1 addition & 1 deletion BLAZAMGui/Layouts/MainLayout.razor
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
@using System.Security.Claims;
@inherits LayoutComponentBase

@inject NavigationManager Nav
@inject AppNavigationManager Nav
@inject IActiveDirectoryContext directory
@inject IApplicationUserStateService UserStateService
@inject IAppDatabaseFactory DbFactory
Expand Down
3 changes: 2 additions & 1 deletion BLAZAMGui/UI/AppModal.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ protected override void OnInitialized()
YesText = AppLocalization["Ok"];
if (Options == null)
Options = new();
AllowClose=true;
}
/// <summary>
/// Re-renders the modal with the latest property values
Expand All @@ -143,7 +144,7 @@ public void RefreshView()

IsShown = true;

return Modal?.Show();
return Modal?.Show(null,Options);
}

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion BLAZAMGui/UI/Dashboard/Widgets/AllWidgets.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public static List<Widget> Available(IApplicationUserState? applicationUser)
|| applicationUser.HasRole(UserRoles.SearchGroups)
|| applicationUser.HasRole(UserRoles.SearchPrinters)
|| applicationUser.HasRole(UserRoles.SearchComputers))
widgets.Add(new ChangedEntriesWidget() { WidgetType = DashboardWidgetType.ChangedEntries, Title = "Entries changed in the last 24 hhours" });
widgets.Add(new ChangedEntriesWidget() { WidgetType = DashboardWidgetType.ChangedEntries, Title = "Entries changed in the last 24 hours" });


if (applicationUser.IsSuperAdmin || applicationUser.HasRole(UserRoles.SearchOUs))
Expand Down
3 changes: 2 additions & 1 deletion BLAZAMGui/UI/Outputs/AppDocumentationButton.razor
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
@inject IStringLocalizer<AppLocalization> AppLocalization
@if (!Page.IsNullOrEmpty())
{
<MudTooltip Text=@AppLocalization["Click to view help documentation"] RootClass="d-inline" Class="pa-4">
<MudTooltip Text=@AppLocalization["Click to view help documentation"] RootClass="d-inline align-middle" Class="pa-4">
<MudFab StartIcon="@Icon"
Href=@("https://docs.blazam.org"+@Page)
Target="_blank"
DisableElevation=true
Size="@Size"
IconSize="@IconSize"
IconColor="@IconColor"
Expand Down
33 changes: 33 additions & 0 deletions BLAZAMGui/UI/Settings/UserActivity.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
@inherits SettingsComponents
<MudText Typo="Typo.h4">@AppLocalization["User Activity"]</MudText>
<MudDataGrid Items="@UserStateService.UserStates.Where(u=>u.User.Identity?.IsAuthenticated==true)">
<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" />


<TemplateColumn Title="Impersonator">
<CellTemplate>
<MudText>@context.Item.Impersonator?.Identity?.Name</MudText>
</CellTemplate>
</TemplateColumn>

<PropertyColumn Title="Last URI" Property="x => x.LastUri" />

<TemplateColumn Title="Last Access">
<CellTemplate>
<MudText>@context.Item.LastAccessed.ToLocalTime()</MudText>
</CellTemplate>
</TemplateColumn>

<PropertyColumn Title="Session Expiration Time" Property="x => x.Ticket==null?null:(DateTimeOffset.UtcNow-x.Ticket.Properties.ExpiresUtc)" />




</Columns>
</MudDataGrid>
@code {


}
23 changes: 23 additions & 0 deletions BLAZAMGui/UI/TemplateComponent.razor.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@

using BLAZAM.Database.Models.Permissions;
using BLAZAM.Database.Models.Templates;
using BLAZAM.Gui.UI.Settings;
using Microsoft.EntityFrameworkCore;
Expand Down Expand Up @@ -30,7 +31,29 @@ protected IEnumerable<DirectoryTemplate> Templates
}
set => templates = value;
}

public IEnumerable<DirectoryTemplate> TemplatesUserCanUse { get {
var list = new List<DirectoryTemplate>();
foreach (var template in Templates)
{
if (CurrentUser.State.HasActionPermission(template.ParentOU, ObjectActions.Create, ActiveDirectoryObjectType.User))
{
list.Add(template);

}

}
return list;
} }
protected IEnumerable<string?> TemplateCategories { get; private set; }
protected IEnumerable<string?> TemplateCategoriesUserCanUse { get {
var cats = TemplatesUserCanUse.Select(c => c.Category).Where(c => c != "" && c != null).Distinct().ToList();
if (cats != null)
{
cats.Prepend("All");
}
return cats;
} }

public DirectoryTemplate? SelectedTemplate
{
Expand Down
6 changes: 6 additions & 0 deletions BLAZAMServices/Audit/LogonAudit.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ public async Task<bool> AttemptedLogin(ClaimsPrincipal user, string? iPAddress=n
CurrentUser = UserStateService.CreateUserState(user);
return await Log("Attempted Login", iPAddress);
}
public async Task<bool> Impersonate(ClaimsPrincipal impersonator, ClaimsPrincipal impersonateee, string? ipAddress = null)
{
CurrentUser = UserStateService.CreateUserState(impersonateee);
CurrentUser.Impersonator = impersonator;
return await Log("Impersonation", ipAddress);
}
public async Task<bool> Login(ClaimsPrincipal user,string? ipAddress=null)
{
CurrentUser = UserStateService.CreateUserState(user);
Expand Down
Loading

0 comments on commit 7e4529a

Please sign in to comment.