本文整理匯總了Python中twisted.cred.credentials.username方法的典型用法代碼示例。如果您正苦於以下問題:Python credentials.username方法的具體用法?Python credentials.username怎麽用?Python credentials.username使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類twisted.cred.credentials
的用法示例。
在下文中一共展示了credentials.username方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: requestAvatarId
# 需要導入模塊: from twisted.cred import credentials [as 別名]
# 或者: from twisted.cred.credentials import username [as 別名]
def requestAvatarId(credentials):
"""
@param credentials: something which implements one of the interfaces in
self.credentialInterfaces.
@return: a Deferred which will fire a string which identifies an
avatar, an empty tuple to specify an authenticated anonymous user
(provided as checkers.ANONYMOUS) or fire a Failure(UnauthorizedLogin).
Alternatively, return the result itself.
@see: L{twisted.cred.credentials}
"""
# A note on anonymity - We do not want None as the value for anonymous
# because it is too easy to accidentally return it. We do not want the
# empty string, because it is too easy to mistype a password file. For
# example, an .htpasswd file may contain the lines: ['hello:asdf',
# 'world:asdf', 'goodbye', ':world']. This misconfiguration will have an
# ill effect in any case, but accidentally granting anonymous access is a
# worse failure mode than simply granting access to an untypeable
# username. We do not want an instance of 'object', because that would
# create potential problems with persistence.
示例2: _loadCredentials
# 需要導入模塊: from twisted.cred import credentials [as 別名]
# 或者: from twisted.cred.credentials import username [as 別名]
def _loadCredentials(self):
"""
Loads the credentials from the configured file.
@return: An iterable of C{username, password} couples.
@rtype: C{iterable}
@raise UnauthorizedLogin: when failing to read the credentials from the
file.
"""
try:
with open(self.filename, "rb") as f:
for line in f:
line = line.rstrip()
parts = line.split(self.delim)
if self.ufield >= len(parts) or self.pfield >= len(parts):
continue
if self.caseSensitive:
yield parts[self.ufield], parts[self.pfield]
else:
yield parts[self.ufield].lower(), parts[self.pfield]
except IOError as e:
self._log.error("Unable to load credentials db: {e!r}", e=e)
raise error.UnauthorizedLogin()
示例3: assertServerAuthenticated
# 需要導入模塊: from twisted.cred import credentials [as 別名]
# 或者: from twisted.cred.credentials import username [as 別名]
def assertServerAuthenticated(self, loginArgs, username="username", password="password"):
"""
Assert that a login attempt has been made, that the credentials and
interfaces passed to it are correct, and that when the login request
is satisfied, a successful response is sent by the ESMTP server
instance.
@param loginArgs: A C{list} previously passed to L{portalFactory}.
"""
d, credentials, mind, interfaces = loginArgs.pop()
self.assertEqual(loginArgs, [])
self.assertTrue(twisted.cred.credentials.IUsernamePassword.providedBy(credentials))
self.assertEqual(credentials.username, username)
self.assertTrue(credentials.checkPassword(password))
self.assertIn(smtp.IMessageDeliveryFactory, interfaces)
self.assertIn(smtp.IMessageDelivery, interfaces)
d.callback((smtp.IMessageDeliveryFactory, None, lambda: None))
self.assertEqual(
["235 Authentication successful."],
self.transport.value().splitlines())
示例4: test_plainAuthentication
# 需要導入模塊: from twisted.cred import credentials [as 別名]
# 或者: from twisted.cred.credentials import username [as 別名]
def test_plainAuthentication(self):
"""
Test that the LOGIN authentication mechanism can be used
"""
loginArgs = []
self.server.portal = self.portalFactory(loginArgs)
self.server.dataReceived('EHLO\r\n')
self.transport.clear()
self.assertServerResponse(
'AUTH LOGIN\r\n',
["334 " + "User Name\0".encode('base64').strip()])
self.assertServerResponse(
'username'.encode('base64') + '\r\n',
["334 " + "Password\0".encode('base64').strip()])
self.assertServerResponse(
'password'.encode('base64').strip() + '\r\n',
[])
self.assertServerAuthenticated(loginArgs)
示例5: test_plainAuthenticationEmptyPassword
# 需要導入模塊: from twisted.cred import credentials [as 別名]
# 或者: from twisted.cred.credentials import username [as 別名]
def test_plainAuthenticationEmptyPassword(self):
"""
Test that giving an empty password for plain auth succeeds.
"""
loginArgs = []
self.server.portal = self.portalFactory(loginArgs)
self.server.dataReceived('EHLO\r\n')
self.transport.clear()
self.assertServerResponse(
'AUTH LOGIN\r\n',
["334 " + "User Name\0".encode('base64').strip()])
self.assertServerResponse(
'username'.encode('base64') + '\r\n',
["334 " + "Password\0".encode('base64').strip()])
self.assertServerResponse('\r\n', [])
self.assertServerAuthenticated(loginArgs, password='')
示例6: test_plainAuthenticationInitialResponse
# 需要導入模塊: from twisted.cred import credentials [as 別名]
# 或者: from twisted.cred.credentials import username [as 別名]
def test_plainAuthenticationInitialResponse(self):
"""
The response to the first challenge may be included on the AUTH command
line. Test that this is also supported.
"""
loginArgs = []
self.server.portal = self.portalFactory(loginArgs)
self.server.dataReceived('EHLO\r\n')
self.transport.clear()
self.assertServerResponse(
'AUTH LOGIN ' + "username".encode('base64').strip() + '\r\n',
["334 " + "Password\0".encode('base64').strip()])
self.assertServerResponse(
'password'.encode('base64').strip() + '\r\n',
[])
self.assertServerAuthenticated(loginArgs)
示例7: assertServerAuthenticated
# 需要導入模塊: from twisted.cred import credentials [as 別名]
# 或者: from twisted.cred.credentials import username [as 別名]
def assertServerAuthenticated(self, loginArgs, username=b"username",
password=b"password"):
"""
Assert that a login attempt has been made, that the credentials and
interfaces passed to it are correct, and that when the login request
is satisfied, a successful response is sent by the ESMTP server
instance.
@param loginArgs: A C{list} previously passed to L{portalFactory}.
@param username: The login user.
@param password: The login password.
"""
d, credentials, mind, interfaces = loginArgs.pop()
self.assertEqual(loginArgs, [])
self.assertTrue(twisted.cred.credentials.IUsernamePassword.providedBy(credentials))
self.assertEqual(credentials.username, username)
self.assertTrue(credentials.checkPassword(password))
self.assertIn(smtp.IMessageDeliveryFactory, interfaces)
self.assertIn(smtp.IMessageDelivery, interfaces)
d.callback((smtp.IMessageDeliveryFactory, None, lambda: None))
self.assertEqual(
[b"235 Authentication successful."],
self.transport.value().splitlines())
示例8: test_plainAuthentication
# 需要導入模塊: from twisted.cred import credentials [as 別名]
# 或者: from twisted.cred.credentials import username [as 別名]
def test_plainAuthentication(self):
"""
Test that the LOGIN authentication mechanism can be used
"""
loginArgs = []
self.server.portal = self.portalFactory(loginArgs)
self.server.dataReceived(b'EHLO\r\n')
self.transport.clear()
self.assertServerResponse(
b'AUTH LOGIN\r\n',
[b"334 " + base64.b64encode(b"User Name\0").strip()])
self.assertServerResponse(
base64.b64encode(b'username') + b'\r\n',
[b"334 " + base64.b64encode(b"Password\0").strip()])
self.assertServerResponse(
base64.b64encode(b'password').strip() + b'\r\n',
[])
self.assertServerAuthenticated(loginArgs)
示例9: test_plainAuthenticationEmptyPassword
# 需要導入模塊: from twisted.cred import credentials [as 別名]
# 或者: from twisted.cred.credentials import username [as 別名]
def test_plainAuthenticationEmptyPassword(self):
"""
Test that giving an empty password for plain auth succeeds.
"""
loginArgs = []
self.server.portal = self.portalFactory(loginArgs)
self.server.dataReceived(b'EHLO\r\n')
self.transport.clear()
self.assertServerResponse(
b'AUTH LOGIN\r\n',
[b"334 " + base64.b64encode(b"User Name\0").strip()])
self.assertServerResponse(
base64.b64encode(b'username') + b'\r\n',
[b"334 " + base64.b64encode(b"Password\0").strip()])
self.assertServerResponse(b'\r\n', [])
self.assertServerAuthenticated(loginArgs, password=b'')
示例10: test_plainAuthenticationInitialResponse
# 需要導入模塊: from twisted.cred import credentials [as 別名]
# 或者: from twisted.cred.credentials import username [as 別名]
def test_plainAuthenticationInitialResponse(self):
"""
The response to the first challenge may be included on the AUTH command
line. Test that this is also supported.
"""
loginArgs = []
self.server.portal = self.portalFactory(loginArgs)
self.server.dataReceived(b'EHLO\r\n')
self.transport.clear()
self.assertServerResponse(
b'AUTH LOGIN ' + base64.b64encode(b"username").strip() + b'\r\n',
[b"334 " + base64.b64encode(b"Password\0").strip()])
self.assertServerResponse(
base64.b64encode(b'password').strip() + b'\r\n',
[])
self.assertServerAuthenticated(loginArgs)
示例11: requestAvatarId
# 需要導入模塊: from twisted.cred import credentials [as 別名]
# 或者: from twisted.cred.credentials import username [as 別名]
def requestAvatarId(self, credentials):
"""
@param credentials: something which implements one of the interfaces in
self.credentialInterfaces.
@return: a Deferred which will fire a string which identifies an
avatar, an empty tuple to specify an authenticated anonymous user
(provided as checkers.ANONYMOUS) or fire a Failure(UnauthorizedLogin).
Alternatively, return the result itself.
"""
# A note on anonymity - We do not want None as the value for anonymous
# because it is too easy to accidentally return it. We do not want the
# empty string, because it is too easy to mistype a password file. For
# example, an .htpasswd file may contain the lines: ['hello:asdf',
# 'world:asdf', 'goodbye', ':world']. This misconfiguration will have an
# ill effect in any case, but accidentally granting anonymous access is a
# worse failure mode than simply granting access to an untypeable
# username. We do not want an instance of 'object', because that would
# create potential problems with persistence.
示例12: requestAvatarId
# 需要導入模塊: from twisted.cred import credentials [as 別名]
# 或者: from twisted.cred.credentials import username [as 別名]
def requestAvatarId(self, credentials):
username = credentials.username
if username in self.tokens:
if credentials.checkPassword(self.tokens[username]):
return defer.succeed(username)
else:
return defer.fail(
credError.UnauthorizedLogin("Bad session token"))
else:
return defer.fail(
credError.UnauthorizedLogin("No such user"))
示例13: addUser
# 需要導入模塊: from twisted.cred import credentials [as 別名]
# 或者: from twisted.cred.credentials import username [as 別名]
def addUser(self, username, password):
self.users[username] = password
示例14: _cbPasswordMatch
# 需要導入模塊: from twisted.cred import credentials [as 別名]
# 或者: from twisted.cred.credentials import username [as 別名]
def _cbPasswordMatch(self, matched, username):
if matched:
return username
else:
return failure.Failure(error.UnauthorizedLogin())
示例15: getUser
# 需要導入模塊: from twisted.cred import credentials [as 別名]
# 或者: from twisted.cred.credentials import username [as 別名]
def getUser(self, username):
if not self.caseSensitive:
username = username.lower()
if self.cache:
if self._credCache is None or os.path.getmtime(self.filename) > self._cacheTimestamp:
self._cacheTimestamp = os.path.getmtime(self.filename)
self._credCache = dict(self._loadCredentials())
return username, self._credCache[username]
else:
for u, p in self._loadCredentials():
if u == username:
return u, p
raise KeyError(username)