ReferencesProviderBase<TIdMemberReference,TIdReference>
Members
Namespace: ASPSecurityKit.Authorization
Assembly: ASPSecurityKit.dll
Summary
Provides an implementation for IReferencesProvider<TIdMemberReference> to aid in getting related references to authorize entityIds. See remarks for more details.
Generic Types
Name | Description |
---|---|
TIdMemberReference | The concrete type that implements IIdMemberReference model. |
TIdReference | The concrete type that implements IIdReference model. |
Remarks
This is only a partial (abstract) implementation. You should inherit from it and add actual loader definitions (methods) that return the related references.
A typical loader definition for an entityId named as ‘CustomerId’ looks like as follows: public List<TIdReference> CustomerId(guid id)
.
If you’re running the pipeline asynchronously, implement async definitions.
You can also add a multi-entityId loader definition which basically returns a a HashSet<TIdMemberReference>
(meaning collection of entityIds each of which needs to be authorized separately).
If you don’t want a method, that looks like a references loader definition, be treated as such, decorate it with the NotAReferencesLoaderAttribute.
For more detailed information, visit https://ASPSecurityKit.net/docs/how-to-perform-activity-based-data-aware-authorization/#obtaining-related-references
Constructors
#ctor(logger)
Summary
Initializes a new instance of the ReferencesProviderBase<TIdMemberReference,TIdReference> class.
Parameters
Name | Type | Description |
---|---|---|
logger | ASPSecurityKit.ILogger | The logger. |
Properties
Logger
Summary
Gets the ILogger instance.
Value
The ILogger instance.
Methods
IsDefinedFor(idMember)
Summary
Gets a value indicating whether any references loader has been defined for the given entityId member (the MemberName).
Returns
true
if any references loader has been defined for the given entityId member; otherwise, false
.
Parameters
Name | Type | Description |
---|---|---|
idMember | `0 | The entityId member. |
Exceptions
Type | Description |
---|---|
System.ArgumentNullException | When idMember is null. |
IsSyncDefinedFor(idMember)
Summary
Gets a value indicating whether a synchronous references loader has been defined for the given entityId member (the MemberName).
Returns
true
if a synchronous references loader has been defined for the given entityId member; otherwise, false
.
Parameters
Name | Type | Description |
---|---|---|
idMember | `0 | The entityId member. |
Exceptions
Type | Description |
---|---|
System.ArgumentNullException | When idMember is null. |
IsAsyncDefinedFor(idMember)
Summary
Gets a value indicating whether an async references loader has been defined for the given entityId member (the MemberName).
Returns
true
if an async references loader has been defined for the given entityId member; otherwise, false
.
Parameters
Name | Type | Description |
---|---|---|
idMember | `0 | The entityId member. |
Exceptions
Type | Description |
---|---|
System.ArgumentNullException | When idMember is null. |
GetReferences(idMember)
Summary
Gets the entityIds along with related references for the given entityId member. Multiple items are returned typically when the given entityId member has a collection value and each item of the collection needs to be authorized separately; otherwise, only one item is returned.
Returns
A HashSet`1 with TIdMemberReference
as the generic argument, comprising entityIds (with their related references) each of which needs to be authorized.
Parameters
Name | Type | Description |
---|---|---|
idMember | `0 | The entityId member. |
Exceptions
Type | Description |
---|---|
System.ArgumentNullException | When idMember is null. |
System.InvalidOperationException | When no references loader is registered for the given entityId member. |
GetReferencesAsync(idMember)
Summary
Gets the entityIds along with related references for the given entityId member. Multiple items are returned typically when the given entityId member has a collection value and each item of the collection needs to be authorized separately; otherwise, only one item is returned.
Returns
A HashSet`1 with TIdMemberReference
as the generic argument, comprising entityIds (with their related references) each of which needs to be authorized.
Parameters
Name | Type | Description |
---|---|---|
idMember | `0 | The entityId member. |
Exceptions
Type | Description |
---|---|
System.ArgumentNullException | When idMember is null. |
System.InvalidOperationException | When no references loader is registered for the given entityId member. |
GetReferencesAsync(idMember,cancellationToken)
Summary
Gets the entityIds along with related references for the given entityId member. Multiple items are returned typically when the given entityId member has a collection value and each item of the collection needs to be authorized separately; otherwise, only one item is returned.
Returns
A HashSet`1 with TIdMemberReference
as the generic argument, comprising entityIds (with their related references) each of which needs to be authorized.
Parameters
Name | Type | Description |
---|---|---|
idMember | `0 | The entityId member. |
cancellationToken | System.Threading.CancellationToken | The cancellation token. |
Exceptions
Type | Description |
---|---|
System.ArgumentNullException | When idMember is null. |
System.InvalidOperationException | When no references loader is registered for the given entityId member. |
Remarks
The default implementation tries to execute the async provider method first. If no async provider is registered and a synchronous definition is registered, it executes the same but also logs a warning.
NewIdMemberReference(memberName,value,parentName)
Summary
Creates a new instance of TIdMemberReference
type.
Returns
An instance of new TIdMemberReference
created.
Parameters
Name | Type | Description |
---|---|---|
memberName | System.String | The entityId member name. |
value | System.Object | The entityId member value. |
parentName | System.String | Optional. The name of the parent container object for this member. If provided, can be used for prefixing member name that has only ‘Id’ to locate the right related references provider. |
Exceptions
Type | Description |
---|---|
System.ArgumentNullException | When value is null or memberName is null/empty/whitespace. |
AddSelfAsReference(idMember)
Summary
Adds the entityId to its related references collection (References). Typically called when there’s no references loader defined (IsDefinedFor) for the given entityId and direct data authorization of the entityId is thus attempted.
Returns
true
if the entityId value was added successfully to its related references collection; otherwise, false
.
Parameters
Name | Type | Description |
---|---|---|
idMember | `0 | The entityId member. |
Exceptions
Type | Description |
---|---|
System.ArgumentNullException | When idMember is null. |