Пример #1
0
  def _transform_find_group_results(self, result_data, group_name_attr):
    group_info = []
    if result_data:
      for dn, data in result_data:
        # Case insensitivity
        data = CaseInsensitiveDict.from_dict(data)

        # Skip Active Directory # refldap entries.
        if dn is not None:

          # Skip unnamed entries.
          if group_name_attr not in data:
            LOG.warn('Could not find %s in ldap attributes' % group_name_attr)
            continue

          ldap_info = {
            'dn': dn,
            'name': data[group_name_attr][0]
          }

          member_attr = desktop.conf.LDAP.GROUPS.GROUP_MEMBER_ATTR.get()
          if member_attr in data:
            ldap_info['members'] = data[member_attr]
          else:
            ldap_info['members'] = []

          if 'posixGroup' in data['objectClass'] and 'memberUid' in data:
            ldap_info['posix_members'] = data['memberUid']
          else:
            ldap_info['posix_members'] = []

          group_info.append(ldap_info)

    return group_info
Пример #2
0
    def _transform_find_group_results(self, result_data, group_name_attr, group_member_attr):
        group_info = []
        if result_data:
            for dn, data in result_data:
                # Skip Active Directory # refldap entries.
                if dn is not None:
                    # Case insensitivity
                    data = CaseInsensitiveDict.from_dict(data)

                    # Skip unnamed entries.
                    if group_name_attr not in data:
                        LOG.warn("Could not find %s in ldap attributes" % group_name_attr)
                        continue

                    group_name = data[group_name_attr][0]
                    if desktop.conf.LDAP.FORCE_USERNAME_LOWERCASE.get():
                        group_name = group_name.lower()
                    elif desktop.conf.LDAP.FORCE_USERNAME_UPPERCASE.get():
                        group_name = group_name.upper()

                    ldap_info = {"dn": dn, "name": group_name}

                    if group_member_attr in data and "posixGroup" not in data["objectClass"]:
                        ldap_info["members"] = data[group_member_attr]
                    else:
                        ldap_info["members"] = []

                    if "posixGroup" in data["objectClass"] and "memberUid" in data:
                        ldap_info["posix_members"] = data["memberUid"]
                    else:
                        ldap_info["posix_members"] = []

                    group_info.append(ldap_info)

        return group_info
Пример #3
0
    def _transform_find_group_results(self, result_data, group_name_attr):
        group_info = []
        if result_data:
            for dn, data in result_data:
                # Skip Active Directory # refldap entries.
                if dn is not None:
                    # Case insensitivity
                    data = CaseInsensitiveDict.from_dict(data)

                    # Skip unnamed entries.
                    if group_name_attr not in data:
                        LOG.warn('Could not find %s in ldap attributes' %
                                 group_name_attr)
                        continue

                    ldap_info = {'dn': dn, 'name': data[group_name_attr][0]}

                    member_attr = desktop.conf.LDAP.GROUPS.GROUP_MEMBER_ATTR.get(
                    )
                    if member_attr in data and 'posixGroup' not in data[
                            'objectClass']:
                        ldap_info['members'] = data[member_attr]
                    else:
                        ldap_info['members'] = []

                    if 'posixGroup' in data[
                            'objectClass'] and 'memberUid' in data:
                        ldap_info['posix_members'] = data['memberUid']
                    else:
                        ldap_info['posix_members'] = []

                    group_info.append(ldap_info)

        return group_info
Пример #4
0
 def test_case_insensitive_dictionary(self):
   d = CaseInsensitiveDict()
   d["Test"] = "Test"
   assert_true("Test" in d)
   assert_true("test" in d)
   assert_equal("Test", d['Test'])
   assert_equal("Test", d['test'])
   assert_not_equal("test", d['Test'])
   assert_not_equal("test", d['test'])
Пример #5
0
    def _transform_find_user_results(cls, result_data, user_name_attr):
        """
    :param result_data: List of dictionaries that have ldap attributes and their associated values. Generally the result list from an ldapsearch request.
    :param user_name_attr: The ldap attribute that is returned by the server to map to ``username`` in the return dictionary.

    :returns list of dictionaries that take on the following form: {
      'dn': <distinguished name of entry>,
      'username': <ldap attribute associated with user_name_attr>
      'first': <first name>
      'last': <last name>
      'email': <email>
      'groups': <list of DNs of groups that user is a member of>
    }
    """
        user_info = []
        if result_data:
            for dn, data in result_data:
                # Skip Active Directory # refldap entries.
                if dn is not None:
                    # Case insensitivity
                    data = CaseInsensitiveDict.from_dict(data)

                    # Skip unnamed entries.
                    if user_name_attr not in data:
                        LOG.warn('Could not find %s in ldap attributes' %
                                 user_name_attr)
                        continue

                    ldap_info = {'dn': dn, 'username': data[user_name_attr][0]}

                    if 'givenName' in data:
                        first_name = smart_text(data['givenName'][0])
                        if len(first_name) > 30:
                            LOG.warn(
                                'First name is truncated to 30 characters for [<User: %s>].'
                                % ldap_info['username'])
                        ldap_info['first'] = first_name[:30]
                    if 'sn' in data:
                        last_name = smart_text(data['sn'][0])
                        if len(last_name) > 30:
                            LOG.warn(
                                'Last name is truncated to 30 characters for [<User: %s>].'
                                % ldap_info['username'])
                        ldap_info['last'] = last_name[:30]
                    if 'mail' in data:
                        ldap_info['email'] = data['mail'][0]
                    # memberOf and isMemberOf should be the same if they both exist
                    if 'memberOf' in data:
                        ldap_info['groups'] = data['memberOf']
                    if 'isMemberOf' in data:
                        ldap_info['groups'] = data['isMemberOf']

                    user_info.append(ldap_info)
        return user_info
