Exemplo n.º 1
0
    def get_groups(self):
        """Return all LDAP groups below the adapted LDAPUserFolder's
        groups_base.

        If defined, the `group_filter` property on the adapted LDAPUserFolder
        is used to further filter the results.
        """
        # Build a filter expression that matches objectClasses for all
        # possible group objectClasseses encountered in the wild

        possible_classes = ''
        for oc in GROUP_MEMBER_MAP.keys():
            # concatenate (objectClass=foo) pairs
            possible_classes += filter_format('(%s=%s)', ('objectClass', oc))

        # Build the final OR expression:
        # (|(objectClass=aaa)(objectClass=bbb)(objectClass=ccc))
        search_filter = '(|%s)' % possible_classes

        custom_filter = self.get_group_filter()
        if custom_filter not in [None, '']:
            search_filter = self._combine_filters(custom_filter, search_filter)

        results = self.search(base_dn=self.context.groups_base,
                              filter=search_filter)
        mapped_results = []
        for result in results:
            mapped_results.append(self.apply_schema_map(result))

        return mapped_results
Exemplo n.º 2
0
    def get_groups(self, use_lookup_base=False):
        """Return all LDAP groups below the adapted LDAPUserFolder's
        `groups_base` (or the `lookup_groups_base` if `use_lookup_base` is True).

        If defined, the `group_filter` property on the adapted LDAPUserFolder
        is used to further filter the results.
        """
        # Build a filter expression that matches objectClasses for all
        # possible group objectClasseses encountered in the wild

        possible_classes = ''
        for oc in GROUP_MEMBER_MAP.keys():
            # concatenate (objectClass=foo) pairs
            possible_classes += filter_format('(%s=%s)', ('objectClass', oc))

        # Build the final OR expression:
        # (|(objectClass=aaa)(objectClass=bbb)(objectClass=ccc))
        search_filter = '(|%s)' % possible_classes

        custom_filter = self.get_group_filter()
        search_filter = self._combine_filters(custom_filter, search_filter)

        if use_lookup_base:
            base_dn = getattr(
                self.context, 'lookup_groups_base', self.context.groups_base)
        else:
            base_dn = self.context.groups_base

        results = self.search(base_dn=base_dn, search_filter=search_filter)

        mapped_results = []
        for result in results:
            mapped_results.append(self.apply_schema_map(result))

        return mapped_results
Exemplo n.º 3
0
    def getGroups(self, dn='*', attr=None):
        """ return group records i know about """
        group_list = []

        if self.groups_base:
            no_show = ('Anonymous', 'Authenticated', 'Shared')

            if dn == '*':
                group_classes = GROUP_MEMBER_MAP.keys()
                filt_list = [
                    filter_format('(%s=%s)', ('objectClass', g))
                    for g in group_classes
                ]
                group_filter = '(|%s)' % ''.join(filt_list)
            else:
                member_attrs = list(Set(GROUP_MEMBER_MAP.values()))
                filt_list = [
                    filter_format('(%s=%s)', (m_attr, dn))
                    for m_attr in member_attrs
                ]
                group_filter = '(|%s)' % ''.join(filt_list)
            luf = self.getLUF()

            res = luf._delegate.search(self.groups_base,
                                       self.groups_scope,
                                       group_filter,
                                       attrs=['dn', 'cn'])

            if res['size'] > 0:
                resultset = res['results']
                for i in range(res['size']):
                    dn = resultset[i].get('dn')
                    try:
                        cn = resultset[i].get('cn')[0]
                    except KeyError:  # NDS oddity
                        cn = luf._delegate.explode_dn(dn, 1)[0]

                    if attr is None:
                        group_list.append((cn, dn))
                    elif attr == 'cn':
                        group_list.append(cn)
                    elif attr == 'dn':
                        group_list.append(dn)

        return group_list
Exemplo n.º 4
0
    def getGroups(self, dn='*', attr=None):
        """ return group records i know about """
        group_list = []

        if self.groups_base:
            no_show = ('Anonymous', 'Authenticated', 'Shared')

            if dn == '*':
                group_classes = GROUP_MEMBER_MAP.keys()
                filt_list = [ filter_format('(%s=%s)', ('objectClass', g))
                                        for g in group_classes ]
                group_filter = '(|%s)' % ''.join(filt_list)
            else:
                member_attrs = list(Set(GROUP_MEMBER_MAP.values()))
                filt_list = [ filter_format('(%s=%s)', (m_attr, dn))
                                            for m_attr in member_attrs ]
                group_filter = '(|%s)' % ''.join(filt_list)
            luf = self.getLUF()

            res = luf._delegate.search( self.groups_base
                                      , self.groups_scope
                                      , group_filter
                                      , attrs=['dn', 'cn']
                                      )

            if res['size'] > 0:
                resultset = res['results']
                for i in range(res['size']):
                    dn = resultset[i].get('dn')
                    try:
                        cn = resultset[i].get('cn')[0]
                    except KeyError:    # NDS oddity
                        cn = luf._delegate.explode_dn(dn, 1)[0]

                    if attr is None:
                        group_list.append((cn, dn))
                    elif attr == 'cn':
                        group_list.append(cn)
                    elif attr == 'dn':
                        group_list.append(dn)

        return group_list
Exemplo n.º 5
0
    def get_groups(self, use_lookup_base=False):
        """Return all LDAP groups below the adapted LDAPUserFolder's
        `groups_base` (or the `lookup_groups_base` if `use_lookup_base` is True).

        If defined, the `group_filter` property on the adapted LDAPUserFolder
        is used to further filter the results.
        """
        # Build a filter expression that matches objectClasses for all
        # possible group objectClasseses encountered in the wild

        possible_classes = ''
        for oc in GROUP_MEMBER_MAP.keys():
            # concatenate (objectClass=foo) pairs
            possible_classes += filter_format('(%s=%s)', ('objectClass', oc))

        # Build the final OR expression:
        # (|(objectClass=aaa)(objectClass=bbb)(objectClass=ccc))
        search_filter = '(|%s)' % possible_classes

        custom_filter = self.get_group_filter()
        search_filter = self._combine_filters(custom_filter, search_filter)

        if use_lookup_base:
            base_dn = getattr(
                self.context, 'lookup_groups_base', self.context.groups_base)
        else:
            base_dn = self.context.groups_base

        results = self.search(base_dn=base_dn, filter=search_filter)

        mapped_results = []
        for result in results:
            dn, entry = result
            if dn is None:
                # This is likely a referral to be hunted down by
                # client-chasing. We don't support those.
                logger.info('Skipping referral: %r' % (result, ))
                continue
            mapped_results.append(self.apply_schema_map(result))

        return mapped_results