Blog moved

September 10th, 2005

My Blog has been moved… This is the new url: http://blogs.southworks.net/blogs/matiaswoloski

AzMan could define operations, tasks and roles. You can use operations and tasks from entlib.


Here you have a small AzMan wrapper class that will encapsulate how to use AzMan from EntLib
Note: this code is not tested nor compiled. It is provided as-is.


public class AzMan {
    public static bool CheckOperation( string operation, IPrincipal principal ) {
        return Check ( “O:” + operation, principal );
    }

    public static bool CheckTask( string task, IPrincipal principal ) {
        return Check ( task, principal );
    }


    private static bool Check( string context, IPrincipal principal ) {
        IAuthorizationProvider authzProv = AuthorizationFactory.GetAuthorizationProvider(“AzManProvider”);
        bool isAuthorized = authzProv.Authorize( principal, context );
        return isAuthorized;
    }
}


WindowsPrincipal principal = new WindowsPrincipal( WindowsIdentity.GetCurrent() );
if ( AzMan.CheckOperation( “PayBill”, principal ) {
    // principal can do operation PayBill
} else {
    // ERR!
}

if ( AzMan.CheckTask( “TransferFunds”, principal ) {
    // principal can do task TransferFunds
} else {
    // ERR!
}




 

Send an email when an exception is thrown using EntLib is not rocket science.

Here is a screen shot of how the configuration looks like

ex1

The steps involved are:

  1. Create an Exception Handling App Block
  2. Create a New Policy (for instance “Email Policy“)
  3. Create a new type of Exception to manage on the policy. Using “Exception“ will catch every kind of exception thrown
  4. Create a new Logging Handler for the Exception. Here the Logging and Instrumentation App Block will be added to the config.
  5. Add the Email Sink on the Logging Block and configure it (from and to email address, etc).
  6. Create a new Category (for instance “Several“) and add a new Destination
  7. Configure the Destintation to use the Text Formatter and the Email Sink
  8. Go to the Logging Handler node and set the LogCategory to “Several“

Here are the config files ExceptionLoggingToEmail.zip (2.91 KB)

Btw, sending an email is a task that requires some resources so
maybe It would be better to use the Async Logging as I described in the
last post. And let the distributor service to send the exception email in another process or server.