Business Base Authorization Question

Business Base Authorization Question

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


jfreeman posted on Friday, November 21, 2008

I have a Business Base object that I want to allow users to edit if they are in a certain AD group.  However, if they are not in the group I would like to prevent them from making changes to the fields (basically mark all the fields read-only).  I don't want them trying to make changes and then realize after they hit the Save button that they do not have the correct authorization.  Is there a way to do this.  Thanks.

Jonathan         

ajj3085 replied on Friday, November 21, 2008

Yes, usually you override AddAuthorizationRules in you BB subclass, and call AuthorizationRules.AllowWrite( property, roles ).  Then you can use the ReadWriteAuthoriztion component if you're in Windows Forms or PropertyStatus will handle it in Wpf.

jfreeman replied on Friday, November 21, 2008

So I would need to call AuthorizationRules.AllowWrite for each field on the object.  I have about 75 fields on this object.  Is that the only way to handle this?  Thanks for you help.

Jonathan

sergeyb replied on Friday, November 21, 2008

Something like this is what I use:

protected override void AddAuthorizationRules()

        {

            string[] writeRoles = new string[] { SecurityRole.UberAdmin.ToString() };

            foreach (var item in this.FieldManager.GetRegisteredProperties())

            {

                 AuthorizationRules.AllowWrite(item, writeRoles);

            }

        }

 

Saves a lot of typing.

 

Sergey Barskiy

Principal Consultant

office: 678.405.0687 | mobile: 404.388.1899

cid:_2_0648EA840648E85C001BBCB886257279
Microsoft Worldwide Partner of the Year | Custom Development Solutions, Technical Innovation

 

From: jfreeman [mailto:cslanet@lhotka.net]
Sent: Friday, November 21, 2008 4:46 PM
To: Sergey Barskiy
Subject: Re: [CSLA .NET] Business Base Authorization Question

 

So I would need to call AuthorizationRules.AllowWrite for each field on the object.  I have about 75 fields on this object.  Is that the only way to handle this?  Thanks for you help.

Jonathan



jfreeman replied on Friday, November 21, 2008

Thank you Sergey.  You rock!

Jonathan

jfreeman replied on Monday, November 24, 2008

I was able to use the code from Sergey and it works perfectly.  However, by turning on Authorization for every control on the form, the screen now takes 30 seconds to load.  Before I made the changes it took about 3 seconds.  The screen has about 100 fields on it.  Is there any way to decrease the load time?  I don't think the users are going to like waiting 30 seconds to open this screen.  Thanks.

Jonathan

sergeyb replied on Monday, November 24, 2008

By authorization control do you mean PropertyStatus (WPF) or AuthorizeReadWrite (WinForms)?

 

Sergey Barskiy

Principal Consultant

office: 678.405.0687 | mobile: 404.388.1899

cid:_2_0648EA840648E85C001BBCB886257279
Microsoft Worldwide Partner of the Year | Custom Development Solutions, Technical Innovation

 

From: jfreeman [mailto:cslanet@lhotka.net]
Sent: Monday, November 24, 2008 12:49 PM
To: Sergey Barskiy
Subject: Re: [CSLA .NET] RE: Business Base Authorization Question

 

I was able to use the code from Sergey and it works perfectly.  However, by turning on Authorization for every control on the form, the screen now takes 30 seconds to load.  Before I made the changes it took about 3 seconds.  The screen has about 100 fields on it.  Is there any way to decrease the load time?  I don't think the users are going to like waiting 30 seconds to open this screen.  Thanks.

Jonathan



jfreeman replied on Monday, November 24, 2008

Sorry.  I should have clarified.  WinForms AuthorizeReadWrite.  Thanks.

Jonathan

sergeyb replied on Monday, November 24, 2008

I just looked at the class, and it does have a fair amount of reflection, but I cannot imagine that it would take anywhere near 30 seconds for 100 fields.  Something else I causing the issue, I think.  Could it be that there is something else going on that causes this component to fire too many times?

 

Sergey Barskiy

Principal Consultant

office: 678.405.0687 | mobile: 404.388.1899

cid:_2_0648EA840648E85C001BBCB886257279
Microsoft Worldwide Partner of the Year | Custom Development Solutions, Technical Innovation

 

From: jfreeman [mailto:cslanet@lhotka.net]
Sent: Monday, November 24, 2008 1:54 PM
To: Sergey Barskiy
Subject: Re: [CSLA .NET] RE: RE: Business Base Authorization Question

 

Sorry.  I should have clarified.  WinForms AuthorizeReadWrite.  Thanks.

Jonathan



jfreeman replied on Monday, December 01, 2008

I've stepped through my code a few times to make sure and it only calls ResetControlAuthorization one time.  I stumped.  Any other ideas?

Jonathan

Copyright (c) Marimer LLC