當前位置: 首頁>>代碼示例>>Python>>正文


Python ldap.SCOPE_ONELEVEL屬性代碼示例

本文整理匯總了Python中ldap.SCOPE_ONELEVEL屬性的典型用法代碼示例。如果您正苦於以下問題:Python ldap.SCOPE_ONELEVEL屬性的具體用法?Python ldap.SCOPE_ONELEVEL怎麽用?Python ldap.SCOPE_ONELEVEL使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在ldap的用法示例。


在下文中一共展示了ldap.SCOPE_ONELEVEL屬性的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_search_valid_username

# 需要導入模塊: import ldap [as 別名]
# 或者: from ldap import SCOPE_ONELEVEL [as 別名]
def test_search_valid_username(self):
        username = 'sarah_connor'
        password = 'Reece4ever'
        user_dn = 'uid={},ou=users,dc=example,dc=com'.format(username)

        mock_res = (user_dn, LDAPAuthenticationBackendTestCase.directory[user_dn])

        user = {"base_dn": "ou=users,dc=example,dc=com", "search_filter": "(uid={username})", "scope": "onelevel"}

        self.ldapobj.search_s.seed(user["base_dn"], ldap.SCOPE_ONELEVEL, user["search_filter"].format(username=username))([mock_res])

        result = _do_simple_bind('cn=manager,dc=example,dc=com', 'ldaptest', user_search=user, group_search=None, username=username, password=password)

        expected_methods_called = (
            self.connect_methods +
            ['simple_bind_s', 'whoami_s', 'search', 'result', 'result'] +
            self.connect_methods +
            ['simple_bind_s', 'whoami_s', 'unbind', 'unbind']
        )

        self.assertEquals(self.ldapobj.methods_called(), expected_methods_called)
        self.assertTrue(result) 
開發者ID:StackStorm,項目名稱:st2-auth-backend-ldap,代碼行數:24,代碼來源:test_ldap_backend.py

示例2: test_search_invalid_username

# 需要導入模塊: import ldap [as 別名]
# 或者: from ldap import SCOPE_ONELEVEL [as 別名]
def test_search_invalid_username(self):
        username = 'invalid_username'
        password = 'Reece4ever'
        user = {"base_dn": "ou=users,dc=example,dc=com", "search_filter": "(uid={username})", "scope": "onelevel"}

        mock_res = []

        self.ldapobj.search_s.seed(user["base_dn"], ldap.SCOPE_ONELEVEL, user["search_filter"].format(username=username))(mock_res)
        result = _do_simple_bind('cn=manager,dc=example,dc=com', 'ldaptest', user_search=user, group_search=None, username=username, password=password)

        expected_methods_called = (
            self.connect_methods +
            ['simple_bind_s', 'whoami_s', 'search', 'result', 'unbind']
        )

        self.assertEquals(self.ldapobj.methods_called(), expected_methods_called)
        self.assertFalse(result) 
開發者ID:StackStorm,項目名稱:st2-auth-backend-ldap,代碼行數:19,代碼來源:test_ldap_backend.py

示例3: test_search_invalid_password

# 需要導入模塊: import ldap [as 別名]
# 或者: from ldap import SCOPE_ONELEVEL [as 別名]
def test_search_invalid_password(self):
        username = 'sarah_connor'
        password = 'bad_password'
        user = {"base_dn": "ou=users,dc=example,dc=com", "search_filter": "(uid={username})", "scope": "onelevel"}

        mock_res_id = 1234
        mock_res = (ldap.RES_SEARCH_RESULT, None)

        self.ldapobj._search.seed(user["base_dn"], ldap.SCOPE_ONELEVEL, user["search_filter"].format(username=username))(mock_res_id)
        self.ldapobj._result.seed(mock_res_id, all=0)(mock_res)
        result = _do_simple_bind('cn=manager,dc=example,dc=com', 'ldaptest', user_search=user, group_search=None, username=username, password=password)

        expected_methods_called = (
            self.connect_methods +
            ['simple_bind_s', 'whoami_s', 'search', 'result', 'unbind']
        )

        self.assertEquals(self.ldapobj.methods_called(), expected_methods_called)
        self.assertFalse(result) 
開發者ID:StackStorm,項目名稱:st2-auth-backend-ldap,代碼行數:21,代碼來源:test_ldap_backend.py

示例4: _count_netgroups

