ploneplone-4.x

Plone: list all ldap users


I'm trying to get the list of all users - local accounts and ldap ones.

If I know an userid (ldap or local account) this is simple, I can get it and check it's properties:

site = self.context.portal_url.getPortalObject() from 
Products.CMFCore.utils import getToolByName
membership_tool = getToolByName(site, 'portal_membership') 
membership_tool.getMemberById('some_user_id')

^ This is working for both: ldap and local.

membership_tool.listMemberIds()  # local accounts ids are listed

The same with:

users_tool = getToolByName(self, 'acl_users')
users_tool.getUserIds()  # local accounts ids are listed

Any idea how to get the list of users that are using ldap account?


Solution

  • Solved by iterating the keys of _members in portal_memberdata tool. We have some fields for each user.

    md = getToolByName(self, 'portal_memberdata')
    all_members = [x for x in md._members.keys()]  # ids of ldap and local accounts are listed