[Grok-dev] Make self.request.principal to be an instance of MyOwnPrincipalInfo (my own class)

Hector Blanco white.lists at gmail.com
Mon Jan 10 10:00:37 EST 2011


Thanks for all your replies

2011/1/10 Jan-Wijbrand Kolman <janwijbrand at gmail.com>:
> On 1/9/11 21:57 PM, Hector Blanco wrote:
>> --------------- (in app.py) ---------------
>> def authenticateCredentials(self, credentials):
>>       if isinstance(credentials, dict):
>>               if (("login" in credentials) and ("password" in credentials)):
>>                       user = self.getAccount(credentials['login'])
>>                       if user and (user.checkPassword(credentials['password'])):
>>                               return MyOwnPrincipalInfo.MyOwnPrincipalInfo(user)
>>       return None

> This "def authenticateCredentials()" method is implemented where in your
> code? If you want to do this, you'd need to create your own
> IAuthentication utility and register that for you site.

I put it in app.py

> Another possibility, if you for some reason you cannot use the dolmen.*
> packages that would provide features you are looking for, is to create
> your own IAuthenticatedPrincipalFactory adapter.
> This adapter is looked up whenever the Pluggable Authentication Utility
> creates an authenticated principal from the principal info that was
> found. There you could hook in you own implementation, something like
> (incomplete and untested, but I hope you get the idea!):
> class MyOwnPrincipalInfo(grok.MultiAdapter):
>         grok.adapts(IPrincipalInfo, IBrowserRequest)
>        grok.implements(IPrincipalInfo)
>        def someOtherVeryCoolStuff(self):
>                # do whatever

Gonna try that... Let's see what happens :)

> regrrds, jw

Thanks again for all the hints

More information about the Grok-dev mailing list