# 需要導入模塊: import ldap [as 別名]
# 或者: from ldap import SCOPE_ONELEVEL [as 別名]
def _count_netgroups(self):
        self._log.debug('Counting netgroups...')
        results = self._search(
            'cn=ng,cn=alt,%s' % self._base_dn,
            '(ipaUniqueID=*)',
            ['dn'],
            scope=ldap.SCOPE_ONELEVEL
        )

        if not results and type(results) is not list:
            r = 0
        else:
            r = len(results)

        self._log.debug(r)
        return r 
開發者ID:peterpakos,項目名稱:checkipaconsistency,代碼行數:18,代碼來源:freeipaserver.py

示例5: _count_certificates

# 需要導入模塊: import ldap [as 別名]
# 或者: from ldap import SCOPE_ONELEVEL [as 別名]
def _count_certificates(self):
        self._log.debug('Counting certificates...')
        results = self._search(
            'ou=certificateRepository,ou=ca,o=ipaca',
            '(certStatus=*)',
            ['subjectName'],
            scope=ldap.SCOPE_ONELEVEL
        )

        if not results and type(results) is not list:
            r = 0
        else:
            r = len(results)

        self._log.debug(r)
        return r 
開發者ID:peterpakos,項目名稱:checkipaconsistency,代碼行數:18,代碼來源:freeipaserver.py

示例6: _scope_to_ldap_option

# 需要導入模塊: import ldap [as 別名]
# 或者: from ldap import SCOPE_ONELEVEL [as 別名]
def _scope_to_ldap_option(self, scope):
        """
        Transform scope string into ldap module constant.
        """
        if 'base' in scope.lower():
            opt = ldap.SCOPE_BASE
        elif 'onelevel' in scope.lower():
            opt = ldap.SCOPE_ONELEVEL
        else:
            opt = ldap.SCOPE_SUBTREE
        return opt 
開發者ID:StackStorm,項目名稱:st2-auth-backend-ldap,代碼行數:13,代碼來源:ldap_backend.py

示例7: test_search_valid_username_valid_group

# 需要導入模塊: import ldap [as 別名]
# 或者: from ldap import SCOPE_ONELEVEL [as 別名]
def test_search_valid_username_valid_group(self):
        username = 'john_connor'
        password = 'HastaLavista'
        user_dn = 'uid={},ou=users,dc=example,dc=com'.format(username)
        mock_user_res_id = 1234
        mock_user_res = (ldap.RES_SEARCH_RESULT, [(user_dn, LDAPAuthenticationBackendTestCase.directory[user_dn])])

        groupname = 'resistance'
        group_dn = 'cn={groupname},ou=groups,dc=example,dc=com'.format(groupname=groupname)
        mock_group_res_id = 9999
        mock_group_res = (ldap.RES_SEARCH_RESULT, [(group_dn, LDAPAuthenticationBackendTestCase.directory[group_dn])])

        user = {"base_dn": "ou=users,dc=example,dc=com", "search_filter": "(uid={username})", "scope": "onelevel"}
        group = {"base_dn": "ou=groups,dc=example,dc=com", "search_filter": "(&(cn=%s)(memberUid={username}))"%groupname, "scope": "subtree"}

        self.ldapobj._search.seed(user["base_dn"], ldap.SCOPE_ONELEVEL, user["search_filter"].format(username=username))(mock_user_res_id)
        self.ldapobj._search.seed(group["base_dn"], ldap.SCOPE_SUBTREE, group["search_filter"].format(username=username))(mock_group_res_id)
        self.ldapobj._result.seed(mock_user_res_id, all=0)(mock_user_res)
        self.ldapobj._result.seed(mock_group_res_id, all=0)(mock_group_res)

        result = _do_simple_bind('cn=manager,dc=example,dc=com', 'ldaptest', user_search=user, group_search=group, username=username, password=password)

        expected_methods_called = (
            self.connect_methods +
            ['simple_bind_s', 'whoami_s', 'search', 'result', 'result'] +
            self.connect_methods +
            ['simple_bind_s', 'whoami_s', 'unbind', 'search', 'result', 'result', 'unbind']
        )

        self.assertEquals(self.ldapobj.methods_called(), expected_methods_called)
        self.assertTrue(result) 
開發者ID:StackStorm,項目名稱:st2-auth-backend-ldap,代碼行數:33,代碼來源:test_ldap_backend.py

