CSLA .NET

From Rockford Lhotka's Expert C# 2005 and VB 2005 Business Objects books

Welcome to CSLA .NET Sign in | Join | Help
in Search

security to the class based on roles

Last post 10-20-2006, 7:17 AM by ajj3085. 5 replies.
Sort Posts: Previous Next
  •  10-19-2006, 8:16 AM 7968

    security to the class based on roles

    I want to set up security to my classes so that only authorized user can use the class else an exception to be throw.so when i first call the class in my constructor i want to check if the user is authenticated.How should i implement this.
  •  10-19-2006, 8:40 AM 7969 in reply to 7968

    Re: security to the class based on roles

    Check out the Project class from the ProjectTracker demo. 

    You define some static members to get a boolean to determine if an opeation (such as fetch) is allowed.  Then in your fetch factory methods, you throw a security exception if the user doesn't have permission.

    HTH
    Andy
  •  10-19-2006, 10:16 AM 7984 in reply to 7969

    Re: security to the class based on roles

    I had a look the project class.Would you please show me a simple example here of the static method you are talking about?

     

  •  10-19-2006, 10:37 AM 7986 in reply to 7984

    Re: security to the class based on roles

    In the project class, check out the method at line 201 and the method at 235 (assuming csla 2.1)

    Andy
  •  10-19-2006, 9:20 PM 8025 in reply to 7986

    Re: security to the class based on roles

    i am using Expert c# business objects not the Expert c# 2005 business objects book.Would any one help me with this
  •  10-20-2006, 7:17 AM 8032 in reply to 8025

    Re: security to the class based on roles

    Its the same in both versions of the book.  Look on page 479 of your book (I have both editions), all three code samples show checking the user's role, and if the user doesn't belong to one of the specified roles, a security exception is thrown.

    The only difference is that in the new edition of the book, Rocky wraps up the big if statement checking roles into a seperate method, called CanEdit or something like that.  The concept is the same, and the CanEdit static method is a good idea because you can expose that to the UI, which can hide controls or menus based on its return value.

    HTH
    Andy
View as RSS news feed in XML

Please contact Magenic for your .NET consulting and CSLA .NET mentoring needs.
Please consider making a donation to help support the ongoing development of CSLA .NET.

Make donation through PayPal - it's fast, free and secure!
Why donate?
Powered by Community Server, by Telligent Systems