当前位置: 首页>>代码示例>>Python>>正文


Python credentials.IUsernamePassword方法代码示例

本文整理汇总了Python中twisted.cred.credentials.IUsernamePassword方法的典型用法代码示例。如果您正苦于以下问题:Python credentials.IUsernamePassword方法的具体用法?Python credentials.IUsernamePassword怎么用?Python credentials.IUsernamePassword使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在twisted.cred.credentials的用法示例。


在下文中一共展示了credentials.IUsernamePassword方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: requestAvatarId

# 需要导入模块: from twisted.cred import credentials [as 别名]
# 或者: from twisted.cred.credentials import IUsernamePassword [as 别名]
def requestAvatarId(self, c):
        try:
            u, p = self.getUser(c.username)
        except KeyError:
            return defer.fail(error.UnauthorizedLogin())
        else:
            up = credentials.IUsernamePassword(c, None)
            if self.hash:
                if up is not None:
                    h = self.hash(up.username, up.password, p)
                    if h == p:
                        return defer.succeed(u)
                return defer.fail(error.UnauthorizedLogin())
            else:
                return defer.maybeDeferred(c.checkPassword, p
                    ).addCallback(self._cbPasswordMatch, u)



# For backwards compatibility
# Allow access as the old name. 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:23,代码来源:checkers.py

示例2: test_createsDictionary

# 需要导入模块: from twisted.cred import credentials [as 别名]
# 或者: from twisted.cred.credentials import IUsernamePassword [as 别名]
def test_createsDictionary(self):
        """
        Test that the --auth command line creates a dictionary
        mapping supported interfaces to the list of credentials
        checkers that support it.
        """
        options = DummyOptions()
        options.parseOptions(['--auth', 'memory', '--auth', 'anonymous'])
        chd = options['credInterfaces']
        self.assertEqual(len(chd[credentials.IAnonymous]), 1)
        self.assertEqual(len(chd[credentials.IUsernamePassword]), 1)
        chdAnonymous = chd[credentials.IAnonymous][0]
        chdUserPass = chd[credentials.IUsernamePassword][0]
        self.assertTrue(checkers.ICredentialsChecker.providedBy(chdAnonymous))
        self.assertTrue(checkers.ICredentialsChecker.providedBy(chdUserPass))
        self.assertIn(credentials.IAnonymous,
                      chdAnonymous.credentialInterfaces)
        self.assertIn(credentials.IUsernamePassword,
                      chdUserPass.credentialInterfaces) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:21,代码来源:test_strcred.py

示例3: test_canAddSupportedChecker

# 需要导入模块: from twisted.cred import credentials [as 别名]
# 或者: from twisted.cred.credentials import IUsernamePassword [as 别名]
def test_canAddSupportedChecker(self):
        """
        Test that when addChecker is called with a checker that
        implements at least one of the interfaces our application
        supports, it is successful.
        """
        options = OptionsForUsernamePassword()
        options.addChecker(self.goodChecker)
        iface = options.supportedInterfaces[0]
        # Test that we did get IUsernamePassword
        self.assertIdentical(
            options['credInterfaces'][iface][0], self.goodChecker)
        self.assertIdentical(options['credCheckers'][0], self.goodChecker)
        # Test that we didn't get IUsernameHashedPassword
        self.assertEqual(len(options['credInterfaces'][iface]), 1)
        self.assertEqual(len(options['credCheckers']), 1) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:18,代码来源:test_strcred.py

示例4: test_createsDictionary

# 需要导入模块: from twisted.cred import credentials [as 别名]
# 或者: from twisted.cred.credentials import IUsernamePassword [as 别名]
def test_createsDictionary(self):
        """
        The C{--auth} command line creates a dictionary mapping supported
        interfaces to the list of credentials checkers that support it.
        """
        options = DummyOptions()
        options.parseOptions(['--auth', 'memory', '--auth', 'anonymous'])
        chd = options['credInterfaces']
        self.assertEqual(len(chd[credentials.IAnonymous]), 1)
        self.assertEqual(len(chd[credentials.IUsernamePassword]), 1)
        chdAnonymous = chd[credentials.IAnonymous][0]
        chdUserPass = chd[credentials.IUsernamePassword][0]
        self.assertTrue(checkers.ICredentialsChecker.providedBy(chdAnonymous))
        self.assertTrue(checkers.ICredentialsChecker.providedBy(chdUserPass))
        self.assertIn(credentials.IAnonymous,
                      chdAnonymous.credentialInterfaces)
        self.assertIn(credentials.IUsernamePassword,
                      chdUserPass.credentialInterfaces) 
