On 23 Nov, 2005, at 7:31 am, [EMAIL PROTECTED] wrote:
Personally, I would say this better be generalized to a user defined
function as these authorization thing can easily get too complex. There
you can implement using whatever thing that is appropriate(hook to
LDAP, your own RDBMS tables etc.)

I would definitely agree with this statement. The Identity management framework was intended to provide the basics ALL applications need. There's no possible way we could ever anticipate all requirements.

There are two ways to handle this:

1) Derive your Controller from SecureResource (in addition to Controller) and check the permissions explicitly. For example:

class MyController( controllers.Controller, identity.SecureResource ):

   [EMAIL PROTECTED]( html="mytemplate" )
    def myFunction( self ):
        if not ("admin" in identity.current.groups or \
                "super" in identity.current.groups):
            raise identity.GroupMembershipRequiredException( ("admin",
                                                              "super") )

This will work because SecureResource wraps all exposed methods with code that checks permissions and traps IdentityExceptions. So if your code throws, er, raises an IdentityException, everything will be handled correctly.

Of course, you can then pull your authorisation logic out into a function that you call rather than copying and pasting into each function that requires it.

2) Write your own decorator function. This is not for the faint at heart. But it gives you absolute flexibility. Take a look at the two decorators in turbogears/identity/conditions.py. They'll give you a head-start on what you'll have to do.

--
Jeff Watkins

In the USDA study [of the meat packing industry conducted in 1996] 78.6 percent of the ground beef contained microbes that are spread primarily by fecal material. The medical literature on the causes of food poisoning is full of euphemisms and dry scientific terms: coliform levels, aerobic plate counts, sorbitol, MacConkey agar, and so on. Behind them lies a simple explanation for why eating a hamburger can now make you seriously ill: There is shit in the meat.
-- Eric Schlosser, Fast Food Nation


Reply via email to