[Grok-dev] Make self.request.principal to be an instance of MyOwnPrincipalInfo (my own class)
Jan-Wijbrand Kolman
janwijbrand at gmail.com
Mon Jan 10 04:34:51 EST 2011
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
snip
> I guess that if the principal info is implementing a factory pattern I
> should register MyOwnPrincipalInfo class as "returnable" by the
> factory, but I don't really know how to do that.
>
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.
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
HTH
regrrds, jw
More information about the Grok-dev
mailing list