-
Notifications
You must be signed in to change notification settings - Fork 4
Identifiers
EasyPermissionManagement
performs permission control by running the identifier method with the permission you set with the dynamic identifier method.
For example, suppose you have an identifier method of type User and let's develop the user identifier method step by step.
First, create the UserIdentifier
class using the IIdentifier
interface.
/// <summary>
/// User Identifier Method
/// </summary>
[RegisterIdentifier(PROVIDER)]
public class UserIdentifier : IIdentifier
{
/// <summary>
/// Provider name
/// </summary>
public const string PROVIDER = "User";
/// <summary>
/// Find Identifier Key
/// </summary>
/// <returns>
/// Task of String
/// </returns>
public Task<string> GetAsync()
{
// Return the identifier information to be checked.
}
}
Let's improve our example a little more;
When the UserIdentifier method we developed for User is used, let's assume that the id information in the route values on the incoming request is userId.
Remember that the UserId information is the identifier information that will be checked for the trace defined for us.
Let's add the necessary additions to find the id information from the route object in the request.
/// <summary>
/// User Identifier Method
/// </summary>
[RegisterIdentifier(PROVIDER)]
public class UserIdentifier : IIdentifier
{
/// <summary>
/// Ctor
/// </summary>
/// <param name="httpContextAccessor">
/// Provides access to the current Microsoft.AspNetCore.Http.IHttpContextAccessor.HttpContext,
/// if one is available.
/// </param>
public UserIdentifier(IHttpContextAccessor httpContextAccessor)
{
this.httpContextAccessor = httpContextAccessor;
}
/// <summary>
/// Provider name
/// </summary>
public const string PROVIDER = "User";
private readonly IHttpContextAccessor httpContextAccessor;
/// <summary>
/// Find Identifier Key
/// </summary>
/// <returns>
/// Task of String
/// </returns>
public Task<string> GetAsync()
{
string id = httpContextAccessor.HttpContext.Request.RouteValues["id"]?.ToString();
return Task.FromResult(id);
}
}
Different scenarios can be realized within Identifier methods.
For Example;
- Finding identifier key from Claims
- Finding identifier key from Database
- Finding identifer key from Session
- Finding identifer key from Cookie
- Finding identifer key from external service
Welcome to the EasyPermissionManagement
wiki!
Topics:
-
Getting Started
-
Databases
-
Implementations