Generic CSLA Authorization Rules

Instead of hardcode in client side, it makes sense to read those authorization setting from db or xml file. Here is my idea:


        public static bool CanGetObject()
        {

            return MyAuthorization.GetReadersRoleListOnObject(_typeOfCurrentObject)
                .Where(role => Csla.ApplicationContext.User.IsInRole(role) == true)
                .Count() > 0;

        }

        protected override void AddAuthorizationRules()
        {
            foreach (var prop in GetType().GetProperties().Where( a => a.DeclaringType.Name != "BusinessBase"))
            {
                AuthorizationRules.AllowRead(prop.Name,
                   MyAuthorization.GetReadersRoleListOnProperty<MyCslaBO>(prop.Name).ToArray());
            }

            ... same loop for AllowWrite() ...

       }

Many reflections used here, the performance might be slow.

Also, the AuthorizationRules.AllowExecute(methodname, roles) seems hard to use reflection to get the method list.

Advertisements

One thought on “Generic CSLA Authorization Rules

  1. Pingback: Introducción a CslaUser: Demo CSLA 3.7 « BeyondNet

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s