Skip to content
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
42 changes: 21 additions & 21 deletions DynamicAuthPolicyDemo.Web/DynamicAuthPolicyDemo.Web.csproj
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<IsPackable>false</IsPackable>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<NoWarn>1701;1702;0436</NoWarn>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<NoWarn>1701;1702;0436</NoWarn>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\cloudscribe.DynamicPolicy.Storage.NoDb\cloudscribe.DynamicPolicy.Storage.NoDb.csproj" />
<ProjectReference Include="..\cloudscribe.DynamicPolicy.Web.Mvc\cloudscribe.DynamicPolicy.Web.Mvc.csproj" />
<ProjectReference Include="..\cloudscribe.DynamicPolicy.Web.Views.Bootstrap3\cloudscribe.DynamicPolicy.Web.Views.Bootstrap3.csproj" />
</ItemGroup>

</Project>
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<IsPackable>false</IsPackable>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<NoWarn>1701;1702;0436</NoWarn>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<NoWarn>1701;1702;0436</NoWarn>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\cloudscribe.DynamicPolicy.Storage.NoDb\cloudscribe.DynamicPolicy.Storage.NoDb.csproj" />
<ProjectReference Include="..\cloudscribe.DynamicPolicy.Web.Mvc\cloudscribe.DynamicPolicy.Web.Mvc.csproj" />
<ProjectReference Include="..\cloudscribe.DynamicPolicy.Web.Views.Bootstrap3\cloudscribe.DynamicPolicy.Web.Views.Bootstrap3.csproj" />
</ItemGroup>
</Project>
55 changes: 55 additions & 0 deletions cloudscribe.DynamicPolicy.CoreIntegration/RoleCopiedHandler.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
using cloudscribe.Core.Models;
using cloudscribe.Core.Models.EventHandlers;
using cloudscribe.DynamicPolicy.Models;
using Microsoft.Extensions.Logging;
using System;
using System.Threading.Tasks;

