List Info

Thread: discern the current stage in filter API ?




discern the current stage in filter API ?
user name
2006-05-14 22:29:58
jvanasco wrote:
> First, to answer your question about the use:
> I'm implementing my own 'identity' system in a
> Turbogears application, as their current system
> was incompatible with my application and design
> requirements.
> ...
> class SecuredController(tg.controllers.Controller):
>     def __getattribute__( self, name ):
>         if name[:3]=="_cp":
>             return
tg.controllers.Controller.__getattribute__(self,name)
>         if get_current_filter_phase() ==
'before_main':
>             if not get_request_logged_in():
>                 raise
SecuredControllerFailure("/login/login_required"
)
>         value= object.__getattribute__(self,name)
>         return value
> 
> I needed to know the current filter phase, as TG
> internally makes calls to the controller class
> and cherrypy already does as well.

I think I understand. There's certainly a design flaw in
CherryPy 2, in that you cannot raise InternalRedirect from
anywhere other than a before_main filter method (or a
controller method/page handler). And although I think your
specific case can be addressed in another fashion (see next
para), CherryPy might benefit from something like
mod_perl's "current_callback" function. Thanks
for the idea (and especially the use case ;)!

However, I'm a bit confused about the above code...it seems
that, if the "current phase" is not
"before_main", then you go ahead and grant
access anyway. If you're going to do that, then you might
as well write:

class LoginFilter:
    def before_main(self):
        if not get_request_logged_in():
            raise
SecuredControllerFailure("/login/login_required"
)

class SecuredController(tg.controllers.Controller):
    
    _cp_filters = [LoginFilter()]


...right? That is, rather than test for authorization 100
times and ignore the first 99 failures, just test once at
the right time. That's probably a naive recommendation,
because I missed some requirement. But perhaps the different
approach will inspire you toward a simpler solution. ;)


Robert Brewer
System Architect
Amor Ministries
fumanchuamor.org


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "cherrypy-users" group.
To post to this group, send email to cherrypy-usersgooglegroups.com
To unsubscribe from this group, send email to
cherrypy-users-unsubscribegooglegroups.com
For more options, visit this group at http://
groups.google.com/group/cherrypy-users
-~----------~----~----~----~------~----~------~--~---
discern the current stage in filter API ?
user name
2006-05-15 01:07:31
no, thats a great idea.  i'll give it a shot.

one of the reasons why i'm not using TG's identity, is
that there are
way too many function calls and tests.  my approach was
actually a
large reduction.  yours will be even more.

without saying too much that people might yell at me -
mod_perl has a
lot of great ideas in it.


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "cherrypy-users" group.
To post to this group, send email to cherrypy-usersgooglegroups.com
To unsubscribe from this group, send email to
cherrypy-users-unsubscribegooglegroups.com
For more options, visit this group at http://
groups.google.com/group/cherrypy-users
-~----------~----~----~----~------~----~------~--~---

[1-2]

about | contact  Other archives ( Real Estate discussion Medical topics )