Extending the Security Application Block

Retired Content

This content is outdated and is no longer being maintained. It is provided as a courtesy for individuals who are still using these technologies. This page may contain URLs that were valid when originally published, but now link to sites or pages that no longer exist.

The latest Enterprise Library information can be found at the Enterprise Library site.

The Security Application Block was designed to be used in a variety of applications and to be a general purpose application block. Extension points allow to you adapt the application block to suit the needs of any particular application. You can extend the capabilities of the block by adding custom providers.

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

  1. Create a new class that derives from the AuthorizationProvider class.
  2. Add the class attribute ConfigurationElementType. Specify the type CustomAuthorizationProviderData as the attribute parameter.
  3. Add a constructor that accepts an argument of type NameValueCollection.
  4. Implement the Authorize method. The Authorize method contains the authorization logic for the custom handler. When the method completes, it returns true if the user is authorized and 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
Retired Content

This content is outdated and is no longer being maintained. It is provided as a courtesy for individuals who are still using these technologies. This page may contain URLs that were valid when originally published, but now link to sites or pages that no longer exist.

The latest Enterprise Library information can be found at the Enterprise Library site.