CommandBase Authorizaition binding to UI

CommandBase Authorizaition binding to UI

Old forum URL: forums.lhotka.net/forums/t/10563.aspx


Ranjini posted on Tuesday, July 26, 2011

Please refer to this posting as a starting point - http://forums.lhotka.net/forums/p/10540/49324.aspx#49324

The suggestion to add a rule on the EditObject authorizationaction worked perfectly. However, I am now tryign to show/hide a UI link based on whether the execute action on the commandbase object is permitted. In order to do this, I added the following

 

 

 

 

 

 

public static bool CanEditObject ()

{

 

 

return Csla.Rules.BusinessRules.HasPermission(Csla.Rules.AuthorizationActions.EditObject, typeof(CommandName

)); }

However when using CanEditObject , it throws the following exception

 'Business.CommandName.CanEditObject()' threw an exception of type 'System.MethodAccessException' bool {System.MethodAccessException}

 

 

 

JonnyBee replied on Tuesday, July 26, 2011

Not sure of what could be wrong here - but this code and unit test runs OK:

    [Serializable]
    public class LookupCustomerCommand : CommandBase<LookupCustomerCommand>
    {
        public static bool CanEditObject()
        {
          return BusinessRules.HasPermission(Csla.Rules.AuthorizationActions.EditObjecttypeof(LookupCustomerCommand));
        }
 
        protected static void AddObjectAuthorizationRules()
        {
          BusinessRules.AddRule(typeof(LookupCustomerCommand),
              new Csla.Rules.CommonRules.IsInRole(AuthorizationActions.EditObject"role1""role2"));
        }
}

    [TestMethod()]     public void CanNotEditCommand()     {       Assert.IsFalse(LookupCustomerCommand.CanEditObject());     }

Ranjini replied on Wednesday, July 27, 2011

Is this v4.1.0? That is what I am running and I am continuing to run into this problem.

JonnyBee replied on Wednesday, July 27, 2011

Which platform and UI technology do you get the exception on?   .NET 4 or SL4 or WP?

 

 

 

 

Ranjini replied on Wednesday, July 27, 2011

Silverlight 4/ CSLA 4.1.0

JonnyBee replied on Thursday, July 28, 2011

Hi Ranjini,

I believe the solution for your problem is to change the AddObjectAuthorizationRules to be a public method rather than protected.

Limitations in reflection in Silverlight throws the exception when a method is not accessible for other classes (ie: protected and private).

Read more here: http://msdn.microsoft.com/en-us/library/stfy7tfc%28v=vs.95%29.aspx

 

Ranjini replied on Tuesday, August 02, 2011

Thanks!

Copyright (c) Marimer LLC