Skip to content

Commit

Permalink
obsolete SiteOwner claim
Browse files Browse the repository at this point in the history
  • Loading branch information
MikeAlhayek committed Nov 27, 2024
1 parent 1c3cf78 commit 6bc7448
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ public async Task GenerateAsync(IUser user, ClaimsIdentity claims)

if (await _userManager.IsInRoleAsync(user, await _systemRoleNameProvider.GetAdminRoleAsync()))
{
#pragma warning disable CS0618 // Type or member is obsolete
claims.AddClaim(StandardClaims.SiteOwner);
#pragma warning restore CS0618 // Type or member is obsolete

isAdministrator = true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
<ProjectReference Include="..\..\OrchardCore\OrchardCore.Navigation.Core\OrchardCore.Navigation.Core.csproj" />
<ProjectReference Include="..\..\OrchardCore\OrchardCore.Liquid.Abstractions\OrchardCore.Liquid.Abstractions.csproj" />
<ProjectReference Include="..\..\OrchardCore\OrchardCore.Recipes.Abstractions\OrchardCore.Recipes.Abstractions.csproj" />
<ProjectReference Include="..\..\OrchardCore\OrchardCore.Roles.Core\OrchardCore.Roles.Core.csproj" />
<ProjectReference Include="..\..\OrchardCore\OrchardCore.Settings.Core\OrchardCore.Settings.Core.csproj" />
<ProjectReference Include="..\..\OrchardCore\OrchardCore.Setup.Abstractions\OrchardCore.Setup.Abstractions.csproj" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.Security.Claims;
using Microsoft.AspNetCore.Authorization;
using OrchardCore.Roles;
using OrchardCore.Security;

namespace OrchardCore.Settings.Services;
Expand All @@ -10,10 +11,14 @@ namespace OrchardCore.Settings.Services;
public class SuperUserHandler : IAuthorizationHandler
{
private readonly ISiteService _siteService;
private readonly ISystemRoleNameProvider _systemRoleNameProvider;

public SuperUserHandler(ISiteService siteService)
public SuperUserHandler(
ISiteService siteService,
ISystemRoleNameProvider systemRoleNameProvider)
{
_siteService = siteService;
_systemRoleNameProvider = systemRoleNameProvider;
}

public async Task HandleAsync(AuthorizationHandlerContext context)
Expand All @@ -25,7 +30,7 @@ public async Task HandleAsync(AuthorizationHandlerContext context)
return;
}

if (user.HasClaim(StandardClaims.SiteOwner.Type, StandardClaims.SiteOwner.Value))
if (user.IsInRole(await _systemRoleNameProvider.GetAdminRoleAsync()))
{
SucceedAllRequirements(context);

Expand Down
2 changes: 2 additions & 0 deletions src/OrchardCore.Modules/OrchardCore.Settings/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using OrchardCore.Recipes;
using OrchardCore.Recipes.Services;
using OrchardCore.ResourceManagement;
using OrchardCore.Roles;
using OrchardCore.Security.Permissions;
using OrchardCore.Settings.Deployment;
using OrchardCore.Settings.Drivers;
Expand Down Expand Up @@ -65,6 +66,7 @@ public override void ConfigureServices(IServiceCollection services)

services.AddScoped<ISetupEventHandler, SetupEventHandler>();
services.AddPermissionProvider<Permissions>();
services.AddRolesCoreServices();
services.AddScoped<IAuthorizationHandler, SuperUserHandler>();

services.AddRecipeExecutionStep<SettingsStep>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace OrchardCore.Users.Liquid;

public static class UserFilters
{
public static ValueTask<FluidValue> HasClaim(FluidValue input, FilterArguments arguments, TemplateContext ctx)
public static async ValueTask<FluidValue> HasClaim(FluidValue input, FilterArguments arguments, TemplateContext ctx)
{
if (input.ToObjectValue() is LiquidUserAccessor)
{
Expand Down
13 changes: 0 additions & 13 deletions src/OrchardCore.Modules/OrchardCore.Users/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,6 @@ public override void ConfigureServices(IServiceCollection services)
services.AddScoped<CustomUserSettingsService>();
services.AddRecipeExecutionStep<CustomUserSettingsStep>();
services.AddDisplayDriver<LoginForm, LoginFormDisplayDriver>();
services.AddScoped<ILoginFormEvent, EmailConfirmationLoginFormEvent>();
}

public override void Configure(IApplicationBuilder builder, IEndpointRouteBuilder routes, IServiceProvider serviceProvider)
Expand Down Expand Up @@ -276,16 +275,6 @@ public override void Configure(IApplicationBuilder builder, IEndpointRouteBuilde
}
}

[RequireFeatures("OrchardCore.Email")]
public sealed class EmailStartup : StartupBase
{
public override void ConfigureServices(IServiceCollection services)
{
services.AddScoped<UserEmailService>();
services.AddScoped<IRegistrationFormEvents, EmailConfirmationRegistrationFormEvents>();
}
}

[RequireFeatures("OrchardCore.Roles")]
public sealed class RolesStartup : StartupBase
{
Expand Down Expand Up @@ -443,8 +432,6 @@ public override void ConfigureServices(IServiceCollection services)
services.AddDisplayDriver<LoginForm, RegisterUserLoginFormDisplayDriver>();
services.AddDisplayDriver<RegisterUserForm, RegisterUserFormDisplayDriver>();
services.AddTransient<IConfigureOptions<RegistrationOptions>, RegistrationOptionsConfigurations>();
services.AddScoped<ILoginFormEvent, UserModerationLoginFormEvent>();
services.AddScoped<IRegistrationFormEvents, UserModerationRegistrationFormEvents>();
}

public override void Configure(IApplicationBuilder app, IEndpointRouteBuilder routes, IServiceProvider serviceProvider)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Security.Claims;
using System.Security.Claims;

namespace OrchardCore.Security;

Expand All @@ -7,5 +7,6 @@ public static class StandardClaims
/// <summary>
/// This claim is assigned by the system during the login process if the user belongs to the Administrator role.
/// </summary>
[Obsolete("This claim should not be used and will be removed in the next major release.")]
public static readonly Claim SiteOwner = new("SiteOwner", "true");
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;

namespace OrchardCore.Roles;

public static class ServiceCollectionExtensions
{
public static IServiceCollection AddRolesCoreServices(this IServiceCollection services)
{
return services.AddSingleton<ISystemRoleNameProvider, DefaultSystemRoleNameProvider>();
services.TryAddSingleton<ISystemRoleNameProvider, DefaultSystemRoleNameProvider>();

return services;
}
}

0 comments on commit 6bc7448

Please sign in to comment.