Quantcast
Channel: CSLA .NET
Viewing all articles
Browse latest Browse all 764

Changing "AuthorizationRuleManager" behaviour.

$
0
0

Base class:

public class MyBusinessBase<T> : BusinessBase<T> where T:  MyBusinessBase<T>

{

    protected static void AddObjectAuthorizationRules()
    {
        var tp = typeof(T);
        var roleName = "role_" + tp;
        BusinessRules.AddRule(tp, new IsInRole(AuthorizationActions.CreateObject, roleName));
        BusinessRules.AddRule(tp, new IsInRole(AuthorizationActions.GetObject, roleName));
    }

}

 

If we will change "AuthorizationRuleManager" behaviour like this:

    private static void InitializePerTypeRules(AuthorizationRuleManager mgr, Type type)
    {

        ...

        var type2 = type;
        var flags = BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic |  BindingFlags.DeclaredOnly;
        while (type2 != typeof(object))
        {
            // invoke method to add auth roles
            var method = type2.GetMethod("AddObjectAuthorizationRules", flags);
            if (method != null)
            {
                method.Invoke(null, null);
                break;
            }
            type2 = type2.BaseType;
        }

        ...

    }

 

We will achive next:

- all inherited objects will inherit  "AddObjectAuthorizationRules" method. And I can even override this method.

 

So, is this good or bad idea?


Viewing all articles
Browse latest Browse all 764

Trending Articles