Ejemplo n.º 1
0
    def map_search_criteria(self, criteria):
        """Maps the search criteria from application keys to provider keys

        :param criteria: A dict containing search criteria
        :return: A dict containing search criteria with mapped keys
        """
        mapping = self.settings["mapping"]
        return convert_app_data(criteria, mapping)
Ejemplo n.º 2
0
    def map_search_criteria(self, criteria):
        """Maps the search criteria from application keys to provider keys

        :param criteria: A dict containing search criteria
        :return: A dict containing search criteria with mapped keys
        """
        mapping = self.settings['mapping']
        return convert_app_data(criteria, mapping)
Ejemplo n.º 3
0
 def __init__(self, *args, **kwargs):
     super(LDAPIdentityProvider, self).__init__(*args, **kwargs)
     self.set_defaults()
     self.ldap_settings.setdefault('gid', 'cn')
     self.ldap_settings.setdefault('group_filter', '(objectClass=groupOfNames)')
     self.ldap_settings.setdefault('member_of_attr', 'memberOf')
     self.ldap_settings.setdefault('ad_group_style', False)
     self._attributes = convert_app_data(self.settings['mapping'], {}, self.settings['identity_info_keys']).values()
     self._attributes.append(self.ldap_settings['uid'])
Ejemplo n.º 4
0
 def __init__(self, *args, **kwargs):
     super(LDAPIdentityProvider, self).__init__(*args, **kwargs)
     self.set_defaults()
     self.ldap_settings.setdefault('gid', 'cn')
     self.ldap_settings.setdefault('group_filter',
                                   '(objectClass=groupOfNames)')
     self.ldap_settings.setdefault('member_of_attr', 'memberOf')
     self.ldap_settings.setdefault('ad_group_style', False)
     self._attributes = convert_app_data(
         self.settings['mapping'], {},
         self.settings['identity_info_keys']).values()
     self._attributes.append(self.ldap_settings['uid'])
Ejemplo n.º 5
0
def build_search_filter(criteria, type_filter, mapping=None, exact=False):
    """Builds a valid LDAP search filter for retrieving entries.

    :param criteria: dict -- Criteria to be ANDed together to build the
                     filter, if a criterion has many values they will
                     be ORed together.
    :param mapping: dict -- Mapping from criteria to LDAP attributes
    :param exact: bool -- Match attributes values exactly if ``True``,
                  othewise perform substring matching.
    :return: str -- Valid LDAP search filter.
    """

    assertions = convert_app_data(criteria, mapping or {})
    assert_templates = [_build_assert_template(value, exact) for _, value in iteritems(assertions)]
    assertions = [(k, v) for k, values in iteritems(assertions) if k and values for v in values]
    if not assertions:
        return None
    filter_template = '(&{}{})'.format("".join(assert_templates), type_filter)
    return filter_format(filter_template, (item for assertion in assertions for item in assertion))
Ejemplo n.º 6
0
def build_search_filter(criteria, type_filter, mapping=None, exact=False):
    """Builds a valid LDAP search filter for retrieving entries.

    :param criteria: dict -- Criteria to be ANDed together to build the
                     filter, if a criterion has many values they will
                     be ORed together.
    :param mapping: dict -- Mapping from criteria to LDAP attributes
    :param exact: bool -- Match attributes values exactly if ``True``,
                  othewise perform substring matching.
    :return: str -- Valid LDAP search filter.
    """

    assertions = convert_app_data(criteria, mapping or {})
    assert_templates = [
        _build_assert_template(value, exact)
        for _, value in iteritems(assertions)
    ]
    assertions = [(k, v) for k, values in iteritems(assertions) if k and values
                  for v in values]
    if not assertions:
        return None
    filter_template = '(&{}{})'.format("".join(assert_templates), type_filter)
    return filter_format(filter_template, (item for assertion in assertions
                                           for item in assertion))
Ejemplo n.º 7
0
 def _convert_app_data(*args, **kwargs):
     return OrderedDict(sorted(convert_app_data(*args, **kwargs).items()))
Ejemplo n.º 8
0
def test_convert_app_data(app_data, mapping, key_filter, result):
    assert convert_app_data(app_data, mapping, key_filter) == result
Ejemplo n.º 9
0
def test_convert_app_data(app_data, mapping, key_filter, result):
    assert convert_app_data(app_data, mapping, key_filter) == result
Ejemplo n.º 10
0
 def _convert_app_data(*args, **kwargs):
     return OrderedDict(sorted(convert_app_data(*args, **kwargs).items()))