Re: [Zope3-Users] Run starup code with zope 3.
Le jeudi 12 février 2009 à 17:50 +0100, Sebastian Bartos a écrit : I'm struggling with some Zope 3 startup code. I registered a user like this for the Session Credentials plugin and login form stuff: ... def create(self, data): site = getSite() sm = site.getSiteManager() if sm.has_key('auth'): return Site is already set up pau = Pluggableauth() sm['auth'] = pau sm.registerUtility(pau, Iauth) users = PrincipalFolder() sm['auth']['Users'] = users sm.registerUtility(users, IAuthenticatorPlugin, name=Users) pau.authenticatorPlugins = (users.__name__, ) pau.credentialsPlugins = (No Challenge if Authenticated, Session Credentials) user = InternalPrincipal(user, foo, user, passwordManagerName=SHA1) users[user] = user principalPermissionManager.grantAllPermissionsToPrincipal(user) To run code automatically at application startup, I think that you should have a look at the IDatabaseOpenedWithRootEvent (defined in zope.app.appsetup.interfaces). I use this event to check a set of persistent database utilities at application startup, and it works fine. Thierry Florac -- Chef de projet intranet/internet Office National des Forêts - Département Informatique 2, Avenue de Saint-Mandé 75570 PARIS Cedex 12 Mél : thierry.flo...@onf.fr Tél. : +33 01.40.19.59.64 Fax. : +33 01.40.19.59.85 ___ Zope3-users mailing list Zope3-users@zope.org http://mail.zope.org/mailman/listinfo/zope3-users
Re: [Zope3-Users] Run starup code with zope 3.
2009/2/12 Thierry Florac thierry.flo...@onf.fr: Le jeudi 12 février 2009 à 17:50 +0100, Sebastian Bartos a écrit : I'm struggling with some Zope 3 startup code. I registered a user like this for the Session Credentials plugin and login form stuff: ... def create(self, data): site = getSite() sm = site.getSiteManager() if sm.has_key('auth'): return Site is already set up pau = Pluggableauth() sm['auth'] = pau sm.registerUtility(pau, Iauth) users = PrincipalFolder() sm['auth']['Users'] = users sm.registerUtility(users, IAuthenticatorPlugin, name=Users) pau.authenticatorPlugins = (users.__name__, ) pau.credentialsPlugins = (No Challenge if Authenticated, Session Credentials) user = InternalPrincipal(user, foo, user, passwordManagerName=SHA1) users[user] = user principalPermissionManager.grantAllPermissionsToPrincipal(user) To run code automatically at application startup, I think that you should have a look at the IDatabaseOpenedWithRootEvent (defined in zope.app.appsetup.interfaces). I use this event to check a set of persistent database utilities at application startup, and it works fine. Also, zope.securitypolicy provides a way to store location-based grants. Just adapt your site object to IPrincipalRoleManager or to IPrincipalPermissionManager (defined in zope.security.interfaces) and use its methods to allow/deny roles/permissions to some principal ID. It will handle the actual storing work. Child objects will inherit parent's settings until they have their own local settings. -- WBR, Dan Korostelev ___ Zope3-users mailing list Zope3-users@zope.org http://mail.zope.org/mailman/listinfo/zope3-users
Re: [Zope3-Users] Run starup code with zope 3.
Was playing with the event system a bit, and ended up with the following, which works fine: import zope.event class MyEvent: pass event = MyEvent() def f(event): if isinstance(event, zope.app.appsetup.interfaces.ProcessStarting): Put stuff you want to execute after server startup here. principalPermissionManager.grantAllPermissionsToPrincipal(use) zope.event.subscribers.append(f) ... Is this a good zopey way? - Seth On Thu, 2009-02-12 at 20:32 +0300, Dan Korostelev wrote: 2009/2/12 Thierry Florac thierry.flo...@onf.fr: Le jeudi 12 février 2009 à 17:50 +0100, Sebastian Bartos a écrit : I'm struggling with some Zope 3 startup code. I registered a user like this for the Session Credentials plugin and login form stuff: ... def create(self, data): site = getSite() sm = site.getSiteManager() if sm.has_key('auth'): return Site is already set up pau = Pluggableauth() sm['auth'] = pau sm.registerUtility(pau, Iauth) users = PrincipalFolder() sm['auth']['Users'] = users sm.registerUtility(users, IAuthenticatorPlugin, name=Users) pau.authenticatorPlugins = (users.__name__, ) pau.credentialsPlugins = (No Challenge if Authenticated, Session Credentials) user = InternalPrincipal(user, foo, user, passwordManagerName=SHA1) users[user] = user principalPermissionManager.grantAllPermissionsToPrincipal(user) To run code automatically at application startup, I think that you should have a look at the IDatabaseOpenedWithRootEvent (defined in zope.app.appsetup.interfaces). I use this event to check a set of persistent database utilities at application startup, and it works fine. Also, zope.securitypolicy provides a way to store location-based grants. Just adapt your site object to IPrincipalRoleManager or to IPrincipalPermissionManager (defined in zope.security.interfaces) and use its methods to allow/deny roles/permissions to some principal ID. It will handle the actual storing work. Child objects will inherit parent's settings until they have their own local settings. -- Sebastian Bartos, seth.kriti...@googlemail.com keyserevr: pgp.mit.edu signature.asc Description: This is a digitally signed message part ___ Zope3-users mailing list Zope3-users@zope.org http://mail.zope.org/mailman/listinfo/zope3-users
Re: [Zope3-Users] Run starup code with zope 3.
On Thu, Feb 12, 2009 at 07:28:23PM +0100, Sebastian Bartos wrote: Was playing with the event system a bit, and ended up with the following, which works fine: import zope.event class MyEvent: pass event = MyEvent() def f(event): if isinstance(event, zope.app.appsetup.interfaces.ProcessStarting): Put stuff you want to execute after server startup here. principalPermissionManager.grantAllPermissionsToPrincipal(use) zope.event.subscribers.append(f) ... Is this a good zopey way? An emphatic No. This slows down the processing of every event by performing an extra function call and an if statement, instead of using a hash-driven dispatch that zope.component provides for subscribers. The subscriber / ZCML directive is a good Zopey way. ZCML: subscriber handler=.module.grantStuffOnStartup / Code: @zope.component.adapts(zope.app.appsetup.interfaces.ProcessStarting) def grantStuffOnStartup(event): principalPermissionManager.grantAllPermissionsToPrincipal(use) Also, if you're hardcoding the principal ID here, you might as well just do it in ZCML: grantAll principal=use / and if you're not hardcoding/want to be able to adjust the grant later through the web, you should really use the IPrincipalRoleMap adapter on the root folder that will store the grant persistently in the DB rather than in memory. Marius Gedminas -- There is an almost obvious extension of interfaces that would allow formal specification of arguments and return values. We suspect it leads to the dark side. -- Jim Fulton signature.asc Description: Digital signature ___ Zope3-users mailing list Zope3-users@zope.org http://mail.zope.org/mailman/listinfo/zope3-users