开发者ID:wistbean,项目名称:learn_python3_spider,代码行数:20,代码来源:test_strcred.py

示例5: requestAvatarId

# 需要导入模块: from twisted.cred import credentials [as 别名]
# 或者: from twisted.cred.credentials import IUsernamePassword [as 别名]
def requestAvatarId(self, c):
        try:
            u, p = self.getUser(c.username)
        except KeyError:
            return defer.fail(error.UnauthorizedLogin())
        else:
            up = credentials.IUsernamePassword(c, None)
            if self.hash:
                if up is not None:
                    h = self.hash(up.username, up.password, p)
                    if h == p:
                        return defer.succeed(u)
                return defer.fail(error.UnauthorizedLogin())
            else:
                return defer.maybeDeferred(c.checkPassword, p
                    ).addCallback(self._cbPasswordMatch, u) 
开发者ID:kuri65536,项目名称:python-for-android,代码行数:18,代码来源:checkers.py

示例6: test_checkersPamAuth

# 需要导入模块: from twisted.cred import credentials [as 别名]
# 或者: from twisted.cred.credentials import IUsernamePassword [as 别名]
def test_checkersPamAuth(self):
        """
        The L{OpenSSHFactory} built by L{tap.makeService} has a portal with
        L{IPluggableAuthenticationModules}, L{ISSHPrivateKey} and
        L{IUsernamePassword} interfaces registered as checkers if C{pamauth} is
        available.
        """
        # Fake the presence of pamauth, even if PyPAM is not installed
        self.patch(tap, "pamauth", object())
        config = tap.Options()
        service = tap.makeService(config)
        portal = service.factory.portal
        self.assertEquals(
            set(portal.checkers.keys()),
            set([IPluggableAuthenticationModules, ISSHPrivateKey,
                 IUsernamePassword])) 
开发者ID:kuri65536,项目名称:python-for-android,代码行数:18,代码来源:test_tap.py

示例7: test_createsDictionary

# 需要导入模块: from twisted.cred import credentials [as 别名]
# 或者: from twisted.cred.credentials import IUsernamePassword [as 别名]
def test_createsDictionary(self):
        """
        Test that the --auth command line creates a dictionary
        mapping supported interfaces to the list of credentials
        checkers that support it.
        """
        options = DummyOptions()
        options.parseOptions(['--auth', 'memory', '--auth', 'anonymous'])
        chd = options['credInterfaces']
        self.assertEquals(len(chd[credentials.IAnonymous]), 1)
        self.assertEquals(len(chd[credentials.IUsernamePassword]), 1)
        chdAnonymous = chd[credentials.IAnonymous][0]
        chdUserPass = chd[credentials.IUsernamePassword][0]
        self.assertTrue(checkers.ICredentialsChecker.providedBy(chdAnonymous))
        self.assertTrue(checkers.ICredentialsChecker.providedBy(chdUserPass))
        self.assertIn(credentials.IAnonymous,
                      chdAnonymous.credentialInterfaces)
        self.assertIn(credentials.IUsernamePassword,
                      chdUserPass.credentialInterfaces) 
开发者ID:kuri65536,项目名称:python-for-android,代码行数:21,代码来源:test_strcred.py

示例8: testAnonymousLoginDenied

# 需要导入模块: from twisted.cred import credentials [as 别名]
# 或者: from twisted.cred.credentials import IUsernamePassword [as 别名]
def testAnonymousLoginDenied(self):
        # Reconfigure the server to disallow anonymous access, and to have an
        # IUsernamePassword checker that always rejects.
        self.factory.allowAnonymous = False
        denyAlwaysChecker = checkers.InMemoryUsernamePasswordDatabaseDontUse()
        self.factory.portal.registerChecker(denyAlwaysChecker,
                                            credentials.IUsernamePassword)

        # Same response code as allowAnonymous=True, but different text.
        d = self.assertCommandResponse(
            'USER anonymous',
            ['331 Password required for anonymous.'])

        # It will be denied.  No-one can login.
        d = self.assertCommandFailed(
            'PASS test@twistedmatrix.com',
            ['530 Sorry, Authentication failed.'],
            chainDeferred=d)

        # It's not just saying that.  You aren't logged in.
        d = self.assertCommandFailed(
            'PWD',
            ['530 Please login with USER and PASS.'],
            chainDeferred=d)
        return d 
开发者ID:kuri65536,项目名称:python-for-android,代码行数:27,代码来源:test_ftp.py

