Back to index

plone3  3.1.7
ldapmp.py
Go to the documentation of this file.
00001 ##############################################################################
00002 #
00003 # PlonePAS - Adapt PluggableAuthService for use in Plone
00004 # Copyright (C) 2005 Enfold Systems, Kapil Thangavelu, et al
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 """
00016 """
00017 
00018 from Products.PlonePAS.patch import call, wrap_method
00019 from Products.PlonePAS.plugins.group import PloneGroup
00020 from Products.LDAPMultiPlugins.LDAPPluginBase import LDAPPluginBase
00021 from Products.LDAPMultiPlugins.LDAPMultiPlugin import LDAPMultiPlugin
00022 
00023 from sets import Set
00024 
00025 GROUP_PROPERTY_MAP = {
00026     # target property: (possible key, ...)
00027     'title': ('name',
00028               'displayName',
00029               'cn',),
00030     'description': ('description', ),
00031     'email': ('mail', ),
00032     }
00033 
00034 KNOWN_ATTRS = []
00035 for attrs in GROUP_PROPERTY_MAP.values():
00036     for attr in attrs:
00037         KNOWN_ATTRS.append(attr)
00038 KNOWN_ATTRS = Set(KNOWN_ATTRS)
00039 
00040 def getPropertiesForUser(self, user, request=None):
00041     """Fullfill PropertiesPlugin requirements
00042     """
00043 
00044     if not isinstance(user, PloneGroup):
00045         # It's not a PloneGroup, continue as usual
00046         return call(self, 'getPropertiesForUser', user=user, request=request)
00047 
00048     # We've got a PloneGroup.
00049     # Search for groups instead of users
00050     groups = self.enumerateGroups(id=user.getId(), exact_match=True)
00051     # XXX Should we assert there's only one group?
00052     properties = {}
00053     for group in groups:
00054         for pname, attrs in GROUP_PROPERTY_MAP.items():
00055             for attr in attrs:
00056                 value = group.get(attr)
00057                 if value:
00058                     # Break on first found
00059                     properties[pname] = value
00060                     break
00061 
00062     return properties
00063 
00064 wrap_method(LDAPPluginBase, 'getPropertiesForUser', getPropertiesForUser)
00065 
00066 def getGroupsForPrincipal(self, user, request=None, attr=None):
00067     """ Fulfill GroupsPlugin requirements, but don't return any groups for groups """
00068 
00069     if not isinstance(user, PloneGroup):
00070         # It's not a PloneGroup, continue as usual
00071         return call(self, 'getGroupsForPrincipal', user, request=request, attr=attr)
00072 
00073     return ()
00074 
00075 wrap_method(LDAPMultiPlugin, 'getGroupsForPrincipal', getGroupsForPrincipal)