namespace cloudscribe.DynamicPolicy.CoreIntegration
{
public class RoleCopiedHandler : IHandleRoleCopied
{
public RoleCopiedHandler(
IAuthorizationPolicyCommands policyCommands,
IAuthorizationPolicyQueries policyQueries,
ILogger<RoleCopiedHandler> logger)
{
_policyCommands = policyCommands;
_policyQueries = policyQueries;
_log = logger;
}

private readonly IAuthorizationPolicyCommands _policyCommands;
private readonly IAuthorizationPolicyQueries _policyQueries;
private readonly ILogger _log;

public async Task Handle(ISiteRole sourceRole, ISiteRole newRole)
{
try
{
var tenantId = sourceRole.SiteId.ToString();
var policies = await _policyQueries.GetAll(tenantId);

int updatedCount = 0;
foreach (var policy in policies)
{
if (policy.AllowedRoles.Contains(sourceRole.RoleName))
{
if (!policy.AllowedRoles.Contains(newRole.RoleName))
{
policy.AllowedRoles.Add(newRole.RoleName);
await _policyCommands.Update(policy);
updatedCount++;
}
}
}

_log.LogInformation($"Role '{sourceRole.RoleName}' copied to '{newRole.RoleName}'. Updated {updatedCount} authorization policies.");
}
catch (Exception ex)
{
_log.LogError($"Error handling role copied event: {ex.Message}-{ex.StackTrace}");
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ IConfiguration configuration
services.AddScoped<IVersionProvider, cloudscribe.DynamicPolicy.CoreIntegration.VersionProvider>();
services.AddScoped<IHandleSitePreDelete, SiteDeleteHandler>();
services.AddScoped<IHandleSiteCloned, SiteCloneHandler>();
services.AddScoped<IHandleRoleCopied, RoleCopiedHandler>();
services.AddScoped<IGuardNeededRoles, AuthPolicyRoleGuard>();


Expand Down
Original file line number Diff line number Diff line change
@@ -1,39 +1,39 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<Description>cloudscribe Core integration for Dynamic Authorization Policy Services for ASP.NET Core</Description>
<Version>8.5.0</Version>
<TargetFramework>net8.0</TargetFramework>
<Authors>Joe Audette</Authors>
<PackageIcon>icon.png</PackageIcon>
<PackageProjectUrl>https://github.com/cloudscribe/dynamic-authorization-policy</PackageProjectUrl>
<PackageLicenseExpression>Apache-2.0</PackageLicenseExpression>
<RepositoryUrl>https://github.com/cloudscribe/dynamic-authorization-policy.git</RepositoryUrl>
<RepositoryType>git</RepositoryType>
<PackageReadmeFile>README.md</PackageReadmeFile>
</PropertyGroup>

<ItemGroup>
<None Include="README.md" Pack="true" PackagePath="/" />
</ItemGroup>

<ItemGroup>
<None Include="icon.png" Pack="true" PackagePath="\"/>
</ItemGroup>

<ItemGroup>
<PackageReference Include="cloudscribe.Core.Models" Version="8.5.0" />
<PackageReference Include="cloudscribe.Multitenancy" Version="8.5.0" />

<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="8.0.2" />
<PackageReference Include="Microsoft.Extensions.Localization" Version="8.0.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\cloudscribe.DynamicPolicy.Models\cloudscribe.DynamicPolicy.Models.csproj" />
<ProjectReference Include="..\cloudscribe.DynamicPolicy.Web.Mvc\cloudscribe.DynamicPolicy.Web.Mvc.csproj" />
</ItemGroup>

</Project>
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<Description>cloudscribe Core integration for Dynamic Authorization Policy Services for ASP.NET Core</Description>
<Version>8.6.0</Version>
<TargetFramework>net8.0</TargetFramework>
<Authors>Joe Audette</Authors>
<PackageIcon>icon.png</PackageIcon>
<PackageProjectUrl>https://github.com/cloudscribe/dynamic-authorization-policy</PackageProjectUrl>
<PackageLicenseExpression>Apache-2.0</PackageLicenseExpression>
<RepositoryUrl>https://github.com/cloudscribe/dynamic-authorization-policy.git</RepositoryUrl>
<RepositoryType>git</RepositoryType>
<PackageReadmeFile>README.md</PackageReadmeFile>
</PropertyGroup>
<ItemGroup>
<None Include="README.md" Pack="true" PackagePath="/" />
</ItemGroup>
<ItemGroup>
<None Include="icon.png" Pack="true" PackagePath="\"/>
</ItemGroup>
<ItemGroup>
<PackageReference Include="cloudscribe.Core.Models" Version="8.6.0" />
<PackageReference Include="cloudscribe.Multitenancy" Version="8.6.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="8.0.2" />
<PackageReference Include="Microsoft.Extensions.Localization" Version="8.0.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\cloudscribe.DynamicPolicy.Models\cloudscribe.DynamicPolicy.Models.csproj" />
<ProjectReference Include="..\cloudscribe.DynamicPolicy.Web.Mvc\cloudscribe.DynamicPolicy.Web.Mvc.csproj" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<Description>model classes for Dynamic Authorization Policy for ASP.NET Core</Description>
<Version>8.5.0</Version>
<TargetFramework>net8.0</TargetFramework>
<Authors>Joe Audette</Authors>
<PackageIcon>icon.png</PackageIcon>
<PackageProjectUrl>https://github.com/cloudscribe/dynamic-authorization-policy</PackageProjectUrl>
<PackageLicenseExpression>Apache-2.0</PackageLicenseExpression>
<RepositoryUrl>https://github.com/cloudscribe/dynamic-authorization-policy.git</RepositoryUrl>
<RepositoryType>git</RepositoryType>
<PackageReadmeFile>README.md</PackageReadmeFile>
</PropertyGroup>

<ItemGroup>
<None Include="README.md" Pack="true" PackagePath="/" />
</ItemGroup>

<ItemGroup>
<None Include="icon.png" Pack="true" PackagePath="\"/>
</ItemGroup>

<ItemGroup>
<PackageReference Include="cloudscribe.Pagination.Models" Version="8.5.0" />

<PackageReference Include="Microsoft.Extensions.Options" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Caching.Abstractions" Version="8.0.0" />
</ItemGroup>

</Project>
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<Description>model classes for Dynamic Authorization Policy for ASP.NET Core</Description>
<Version>8.6.0</Version>
<TargetFramework>net8.0</TargetFramework>
<Authors>Joe Audette</Authors>
<PackageIcon>icon.png</PackageIcon>
<PackageProjectUrl>https://github.com/cloudscribe/dynamic-authorization-policy</PackageProjectUrl>
<PackageLicenseExpression>Apache-2.0</PackageLicenseExpression>
<RepositoryUrl>https://github.com/cloudscribe/dynamic-authorization-policy.git</RepositoryUrl>
<RepositoryType>git</RepositoryType>
<PackageReadmeFile>README.md</PackageReadmeFile>
</PropertyGroup>
<ItemGroup>
<None Include="README.md" Pack="true" PackagePath="/" />
</ItemGroup>
<ItemGroup>
<None Include="icon.png" Pack="true" PackagePath="\"/>
</ItemGroup>
<ItemGroup>
<PackageReference Include="cloudscribe.Pagination.Models" Version="8.6.0" />
<PackageReference Include="Microsoft.Extensions.Options" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Caching.Abstractions" Version="8.0.0" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@

//saved = true;
}
catch (DbUpdateConcurrencyException ex)

Check warning on line 91 in cloudscribe.DynamicPolicy.Storage.EFCore.Common/AuthorizationPolicyCommands.cs

View workflow job for this annotation

GitHub Actions / build

The variable 'ex' is declared but never used

Check warning on line 91 in cloudscribe.DynamicPolicy.Storage.EFCore.Common/AuthorizationPolicyCommands.cs

View workflow job for this annotation

GitHub Actions / build

The variable 'ex' is declared but never used
{
//foreach (var entry in ex.Entries)
//{
Expand Down Expand Up @@ -142,7 +142,7 @@
{
if (entity.RequiredClaims.Count > 0)
{
for (int i = 0; i < entity.RequiredClaims.Count; i++)
for (int i = entity.RequiredClaims.Count - 1; i >= 0; i--)
{
if (!requiredClaims.HasClaim(entity.RequiredClaims[i].ClaimName))
{
Expand Down Expand Up @@ -192,7 +192,7 @@
{
if (entity.AllowedValues.Count > 0)
{
for (int i = 0; i < entity.AllowedValues.Count; i++)
for (int i = entity.AllowedValues.Count - 1; i >= 0; i--)
{
if (!claim.AllowedValues.Contains(entity.AllowedValues[i].AllowedValue))
{
Expand Down Expand Up @@ -235,7 +235,7 @@
{
if (entity.AuthenticationSchemes.Count > 0)
{
for (int i = 0; i < entity.AuthenticationSchemes.Count; i++)
for (int i = entity.AuthenticationSchemes.Count - 1; i >= 0; i--)
{
if (!authSchemeStrings.Contains(entity.AuthenticationSchemes[i].AuthenticationScheme))
{
Expand Down Expand Up @@ -276,13 +276,14 @@
{
if (entity.AllowedRoles.Count > 0)
{
for (int i = 0; i < entity.AllowedRoles.Count; i++)
// go backwards to avoid classic removal index issues,
// changing what you are supposed to be looping through
for (int i = entity.AllowedRoles.Count - 1; i >= 0; i--)
{
if (!allowedRoleStrings.Contains(entity.AllowedRoles[i].AllowedRole))
{
db.AllowedRoles.Remove(entity.AllowedRoles[i]);
entity.AllowedRoles.RemoveAt(i);

}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,33 +1,33 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<Description>Entity Framework Core implementation of commands and queries for Dynamic Authorization Policies for ASP.NET Core</Description>
<Version>8.5.0</Version>
<TargetFramework>net8.0</TargetFramework>
<Authors>Joe Audette</Authors>
<PackageIcon>icon.png</PackageIcon>
<PackageProjectUrl>https://github.com/cloudscribe/dynamic-authorization-policy</PackageProjectUrl>
<PackageLicenseExpression>Apache-2.0</PackageLicenseExpression>
<RepositoryUrl>https://github.com/cloudscribe/dynamic-authorization-policy.git</RepositoryUrl>
<RepositoryType>git</RepositoryType>
<PackageReadmeFile>README.md</PackageReadmeFile>
</PropertyGroup>

<ItemGroup>
<None Include="README.md" Pack="true" PackagePath="/" />
</ItemGroup>

<ItemGroup>
<None Include="icon.png" Pack="true" PackagePath="\"/>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\cloudscribe.DynamicPolicy.Models\cloudscribe.DynamicPolicy.Models.csproj" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="8.0.0" />
</ItemGroup>

</Project>
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<Description>Entity Framework Core implementation of commands and queries for Dynamic Authorization Policies for ASP.NET Core</Description>
<Version>8.6.0</Version>
<TargetFramework>net8.0</TargetFramework>
<Authors>Joe Audette</Authors>
<PackageIcon>icon.png</PackageIcon>
<PackageProjectUrl>https://github.com/cloudscribe/dynamic-authorization-policy</PackageProjectUrl>
<PackageLicenseExpression>Apache-2.0</PackageLicenseExpression>
<RepositoryUrl>https://github.com/cloudscribe/dynamic-authorization-policy.git</RepositoryUrl>
<RepositoryType>git</RepositoryType>
<PackageReadmeFile>README.md</PackageReadmeFile>
</PropertyGroup>
<ItemGroup>
<None Include="README.md" Pack="true" PackagePath="/" />
</ItemGroup>
<ItemGroup>
<None Include="icon.png" Pack="true" PackagePath="\"/>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\cloudscribe.DynamicPolicy.Models\cloudscribe.DynamicPolicy.Models.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="8.0.0" />
</ItemGroup>
</Project>
Loading
Loading