-
Notifications
You must be signed in to change notification settings - Fork 1
SecurityProvider
Telefrag supports pluggable discretionary access control-based security because not every application will need complex access control, and security processing adds overhead to any bot or application. This allows you to choose the security model that is right for your particular application (or write your own).
Telefrag items that have pluggable security implement ISecurityConsumer, which exposes a Security property that is used to access the security operations for that object. Think of this like the "Security" tab on the property pages of various constructs in Windows.
Accessing the Security property (which is a reference to ISecurityAccessor) requires that a security provider be registered to facilitate those operations (and potentially add other security functionality beyond the required interface). If an ISecurityProvider is not registered, a NoSecurityProviderException() is thrown.
The following related object types are part of the security ecosystem:
| Abstract Type | Concrete Type | Description |
|---|---|---|
| ISecurityProvider | NullSecurityProvider SingleOwnerSecurityProvider StandardSecurityProvider |
Implements the details of managing, storing, and evaluating the access control lists |
| ISecurityConsumer | Bot Client |
A primary object (which is also an IComponentNode) for which a security provider (ISecurityProvider) would be registered. Access lists for the ISecurityConsumer itself as well as other tangential ISecurable objects can be facilitated through its Security property. |
| ISecurable | (many classes) | Any securable object for which an access list can be accessed, manipulated, and evaluated |
| ISecurityAccessor | SecurityAccessor RootSecurityAccessor |
The object on the Security property of an ISecurityConsumer, a menu class that allows you to manage the access list for an object and perform other security functions. |
Security is abstracted through the ISecurityProvider interface. A security provider essentially implements these operations:
- GetSecurityAccessor(ISecurable) - Gets the security accessor for a securable object
- GetAccessList(ISecurable) - Gets the discretionary access control list for a securable object
- HasAccess(ISecurable, Permission, Context) - Tests if the context has access to permission specified on the item
- AssertSecurity(ISecurable, Permission, Context) - Asserts access on the secured object and throws an exception if the user does not have access
- FindAccessEntry(ISecurable, Permission, Context, bool) - Finds the first access entry in the secured object's access control list that matches the user for the permission specified.
This is the standard security provider that ships with Telefrag. It will maintain access lists for any ISecurable object and evaluate them as requested. Its mechanics work very similarly to Windows security; access entries can be Allow or Deny entries; and deny entries take precedence over allow entries.
A security provider that grants full access to a single Telegram user ID and denies all other access.
NullSecurityProvider is a security provider that allows all actions (e.g. no security). It's intended only for use in mocking, testing, and during development.
HasAccess always returns true and AssertSecurity does nothing. Any other attempt to modify security (such as accessing an AccessList) will fail.
To user a security provider, simply register it to the ISecurityProvider type on the corresponding bot/client:
bot.Components.Register<ISecurityProvider, StandardSecurityProvider>();
// OR
var prov = bot.Components.Register<ISecurityProvider, SingleOwnerSecurityProvider>();
prov.SetOwner(owner_id);You can also use the convenience methods included in SecurityExtensions:
During instantiation:
var bot = new Bot("test", o =>
{
o.UseSecurity<StandardSecurityProvider>();
});At any time:
bot.AddStandardSecurity();
bot.AddSingleOwnerSecurity(owner_id);