Пример #6
0
  def _transform_find_user_results(cls, result_data, user_name_attr):
    """
    :param result_data: List of dictionaries that have ldap attributes and their associated values. Generally the result list from an ldapsearch request.
    :param user_name_attr: The ldap attribute that is returned by the server to map to ``username`` in the return dictionary.
    
    :returns list of dictionaries that take on the following form: {
      'dn': <distinguished name of entry>,
      'username': <ldap attribute associated with user_name_attr>
      'first': <first name>
      'last': <last name>
      'email': <email>
      'groups': <list of DNs of groups that user is a member of>
    }
    """
    user_info = []
    if result_data:
      for dn, data in result_data:
        # Skip Active Directory # refldap entries.
        if dn is not None:
          # Case insensitivity
          data = CaseInsensitiveDict.from_dict(data)

          # Skip unnamed entries.
          if user_name_attr not in data:
            LOG.warn('Could not find %s in ldap attributes' % user_name_attr)
            continue

          ldap_info = {
            'dn': dn,
            'username': data[user_name_attr][0]
          }

          if 'givenName' in data:
            if len(data['givenName'][0]) > 30:
              LOG.warn('First name is truncated to 30 characters for [<User: %s>].' % ldap_info['username'])
            ldap_info['first'] = data['givenName'][0][:30]
          if 'sn' in data:
            if len(data['sn'][0]) > 30:
              LOG.warn('Last name is truncated to 30 characters for [<User: %s>].' % ldap_info['username'])
            ldap_info['last'] = data['sn'][0][:30]
          if 'mail' in data:
            ldap_info['email'] = data['mail'][0]
          # memberOf and isMemberOf should be the same if they both exist
          if 'memberOf' in data:
            ldap_info['groups'] = data['memberOf']
          if 'isMemberOf' in data:
            ldap_info['groups'] = data['isMemberOf']

          user_info.append(ldap_info)
    return user_info
Пример #7
0
    def _transform_find_group_results(self, result_data, group_name_attr,
                                      group_member_attr):
        group_info = []
        if result_data:
            for dn, data in result_data:
                # Skip Active Directory # refldap entries.
                if dn is not None:
                    # Case insensitivity
                    data = CaseInsensitiveDict.from_dict(data)

                    # Skip unnamed entries.
                    if group_name_attr not in data:
                        LOG.warn('Could not find %s in ldap attributes' %
                                 group_name_attr)
                        continue

                    group_name = data[group_name_attr][0]
                    if desktop.conf.LDAP.FORCE_USERNAME_LOWERCASE.get():
                        group_name = group_name.lower()
                    elif desktop.conf.LDAP.FORCE_USERNAME_UPPERCASE.get():
                        group_name = group_name.upper()

                    ldap_info = {'dn': dn, 'name': group_name}

                    if group_member_attr in data and group_member_attr.lower(
                    ) != 'memberuid':
                        ldap_info['members'] = data[group_member_attr]
                    else:
                        LOG.warn(
                            'Skipping import of non-posix users from group %s since group_member_attr '
                            'is memberUid or group did not contain any members'
                            % group_name)
                        ldap_info['members'] = []

                    if 'posixgroup' in (item.lower()
                                        for item in data['objectClass']
                                        ) and 'memberUid' in data:
                        ldap_info['posix_members'] = data['memberUid']
                    else:
                        LOG.warn(
                            'Skipping import of posix users from group %s since posixGroup '
                            'not an objectClass or no memberUids found' %
                            group_name)
                        ldap_info['posix_members'] = []

                    group_info.append(ldap_info)

        return group_info
