Extending the Security Application Block
You extend the Security Application Block through designated extension points. Typically, these are custom classes, written by you, that implement a particular interface or derive from an abstract class. Because these custom classes exist in your application space, you do not have to modify or rebuild the block. Instead, you designate your extensions using configuration settings.
You can extend the block by adding a new type of Authorization Provider or by adding a new security cache provider that integrates with your chosen caching mechanism. The following table lists the interfaces and base classes that you can use to extend the block.
Custom Provider or Extension |
Interface or Base Class |
---|---|
Authorization Provider |
AuthorizationProvider |
Security Cache Provider |
ISecurityCacheProvider |
For detailed information about how to integrate custom providers with the Enterprise Library configuration system and configuration tools see Creating Custom Providers for Enterprise Library.
Creating an Authorization Provider
This procedure describes how to create a custom authorization provider class. The code example shows a framework you can use as a basis for the class.
To create a authorization provider class
- Create a new class that derives from the AuthorizationProvider class.
- Add the class attribute ConfigurationElementType. Specify the type CustomAuthorizationProviderData as the attribute parameter.
- Add a constructor that accepts an argument of type NameValueCollection.
- Implement the Authorize method. The Authorize method contains the authorization logic for the custom handler. When the method completes, it must return true if the user is authorized or false if the user is not authorized.
The following code example is a skeletal authorization provider class.
[ConfigurationElementType(typeof(CustomAuthorizationProviderData))]
public class MyAuthorizationProvider : AuthorizationProvider
{
public MyAuthorizationProvider(NameValueCollection configurationItems)
{
}
public override bool Authorize(IPrincipal principal, string context)
{
// Implement the authorization logic here.
}
}
'Usage
<ConfigurationElementType(GetType(CustomAuthorizationProviderData))> _
Public Class MyAuthorizationProvider
Inherits AuthorizationProvider
Public Sub New(ByVal ignore As NameValueCollection)
End Sub
Public Overrides Function Authorize (ByVal principal As IPrincipal, ByVal context As String) As Boolean
' Implement the authorization logic here.
End Function
End Class