示例9: test_listCheckers

# 需要导入模块: from twisted.cred import credentials [as 别名]
# 或者: from twisted.cred.credentials import IUsernamePassword [as 别名]
def test_listCheckers(self):
        """
        The checkers in a portal can check only certain types of credentials.
        Since this portal has
        L{checkers.InMemoryUsernamePasswordDatabaseDontUse} registered, it
        """
        expected = [credentials.IUsernamePassword,
                    credentials.IUsernameHashedPassword]
        got = self.portal.listCredentialsInterfaces()
        self.assertEqual(sorted(got), sorted(expected)) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:12,代码来源:test_cred.py

示例10: test_isChecker

# 需要导入模块: from twisted.cred import credentials [as 别名]
# 或者: from twisted.cred.credentials import IUsernamePassword [as 别名]
def test_isChecker(self):
        """
        Verifies that strcred.makeChecker('memory') returns an object
        that implements the L{ICredentialsChecker} interface.
        """
        self.assertTrue(checkers.ICredentialsChecker.providedBy(self.checker))
        self.assertIn(credentials.IUsernamePassword,
                      self.checker.credentialInterfaces) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:10,代码来源:test_strcred.py

示例11: test_credInterfacesProvidesLists

# 需要导入模块: from twisted.cred import credentials [as 别名]
# 或者: from twisted.cred.credentials import IUsernamePassword [as 别名]
def test_credInterfacesProvidesLists(self):
        """
        Test that when two --auth arguments are passed along which
        support the same interface, a list with both is created.
        """
        options = DummyOptions()
        options.parseOptions(['--auth', 'memory', '--auth', 'unix'])
        self.assertEqual(
            options['credCheckers'],
            options['credInterfaces'][credentials.IUsernamePassword]) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:12,代码来源:test_strcred.py

示例12: test_supportsInterface

# 需要导入模块: from twisted.cred import credentials [as 别名]
# 或者: from twisted.cred.credentials import IUsernamePassword [as 别名]
def test_supportsInterface(self):
        """
        Test that the supportsInterface method behaves appropriately.
        """
        options = OptionsForUsernamePassword()
        self.assertTrue(
            options.supportsInterface(credentials.IUsernamePassword))
        self.assertFalse(
            options.supportsInterface(credentials.IAnonymous))
        self.assertRaises(
            strcred.UnsupportedInterfaces, options.addChecker,
            self.anonChecker) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:14,代码来源:test_strcred.py

示例13: test_supportsAllInterfaces

# 需要导入模块: from twisted.cred import credentials [as 别名]
# 或者: from twisted.cred.credentials import IUsernamePassword [as 别名]
def test_supportsAllInterfaces(self):
        """
        Test that the supportsInterface method behaves appropriately
        when the supportedInterfaces attribute is None.
        """
        options = OptionsSupportsAllInterfaces()
        self.assertTrue(
            options.supportsInterface(credentials.IUsernamePassword))
        self.assertTrue(
            options.supportsInterface(credentials.IAnonymous)) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:12,代码来源:test_strcred.py

示例14: test_defaultAuths

# 需要导入模块: from twisted.cred import credentials [as 别名]
# 或者: from twisted.cred.credentials import IUsernamePassword [as 别名]
def test_defaultAuths(self):
        """
        Make sure that if the C{--auth} command-line option is not passed,
        the default checkers are (for backwards compatibility): SSH and UNIX
        """
        numCheckers = 2

        self.assertIn(ISSHPrivateKey, self.options['credInterfaces'],
            "SSH should be one of the default checkers")
        self.assertIn(IUsernamePassword, self.options['credInterfaces'],
            "UNIX should be one of the default checkers")
        self.assertEqual(numCheckers, len(self.options['credCheckers']),
            "There should be %d checkers by default" % (numCheckers,)) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:15,代码来源:test_tap.py

示例15: test_checkers

# 需要导入模块: from twisted.cred import credentials [as 别名]
# 或者: from twisted.cred.credentials import IUsernamePassword [as 别名]
def test_checkers(self):
        """
        The L{OpenSSHFactory} built by L{tap.makeService} has a portal with
        L{ISSHPrivateKey} and L{IUsernamePassword} interfaces registered as
        checkers.
        """
        config = tap.Options()
        service = tap.makeService(config)
        portal = service.factory.portal
        self.assertEqual(
            set(portal.checkers.keys()),
            set([ISSHPrivateKey, IUsernamePassword])) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:14,代码来源:test_tap.py


注:本文中的twisted.cred.credentials.IUsernamePassword方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。