CacheOptimizedPermitManager<TId>
Members
Namespace: ASPSecurityKit
Assembly: ASPSecurityKit.dll
Summary
Implements IPermitManager<TId> optimized for external cached storage like Redis.
Generic Types
Name | Description |
---|---|
TId | Type of key identifier used in the application. |
Remarks
The stored model is of type Dictionary<KeyWrapper<TId>, HashSet<string>> - basically permissionCodes are stored against each entityId. This is because usually in multi-tenant business applications many permissions are assigned against a higher-level entityId hence the latter repeats for many permissions. Since only EntityId and PermissionCode are persisted, if IPermit instances hold additional data that won’t be available from IPermit instances returned by this manager. Null entityIds are supported to support general permits.
Constructors
#ctor(sessionService)
Summary
Initializes a new instance of the CacheOptimizedPermitManager<TId> class.
Parameters
Name | Type | Description |
---|---|---|
sessionService | ASPSecurityKit.ISessionService | The session service. |
Properties
SessionService
Summary
Gets the session service.
Value
The session service.
Permits
Summary
Gets or sets the permits.
Value
The permits.
Exceptions
Type | Description |
---|---|
System.InvalidOperationException | When permits key is missing in the session store. |
Initialized
Summary
Gets a value indicating whether this instance is initialized.
Value
true
if this instance is initialized; otherwise, false
.
Remarks
Most operations are only available once the instance is initialized using Initialize. An exception could be thrown otherwise. Use this property to determine the initialization status safely.
Methods
Initialize(permits)
Summary
Initializes this instance with specified permits.
Parameters
Name | Type | Description |
---|---|---|
permits | System.Collections.Generic.IEnumerable<IPermit<TId>> | The permits. |
Exceptions
Type | Description |
---|---|
System.ArgumentNullException | When permits is null. |
Remarks
Every call to this method will completely override existing permits collection it holds.
Add(permit)
Summary
Adds the specified permit to the collection this instance holds.
Parameters
Name | Type | Description |
---|---|---|
permit | ASPSecurityKit.IPermit<TId> | The permit to add. |
Exceptions
Type | Description |
---|---|
System.ArgumentNullException | When permit is null. |
Contains(permitHash)
Summary
Determines whether this instance contains the specified permit.
Returns
true
if this instance contains the specified permit; otherwise, false
.
Parameters
Name | Type | Description |
---|---|---|
permitHash | System.String | The permit hash. |
Exceptions
Type | Description |
---|---|
System.ArgumentNullException | When permitHash is null/whitespace. |
Possesses(permissionCode)
Summary
Determines whether this instance contains any permit having the specified permissionCode.
Returns
true
if this instance contains some permit having the specified permissionCode; otherwise, false
.
Parameters
Name | Type | Description |
---|---|---|
permissionCode | System.String | The permission code. |
Exceptions
Type | Description |
---|---|
System.ArgumentNullException | When permissionCode is null/whitespace. |
GetEntityIds(permissionCode)
Summary
Gets all the entity ids associated with the specified permissionCode across the entire permits collection this instance holds.
Returns
All the entity ids associated with the specified permissionCode across the entire permits collection this instance holds.
Parameters
Name | Type | Description |
---|---|---|
permissionCode | System.String | The permission code. |
Exceptions
Type | Description |
---|---|
System.ArgumentNullException | When permissionCode is null/whitespace. |
GetPermits()
Summary
Gets the entire permits collection this instance holds.
Returns
The entire permits collection this instance holds.
Parameters
This method has no parameters.
CreatePermitHash(permissionCode,entityId)
Summary
Creates a unique hash for the specified permissionCode and entityId.
Returns
A unique hash for the specified permissionCode and entityId.
Parameters
Name | Type | Description |
---|---|---|
permissionCode | System.String | The permission code. |
entityId | System.String | The entity identifier. |
Exceptions
Type | Description |
---|---|
System.ArgumentNullException | When permissionCode is null/whitespace. |
CreatePermitHash(permissionCode,entityId)
Summary
Creates a unique hash for the specified permissionCode and entityId.
Returns
A unique hash for the specified permissionCode and entityId.
Parameters
Name | Type | Description |
---|---|---|
permissionCode | System.String | The permission code. |
entityId | System.Nullable<TId> | The entity identifier. |
Exceptions
Type | Description |
---|---|
System.ArgumentNullException | When permissionCode is null/whitespace. |
GetStorageData()
Summary
Gets the data this instance holds in a raw format (to persist in external cache, for instance).
Returns
The data this instance holds in a raw format.
Parameters
This method has no parameters.
SetStorageData(data)
Summary
Re-initializes this instance with the specified raw data (previously obtained via GetStorageData).
Parameters
Name | Type | Description |
---|---|---|
data | System.Object | The raw data. |
Clear()
Summary
Clears the data this instance holds.
Parameters
This method has no parameters.
Add(permits,permit)
Summary
Adds the specified permit into the given permits collection.
Parameters
Name | Type | Description |
---|---|---|
permits | System.Collections.Generic.Dictionary<KeyWrapper<TId>, HashSet<string>> | The permits collection into which permit is to be added. |
permit | ASPSecurityKit.IPermit<TId> | The permit to add. |
Exceptions
Type | Description |
---|---|
System.ArgumentNullException | When permits is null or permit.PermissionCode is null/whitespace. |
GetPermissionsMap()
Summary
Gets the permissions map in which the key is computed using CreatePermitHash and the value (of type IPermit<TId>) is created on the fly based on stored permissionCode-entityId list.
Returns
The permissions map.
Parameters
This method has no parameters.