Пример #8
0
    def _transform_find_user_results(self, result_data, user_name_attr):
        """
    :param result_data: List of dictionaries that have ldap attributes and their associated values. Generally the result list from an ldapsearch request.
    :param user_name_attr: The ldap attribute that is returned by the server to map to ``username`` in the return dictionary.
    
    :returns list of dictionaries that take on the following form: {
      'dn': <distinguished name of entry>,
      'username': <ldap attribute associated with user_name_attr>
      'first': <first name>
      'last': <last name>
      'email': <email>
      'groups': <list of DNs of groups that user is a member of>
    }
    """
        user_info = []
        if result_data:
            for dn, data in result_data:
                # Skip Active Directory # refldap entries.
                if dn is not None:
                    # Case insensitivity
                    data = CaseInsensitiveDict.from_dict(data)

                    # Skip unnamed entries.
                    if user_name_attr not in data:
                        LOG.warn("Could not find %s in ldap attributes" % user_name_attr)
                        continue

                    ldap_info = {"dn": dn, "username": data[user_name_attr][0]}

                    if "givenName" in data:
                        ldap_info["first"] = data["givenName"][0]
                    if "sn" in data:
                        ldap_info["last"] = data["sn"][0]
                    if "mail" in data:
                        ldap_info["email"] = data["mail"][0]
                    # memberOf and isMemberOf should be the same if they both exist
                    if "memberOf" in data:
                        ldap_info["groups"] = data["memberOf"]
                    if "isMemberOf" in data:
                        ldap_info["groups"] = data["isMemberOf"]

                    user_info.append(ldap_info)
        return user_info
Пример #9
0
  def _transform_find_group_results(self, result_data, group_name_attr, group_member_attr):
    group_info = []
    if result_data:
      for dn, data in result_data:
        # Skip Active Directory # refldap entries.
        if dn is not None:
          # Case insensitivity
          data = CaseInsensitiveDict.from_dict(data)

          # Skip unnamed entries.
          if group_name_attr not in data:
            LOG.warn('Could not find %s in ldap attributes' % group_name_attr)
            continue

          group_name = data[group_name_attr][0]
          if desktop.conf.LDAP.FORCE_USERNAME_LOWERCASE.get():
            group_name = group_name.lower()
          elif desktop.conf.LDAP.FORCE_USERNAME_UPPERCASE.get():
            group_name = group_name.upper()

          ldap_info = {
            'dn': dn,
            'name': group_name
          }

          if group_member_attr in data and group_member_attr.lower() != 'memberuid':
            ldap_info['members'] = data[group_member_attr]
          else:
            LOG.warn('Skipping import of non-posix users from group %s since group_member_attr is memberUid or group did not contain any members' % group_name)
            ldap_info['members'] = []

          if 'posixgroup' in (item.lower() for item in data['objectClass']) and 'memberUid' in data:
            ldap_info['posix_members'] = data['memberUid']
          else:
            LOG.warn('Skipping import of posix users from group %s since posixGroup not an objectClass or no memberUids found' % group_name)
            ldap_info['posix_members'] = []

          group_info.append(ldap_info)

    return group_info
Пример #10
0
    def _transform_find_group_results(self, result_data, group_name_attr,
                                      group_member_attr):
        group_info = []
        if result_data:
            for dn, data in result_data:
                # Skip Active Directory # refldap entries.
                if dn is not None:
                    # Case insensitivity
                    data = CaseInsensitiveDict.from_dict(data)

                    # Skip unnamed entries.
                    if group_name_attr not in data:
                        LOG.warn('Could not find %s in ldap attributes' %
                                 group_name_attr)
                        continue

                    group_name = data[group_name_attr][0]
                    if desktop.conf.LDAP.FORCE_USERNAME_LOWERCASE.get():
                        group_name = group_name.lower()
                    elif desktop.conf.LDAP.FORCE_USERNAME_UPPERCASE.get():
                        group_name = group_name.upper()

                    ldap_info = {'dn': dn, 'name': group_name}

                    if group_member_attr in data and 'posixGroup' not in data[
                            'objectClass']:
                        ldap_info['members'] = data[group_member_attr]
                    else:
                        ldap_info['members'] = []

                    if 'posixGroup' in data[
                            'objectClass'] and 'memberUid' in data:
                        ldap_info['posix_members'] = data['memberUid']
                    else:
                        ldap_info['posix_members'] = []

                    group_info.append(ldap_info)

        return group_info
Пример #11
0
  def _transform_find_group_results(self, result_data, group_name_attr, group_member_attr):
    group_info = []
    if result_data:
      for dn, data in result_data:
        # Skip Active Directory # refldap entries.
        if dn is not None:
          # Case insensitivity
          data = CaseInsensitiveDict.from_dict(data)

          # Skip unnamed entries.
          if group_name_attr not in data:
            LOG.warn('Could not find %s in ldap attributes' % group_name_attr)
            continue

          group_name = data[group_name_attr][0]
          if desktop.conf.LDAP.FORCE_USERNAME_LOWERCASE.get():
            group_name = group_name.lower()

          ldap_info = {
            'dn': dn,
            'name': group_name
          }

          if group_member_attr in data and 'posixGroup' not in data['objectClass']:
            ldap_info['members'] = data[group_member_attr]
          else:
            ldap_info['members'] = []

          if 'posixGroup' in data['objectClass'] and 'memberUid' in data:
            ldap_info['posix_members'] = data['memberUid']
          else:
            ldap_info['posix_members'] = []

          group_info.append(ldap_info)

    return group_info