示例8: nodes_of

# 需要導入模塊: import ldap [as 別名]
# 或者: from ldap import SCOPE_ONELEVEL [as 別名]
def nodes_of(region):
    svr = ldap.initialize('ldap://ldap.example.com')
    svr.simple_bind_s('uid=user,cn=users,cn=accounts,dc=in,dc=example,dc=com', 'example-password')

    return [i[1]['fqdn'][0] for i in svr.search_s(
        'cn=computers,cn=accounts,dc=in,dc=example,dc=com',
        ldap.SCOPE_ONELEVEL,
        'cn=*.%s.in.example.com' % region,
        ['fqdn']
    )] 
開發者ID:leancloud,項目名稱:satori,代碼行數:12,代碼來源:region.py

示例9: parse_scope_opt

# 需要導入模塊: import ldap [as 別名]
# 或者: from ldap import SCOPE_ONELEVEL [as 別名]
def parse_scope_opt(value):
    """Convert `scope` option to ldap's `SCOPE_*` constant."""
    return {
        'base': ldap.SCOPE_BASE,
        'one': ldap.SCOPE_ONELEVEL,
        'sub': ldap.SCOPE_SUBTREE
    }[value.lower()] if value else None 
開發者ID:jirutka,項目名稱:ssh-ldap-pubkey,代碼行數:9,代碼來源:config.py

示例10: search

# 需要導入模塊: import ldap [as 別名]
# 或者: from ldap import SCOPE_ONELEVEL [as 別名]
def search(self, base, filter=None, scope=None, attrs=None):
        scope = {
            "base":         ldap.SCOPE_BASE,
            "subtree":      ldap.SCOPE_SUBTREE,
            "sub":          ldap.SCOPE_SUBTREE,
            "onelevel":     ldap.SCOPE_ONELEVEL,
            "one":          ldap.SCOPE_ONELEVEL,
            "subordinate":  ldap.SCOPE_SUBORDINATE,
            "child":        ldap.SCOPE_SUBORDINATE,
        }[scope or "subtree"]
        result = self.conn.search_ext_s(base, scope, filter, attrs)
        result = [(dn, CaseInsensitiveDict(attrs)) for (dn, attrs) in result]
        return result 
開發者ID:grawity,項目名稱:code,代碼行數:15,代碼來源:client_libldap.py

示例11: _count_hbac_rules

# 需要導入模塊: import ldap [as 別名]
# 或者: from ldap import SCOPE_ONELEVEL [as 別名]
def _count_hbac_rules(self):
        self._log.debug('Counting HBAC rules...')
        results = self._search(
            'cn=hbac,%s' % self._base_dn,
            '(ipaUniqueID=*)',
            scope=ldap.SCOPE_ONELEVEL
        )
        r = len(results)
        self._log.debug(r)
        return r 
開發者ID:peterpakos,項目名稱:checkipaconsistency,代碼行數:12,代碼來源:freeipaserver.py

示例12: _count_sudo_rules

# 需要導入模塊: import ldap [as 別名]
# 或者: from ldap import SCOPE_ONELEVEL [as 別名]
def _count_sudo_rules(self):
        self._log.debug('Counting SUDO rules...')
        results = self._search(
            'cn=sudorules,cn=sudo,%s' % self._base_dn,
            '(ipaUniqueID=*)',
            scope=ldap.SCOPE_ONELEVEL
        )
        r = len(results)
        self._log.debug(r)
        return r 
開發者ID:peterpakos,項目名稱:checkipaconsistency,代碼行數:12,代碼來源:freeipaserver.py

示例13: _count_dns_zones

# 需要導入模塊: import ldap [as 別名]
# 或者: from ldap import SCOPE_ONELEVEL [as 別名]
def _count_dns_zones(self):
        self._log.debug('Counting DNS zones...')
        results = self._search(
            'cn=dns,%s' % self._base_dn,
            '(|(objectClass=idnszone)(objectClass=idnsforwardzone))',
            scope=ldap.SCOPE_ONELEVEL
        )
        if not results and type(results) is not list:
            r = 0
        else:
            r = len(results)
        self._log.debug(r)
        return r 
開發者ID:peterpakos,項目名稱:checkipaconsistency,代碼行數:15,代碼來源:freeipaserver.py


注:本文中的ldap.SCOPE_ONELEVEL屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。