Back to index

plone3  3.1.7
LocalRolePlugin.py
Go to the documentation of this file.
00001 ##############################################################################
00002 #
00003 # Copyright (c) 2001 Zope Corporation and Contributors. All Rights
00004 # Reserved.
00005 #
00006 # This software is subject to the provisions of the Zope Public License,
00007 # Version 2.1 (ZPL).  A copy of the ZPL should accompany this
00008 # distribution.
00009 # THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
00010 # WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
00011 # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
00012 # FOR A PARTICULAR PURPOSE.
00013 #
00014 ##############################################################################
00015 """ Classes: LocalRolePlugin
00016 
00017 $Id: LocalRolePlugin.py 70851 2006-10-20 19:25:56Z jens $
00018 """
00019 from AccessControl import ClassSecurityInfo
00020 from Globals import InitializeClass
00021 
00022 from zope.interface import Interface
00023 
00024 from Products.PageTemplates.PageTemplateFile import PageTemplateFile
00025 
00026 from Products.PluggableAuthService.interfaces.plugins import IRolesPlugin
00027 from Products.PluggableAuthService.plugins.BasePlugin import BasePlugin
00028 from Products.PluggableAuthService.utils import classImplements
00029 
00030 class ILocalRolePlugin(Interface):
00031     """ Marker interface.
00032     """
00033 
00034 manage_addLocalRolePluginForm = PageTemplateFile(
00035     'www/lrpAdd', globals(), __name__='manage_addLocalRolePluginForm' )
00036 
00037 def addLocalRolePlugin( dispatcher, id, title='', RESPONSE=None ):
00038     """ Add a Local Role Plugin to 'dispatcher'.
00039     """
00040 
00041     lrp = LocalRolePlugin( id, title )
00042     dispatcher._setObject( id, lrp )
00043 
00044     if RESPONSE is not None:
00045         RESPONSE.redirect( '%s/manage_main?manage_tabs_message=%s' %
00046                            ( dispatcher.absolute_url()
00047                            , 'LocalRolePlugin+added.' ) )
00048 
00049 class LocalRolePlugin( BasePlugin ):
00050     """ Provide roles during Authentication from local roles
00051         assignments made on the root object.
00052     """
00053 
00054     meta_type = 'Local Role Plugin'
00055     security = ClassSecurityInfo()
00056 
00057     def __init__( self, id, title=None ):
00058         self._setId( id )
00059         self.title = title
00060 
00061     #
00062     #    IRolesPlugin implementation
00063     #
00064     security.declarePrivate( 'getRolesForPrincipal' )
00065     def getRolesForPrincipal( self, principal, request=None ):
00066 
00067         """ See IRolesPlugin.
00068         """
00069         local_roles = getattr( self.getPhysicalRoot()
00070                              , '__ac_local_roles__'
00071                              , None )
00072         if local_roles is None:
00073             return None
00074         return local_roles.get( principal.getId() )
00075 
00076 classImplements( LocalRolePlugin
00077                , ILocalRolePlugin
00078                , IRolesPlugin
00079                )
00080 
00081 InitializeClass( LocalRolePlugin )