本文整理汇总了Python中twisted.cred.checkers.ICredentialsChecker方法的典型用法代码示例。如果您正苦于以下问题:Python checkers.ICredentialsChecker方法的具体用法?Python checkers.ICredentialsChecker怎么用?Python checkers.ICredentialsChecker使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类twisted.cred.checkers
的用法示例。
在下文中一共展示了checkers.ICredentialsChecker方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: requestAvatarId
# 需要导入模块: from twisted.cred import checkers [as 别名]
# 或者: from twisted.cred.checkers import ICredentialsChecker [as 别名]
def requestAvatarId(self, credentials):
"""
Part of the L{ICredentialsChecker} interface. Called by a portal with
some credentials to check if they'll authenticate a user. We check the
interfaces that the credentials provide against our list of acceptable
checkers. If one of them matches, we ask that checker to verify the
credentials. If they're valid, we call our L{_cbGoodAuthentication}
method to continue.
@param credentials: the credentials the L{Portal} wants us to verify
"""
ifac = providedBy(credentials)
for i in ifac:
c = self.checkers.get(i)
if c is not None:
d = defer.maybeDeferred(c.requestAvatarId, credentials)
return d.addCallback(self._cbGoodAuthentication,
credentials)
return defer.fail(UnhandledCredentials("No checker for %s" % \
', '.join(map(reflect.qual, ifac))))
示例2: getCredentialsCheckers
# 需要导入模块: from twisted.cred import checkers [as 别名]
# 或者: from twisted.cred.checkers import ICredentialsChecker [as 别名]
def getCredentialsCheckers(self):
"""
Return credentials checkers for this domain.
Subclasses should override this method.
@rtype: L{list} of L{ICredentialsChecker
<checkers.ICredentialsChecker>} provider
@return: Credentials checkers for this domain.
"""
raise NotImplementedError
示例3: getAuthorizedKeys
# 需要导入模块: from twisted.cred import checkers [as 别名]
# 或者: from twisted.cred.checkers import ICredentialsChecker [as 别名]
def getAuthorizedKeys(avatarId):
"""
Gets an iterable of authorized keys that are valid for the given
C{avatarId}.
@param avatarId: the ID of the avatar
@type avatarId: valid return value of
L{twisted.cred.checkers.ICredentialsChecker.requestAvatarId}
@return: an iterable of L{twisted.conch.ssh.keys.Key}
"""
示例4: test_portalRejectedSenderAddress
# 需要导入模块: from twisted.cred import checkers [as 别名]
# 或者: from twisted.cred.checkers import ICredentialsChecker [as 别名]
def test_portalRejectedSenderAddress(self):
"""
Test that a C{MAIL FROM} command with an address rejected by an
L{smtp.SMTP} instance's portal is responded to with the correct error
code.
"""
class DisallowAnonymousAccess(object):
"""
Checker for L{IAnonymous} which rejects authentication attempts.
"""
implements(ICredentialsChecker)
credentialInterfaces = (IAnonymous,)
def requestAvatarId(self, credentials):
return defer.fail(UnauthorizedLogin())
realm = SingletonRealm(smtp.IMessageDelivery, NotImplementedDelivery())
portal = Portal(realm, [DisallowAnonymousAccess()])
proto = smtp.SMTP()
proto.portal = portal
trans = StringTransport()
proto.makeConnection(trans)
# Deal with the necessary preliminaries
proto.dataReceived('HELO example.com\r\n')
trans.clear()
# Try to specify our sender address
proto.dataReceived('MAIL FROM:<alice@example.com>\r\n')
# Clean up the protocol before doing anything that might raise an
# exception.
proto.connectionLost(error.ConnectionLost())
# Make sure that we received exactly the correct response
self.assertEqual(
trans.value(),
'550 Cannot receive from specified address '
'<alice@example.com>: Sender not acceptable\r\n')
示例5: logInAndCheck
# 需要导入模块: from twisted.cred import checkers [as 别名]
# 或者: from twisted.cred.checkers import ICredentialsChecker [as 别名]
def logInAndCheck(self, username, domain='localhost'):
"""
Ensure that logging in via cred succeeds based on the accounts
managed by L{axiom.userbase.LoginSystem}.
"""
s = self.store
def _speedup():
l = userbase.LoginSystem(store=s)
dependency.installOn(l, s)
s.checkpoint()
p = Portal(IRealm(s),
[ICredentialsChecker(s)])
a = l.addAccount(username, 'localhost', SECRET)
gph = GarbageProtocolHandler(store=a.avatars.open(),
garbage=0)
dependency.installOn(gph, gph.store)
return p, gph
p, gph = s.transact(_speedup)
def wasItGph((interface, avatar, logout)):
self.assertEquals(interface, IGarbage)
self.assertEquals(avatar, gph)
logout()
return p.login(UsernamePassword('bob@localhost', SECRET), None, IGarbage
).addCallback(wasItGph)
示例6: _login
# 需要导入模块: from twisted.cred import checkers [as 别名]
# 或者: from twisted.cred.checkers import ICredentialsChecker [as 别名]
def _login(self, avatarId, password):
cc = ICredentialsChecker(self.store)
p = Portal(IRealm(self.store), [cc])
return p.login(UsernamePassword(avatarId, password), None,
lambda orig, default: orig)
示例7: test_install
# 需要导入模块: from twisted.cred import checkers [as 别名]
# 或者: from twisted.cred.checkers import ICredentialsChecker [as 别名]
def test_install(self):
"""
Create a database, install userbase and check that the store
implements L{IRealm} and L{ICredentialsChecker}. i.e. that userbase
has been installed. This is an integration test.
"""
self.userbase('install')
self.assertImplements(self.store, IRealm)
self.assertImplements(self.store, ICredentialsChecker)
示例8: testUpgrade
# 需要导入模块: from twisted.cred import checkers [as 别名]
# 或者: from twisted.cred.checkers import ICredentialsChecker [as 别名]
def testUpgrade(self):
p = Portal(IRealm(self.store),
[ICredentialsChecker(self.store)])
def loggedIn((ifc, av, lgo)):
assert av.garbage == 7
# Bug in cooperator? this triggers an exception.
# return svc.stopService()
d = p.login(
UsernamePassword('test@example.com', SECRET), None, IGarbage)
return d.addCallback(loggedIn)
示例9: testUpgrade
# 需要导入模块: from twisted.cred import checkers [as 别名]
# 或者: from twisted.cred.checkers import ICredentialsChecker [as 别名]
def testUpgrade(self):
p = Portal(IRealm(self.store),
[ICredentialsChecker(self.store)])
def loggedIn((interface, avatarAspect, logout)):
# if we can login, i guess everything is fine
self.assertEquals(avatarAspect.garbage, GARBAGE_LEVEL)
creds = UsernamePassword('@'.join(CREDENTIALS[:-1]), CREDENTIALS[-1])
d = p.login(creds, None, IGarbage)
return d.addCallback(loggedIn)