[mod_python] Accesshandler and normal handler... how they working ?

Jim Gallacher jpg at jgassociates.ca
Tue Nov 14 10:45:00 EST 2006


durumdara wrote:
> Hi !
> 
> I have an access handler, and a normal python handler in my site.
> I use directories, and some of them are need protection. I use my login
> method to enable user access.
> 
> The access handler is check the needed rights to any object. It get user
> data from Session.
> When access granted, it finished it's working.
> When access denied, it send http403 error, and I catch this with custom
> error documents (ssi).
> 
> But I want to know something - the background of access handler.
> 
> 1.)
> The access handler is existing in same Thread as Handler ?

Yes.

> So I want to know. Is modpy do this:
> get url, server info, etc.
> build request + other objects
> get thread
> result = thread.startaccesshandler(req)
> if not result:
>  gotoerrorhandler
> else:
>  result = thread.handler(req)
> ....
> or it use another technology ?

Unless I'm misunderstanding your question, you don't need to mess with 
threads. You are always dealing with the same request object, regardless 
of which phase, and there is one process or thread per request.

Take a look at the mod_python documentation for PythonAuthenHandler, as 
well as my reply to Richard Lewis today on a similar question.

> 2.)
> Can I exchange some data across them ?

Yes.

def authenhandler(req):
     req.foo = 'something for later'
     ...


def handler(req):
     req.write(req.foo)
     ...


> In this time I use file based right table(s).
> Every file in this table has right property.
> I need to load this table in the accesshandler to check grants.
> And later, in the menu building I also need to load this table to check
> grants (the menus are not accessable by user are hided).
> Can I share these infos ? Can I write to the request object, and this
> object is hold these infos to get them in normal handler ?

Yes.

> 3.)
> Can I force the access handler to redirect request ?

Yes.

> Example: the user click on menu that preserved for special users. I
> don't want to redirect to error pages. Can I redirect to my special
> page, 

Yes.

Jim


More information about the Mod_python mailing list