-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
133 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
ControlR.Web.Server/Authz/Policies/DeviceAccessByDeviceResourcePolicy.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
using ControlR.Web.Client.Extensions; | ||
using Microsoft.AspNetCore.Authorization; | ||
|
||
namespace ControlR.Web.Server.Authz.Policies; | ||
|
||
public static class DeviceAccessByDeviceResourcePolicy | ||
{ | ||
public const string PolicyName = "DeviceAccessByDeviceResourcePolicy"; | ||
|
||
public static AuthorizationPolicy Create() | ||
{ | ||
return new AuthorizationPolicyBuilder() | ||
.RequireAuthenticatedUser() | ||
.RequireServiceProviderAssertion((sp, handlerCtx) => | ||
{ | ||
if (handlerCtx.Resource is not Device device) | ||
{ | ||
return false; | ||
} | ||
|
||
if (handlerCtx.User.TryGetTenantId(out var tenantId)) | ||
{ | ||
return false; | ||
} | ||
|
||
if (device.TenantId != tenantId) | ||
{ | ||
return false; | ||
} | ||
|
||
if (handlerCtx.User.IsInRole(RoleNames.ServerAdministrator) || | ||
handlerCtx.User.IsInRole(RoleNames.DeviceAdministrator)) | ||
{ | ||
return true; | ||
} | ||
|
||
handlerCtx.Fail(); | ||
return false; | ||
}) | ||
.Build(); | ||
} | ||
} |
25 changes: 0 additions & 25 deletions
25
ControlR.Web.Server/Authz/Policies/RemoteControlByDevicePolicy.cs
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
using Microsoft.AspNetCore.Authorization; | ||
|
||
namespace ControlR.Web.Server.Authz; | ||
|
||
public class ServiceProviderAsyncRequirement(Func<IServiceProvider, AuthorizationHandlerContext, Task<bool>> assertion) | ||
: IAuthorizationRequirement | ||
{ | ||
public Func<IServiceProvider, AuthorizationHandlerContext, Task<bool>> Assertion { get; } = assertion; | ||
} |
19 changes: 19 additions & 0 deletions
19
ControlR.Web.Server/Authz/ServiceProviderAsyncRequirementHandler.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
using Microsoft.AspNetCore.Authorization; | ||
|
||
namespace ControlR.Web.Server.Authz; | ||
|
||
public class ServiceProviderAsyncRequirementHandler(IServiceProvider serviceProvider) : IAuthorizationHandler | ||
{ | ||
private readonly IServiceProvider _serviceProvider = serviceProvider; | ||
|
||
public async Task HandleAsync(AuthorizationHandlerContext context) | ||
{ | ||
foreach (var requirement in context.Requirements.OfType<ServiceProviderAsyncRequirement>()) | ||
{ | ||
if (await requirement.Assertion.Invoke(_serviceProvider, context)) | ||
{ | ||
context.Succeed(requirement); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters