forked from petrsvihlik/WopiHost
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
petrsvihlik#192 use attribute-based authorization on controllers
- Loading branch information
Leon Segal
committed
Mar 6, 2025
1 parent
175a1f4
commit c792420
Showing
18 changed files
with
238 additions
and
257 deletions.
There are no files selected for viewing
41 changes: 41 additions & 0 deletions
41
src/WopiHost.Abstractions/IWopiAuthorizationRequirement.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,41 @@ | ||
namespace WopiHost.Abstractions; | ||
|
||
/// <summary> | ||
/// The Wopi resource type | ||
/// </summary> | ||
public enum WopiResourceType | ||
{ | ||
/// <summary> | ||
/// <see cref="IWopiFile"/> | ||
/// </summary> | ||
File, | ||
/// <summary> | ||
/// <see cref="IWopiFolder"/> | ||
/// </summary> | ||
Container | ||
}; | ||
|
||
|
||
/// <summary> | ||
/// Represents an authorization requirement for a given combination of resource, user, and action. | ||
/// </summary> | ||
/// <remarks> | ||
/// Creates an instance of <see cref="IWopiAuthorizationRequirement"/> initialized | ||
/// </remarks> | ||
public interface IWopiAuthorizationRequirement | ||
{ | ||
/// <summary> | ||
/// Gets a permissions required for a given combination of resource, user, and action. | ||
/// </summary> | ||
Permission Permission { get; } | ||
|
||
/// <summary> | ||
/// Gets the type of the resource. | ||
/// </summary> | ||
WopiResourceType ResourceType { get; } | ||
|
||
/// <summary> | ||
/// Gets or sets the identifier of the resource. | ||
/// </summary> | ||
string? ResourceId { get; set; } | ||
} |
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 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
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
src/WopiHost.Core/Security/Authorization/WopiAuthorizeAttribute.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 Microsoft.AspNetCore.Authorization; | ||
using WopiHost.Abstractions; | ||
|
||
namespace WopiHost.Core.Security.Authorization; | ||
|
||
/// <summary> | ||
/// Represents an authorization requirement for a given combination of resource, user, and action. | ||
/// </summary> | ||
/// <remarks> | ||
/// Creates an instance of <see cref="WopiAuthorizeAttribute"/> initialized with <paramref name="permission"/>. | ||
/// </remarks> | ||
/// <param name="permission">Permissions required for a given combination of resource, user, and action.</param> | ||
/// <param name="resourceType">type of the resource.</param> | ||
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = true, Inherited = true)] | ||
public class WopiAuthorizeAttribute( | ||
Permission permission, | ||
WopiResourceType resourceType) : AuthorizeAttribute, IWopiAuthorizationRequirement, IAuthorizationRequirement, IAuthorizationRequirementData | ||
{ | ||
/// <summary> | ||
/// Gets a permissions required for a given combination of resource, user, and action. | ||
/// </summary> | ||
public Permission Permission { get; } = permission; | ||
|
||
/// <summary> | ||
/// Gets the type of the resource. | ||
/// </summary> | ||
public WopiResourceType ResourceType { get; } = resourceType; | ||
|
||
/// <summary> | ||
/// Gets or sets the identifier of the resource. | ||
/// </summary> | ||
public string? ResourceId { get; set; } | ||
|
||
/// <summary> | ||
/// Gets the requirements. | ||
/// </summary> | ||
/// <returns></returns> | ||
public IEnumerable<IAuthorizationRequirement> GetRequirements() | ||
{ | ||
yield return this; | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.