Logo Search packages:      
Sourcecode: zope-ldapmultiplugins version File versions  Download package

def LDAPMultiPlugins::ActiveDirectoryMultiPlugin::ActiveDirectoryMultiPlugin::enumerateGroups (   self,
  id = None,
  exact_match = 0,
  sort_by = None,
  max_results = None,
  kw 
)

Fulfill the RoleEnumerationPlugin requirements 

Definition at line 381 of file ActiveDirectoryMultiPlugin.py.

                        :
        """ Fulfill the RoleEnumerationPlugin requirements """
        view_name = self.getId() + '_enumerateGroups'
        criteria = {'id':id, 'exact_match':exact_match,
                    'sort_by':sort_by, 'max_results':max_results}
        criteria.update(kw)

        cached_info = self.ZCacheable_get(view_name = view_name,
                                          keywords = criteria,
                                          default = None)

        if cached_info is not None:
            logger.debug('returning cached results from enumerateGroups')
            return cached_info

        acl = self._getLDAPUserFolder()

        if acl is None:
            return ()

        if id is None and exact_match != 0:
            raise ValueError, 'Exact Match requested but no id provided'
        elif id is None:
            id = ''
            
        plugin_id = self.getId()

        filt = ['(objectClass=%s)' % self.group_class]
        if not id:
            filt.append('(%s=*)' % self.groupid_attr)
        elif exact_match:
            filt.append(filter_format('(%s=%s)',(self.groupid_attr, id)))
        elif id:
            filt.append(filter_format('(%s=*%s*)',(self.groupid_attr, id)))
        filt = '(&%s)' % ''.join(filt)

        if self.groupid_attr.lower() in BINARY_ATTRIBUTES:
            convert_filter = False
        else:
            convert_filter = True

        delegate = acl._delegate
        R = delegate.search( acl.groups_base
                           , acl.groups_scope
                           , filter=filt
                           , convert_filter=convert_filter
                           )

        if R['exception']:
            logger.error("Failed to enumerate groups in %s "
                         "(scope=%s, filter=%s): %s",
                         acl.groups_base, acl.groups_scope, filt,
                         R['exception'])
            return ()

        groups = R['results']

        results = []
        for group in groups:
            tmp = {}
            tmp['title'] = '(Group) ' + group[self.grouptitle_attr][0]
            id = tmp['id'] = group[self.groupid_attr][0]
            tmp['pluginid'] = plugin_id
            results.append(tmp)

        if sort_by is not None:
            results.sort(lambda a, b: cmp( a.get(sort_by, '').lower()
                                          , b.get(sort_by, '').lower()
                                            ) )
        if isinstance(max_results, int) and len(results) > max_results:
            results = results[:max_results+1]

        results =  tuple(results)

        self.ZCacheable_set(results, view_name=view_name, keywords=criteria)

        return results

    security.declarePrivate('enumerateRoles')
    def enumerateRoles( self


Generated by  Doxygen 1.6.0   Back to index