本文整理汇总了Python中twisted.cred.error.Unauthorized方法的典型用法代码示例。如果您正苦于以下问题:Python error.Unauthorized方法的具体用法?Python error.Unauthorized怎么用?Python error.Unauthorized使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类twisted.cred.error
的用法示例。
在下文中一共展示了error.Unauthorized方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: render
# 需要导入模块: from twisted.cred import error [as 别名]
# 或者: from twisted.cred.error import Unauthorized [as 别名]
def render(self, request):
"""
Send www-authenticate headers to the client
"""
def generateWWWAuthenticate(scheme, challenge):
l = []
for k,v in challenge.items():
l.append(networkString("%s=%s" % (k, quoteString(v))))
return b" ".join([scheme, b", ".join(l)])
def quoteString(s):
return '"%s"' % (s.replace('\\', '\\\\').replace('"', '\\"'),)
request.setResponseCode(401)
for fact in self._credentialFactories:
challenge = fact.getChallenge(request)
request.responseHeaders.addRawHeader(
b'www-authenticate',
generateWWWAuthenticate(fact.scheme, challenge))
if request.method == b'HEAD':
return b''
return b'Unauthorized'
示例2: render
# 需要导入模块: from twisted.cred import error [as 别名]
# 或者: from twisted.cred.error import Unauthorized [as 别名]
def render(self, request):
"""
Send www-authenticate headers to the client
"""
def generateWWWAuthenticate(scheme, challenge):
l = []
for k,v in challenge.iteritems():
l.append("%s=%s" % (k, quoteString(v)))
return "%s %s" % (scheme, ", ".join(l))
def quoteString(s):
return '"%s"' % (s.replace('\\', '\\\\').replace('"', '\\"'),)
request.setResponseCode(401)
for fact in self._credentialFactories:
challenge = fact.getChallenge(request)
request.responseHeaders.addRawHeader(
'www-authenticate',
generateWWWAuthenticate(fact.scheme, challenge))
return 'Unauthorized'
示例3: _login
# 需要导入模块: from twisted.cred import error [as 别名]
# 或者: from twisted.cred.error import Unauthorized [as 别名]
def _login(self, credentials, request):
pattern = re.compile("^/sandbox/")
def loginSucceeded(args):
interface, avatar, logout = args
if avatar == checkers.ANONYMOUS and not pattern.match(request.path):
return self._anonymous_resource
else:
return self._root_resource
def loginFailed(result):
if result.check(error.Unauthorized, error.LoginFailed):
return UnauthorizedResource(self._credentialFactories)
else:
log.err(
result,
"HTTPAuthSessionWrapper.getChildWithDefault encountered "
"unexpected error")
return ErrorPage(500, None, None)
d = self._portal.login(credentials, None, IResource)
d.addCallbacks(loginSucceeded, loginFailed)
return d
示例4: validatePublicKey
# 需要导入模块: from twisted.cred import error [as 别名]
# 或者: from twisted.cred.error import Unauthorized [as 别名]
def validatePublicKey(self, pubKeyString):
home = os.path.expanduser('~%s/.ssh/' % self.name)
if home[0] == '~': # couldn't expand
return defer.fail(Unauthorized('not valid user'))
uid, gid = os.geteuid(), os.getegid()
ouid, ogid = pwd.getpwnam(self.name)[2:4]
os.setegid(ogid)
os.seteuid(ouid)
for file in ['authorized_keys', 'authorized_keys2']:
if os.path.exists(home+file):
lines = open(home+file).readlines()
for l in lines:
try:
l2 = l.split()
if len(l2) < 2:
continue
if base64.decodestring(l2[1])==pubKeyString:
os.setegid(gid)
os.seteuid(uid)
return defer.succeed('')
except binascii.Error:
pass # we caught an ssh1 key
os.setegid(gid)
os.seteuid(uid)
return defer.fail(error.ConchError('not valid key'))
示例5: _loginFailed
# 需要导入模块: from twisted.cred import error [as 别名]
# 或者: from twisted.cred.error import Unauthorized [as 别名]
def _loginFailed(self, result):
"""
Handle login failure by presenting either another challenge (for
expected authentication/authorization-related failures) or a server
error page (for anything else).
"""
if result.check(error.Unauthorized, error.LoginFailed):
return UnauthorizedResource(self._credentialFactories)
else:
log.err(
result,
"HTTPAuthSessionWrapper.getChildWithDefault encountered "
"unexpected error")
return ErrorPage(500, None, None)
示例6: render
# 需要导入模块: from twisted.cred import error [as 别名]
# 或者: from twisted.cred.error import Unauthorized [as 别名]
def render(self, request):
"""
Send www-authenticate headers to the client
"""
def ensureBytes(s):
return s.encode('ascii') if isinstance(s, unicode) else s
def generateWWWAuthenticate(scheme, challenge):
l = []
for k, v in challenge.items():
k = ensureBytes(k)
v = ensureBytes(v)
l.append(k + b"=" + quoteString(v))
return b" ".join([scheme, b", ".join(l)])
def quoteString(s):
return b'"' + s.replace(b'\\', b'\\\\').replace(b'"', b'\\"') + b'"'
request.setResponseCode(401)
for fact in self._credentialFactories:
challenge = fact.getChallenge(request)
request.responseHeaders.addRawHeader(
b'www-authenticate',
generateWWWAuthenticate(fact.scheme, challenge))
if request.method == b'HEAD':
return b''
return b'Unauthorized'
示例7: _loginFailed
# 需要导入模块: from twisted.cred import error [as 别名]
# 或者: from twisted.cred.error import Unauthorized [as 别名]
def _loginFailed(self, result):
"""
Handle login failure by presenting either another challenge (for
expected authentication/authorization-related failures) or a server
error page (for anything else).
"""
if result.check(error.Unauthorized, error.LoginFailed):
return UnauthorizedResource(self._credentialFactories)
else:
self._log.failure(
"HTTPAuthSessionWrapper.getChildWithDefault encountered "
"unexpected error",
failure=result,
)
return ErrorPage(500, None, None)
示例8: getChild
# 需要导入模块: from twisted.cred import error [as 别名]
# 或者: from twisted.cred.error import Unauthorized [as 别名]
def getChild(self, path, request):
s = request.getSession()
if s is None:
return request.setupSession()
if path == INIT_PERSPECTIVE:
def loginMethod(identity, password, perspective=None):
idfr = self.service.authorizer.getIdentityRequest(identity)
idfr.addCallback(
lambda ident:
ident.verifyPlainPassword(password).
addCallback(lambda ign:
ident.requestPerspectiveForService(self.service.serviceName))
.addCallback(lambda psp:
s.setClientForService(ident, psp,
self.authResourceFactory(psp),
self.service)))
def loginFailure(f):
if f.trap(Unauthorized):
raise fm.FormException(str(f.value))
raise f
idfr.addErrback(loginFailure)
return idfr
return form.FormProcessor(
loginSignature.method(loginMethod),
callback=self.callback)
elif path == DESTROY_PERSPECTIVE:
s.setClientForService(None, None, None, self.service)
return Redirect(".")
else:
sc = s.clientForService(self.service)
if sc:
return getResource(sc, path, request)
return getResource(self.noAuthResource, path, request)
示例9: getIdentityRequest
# 需要导入模块: from twisted.cred import error [as 别名]
# 或者: from twisted.cred.error import Unauthorized [as 别名]
def getIdentityRequest(self, name):
"""Get a Deferred callback registration object.
I return a L{deferred<twisted.internet.defer.Deferred>} which will
be called back to when an identity is discovered to be available
(or errback for unavailable).
"""
req = defer.Deferred()
if self.identities.has_key(name):
req.callback(self.identities[name])
else:
req.errback(error.Unauthorized("unauthorized"))
return req
示例10: verifyPlainPassword
# 需要导入模块: from twisted.cred import error [as 别名]
# 或者: from twisted.cred.error import Unauthorized [as 别名]
def verifyPlainPassword(self, password):
if pwd:
try:
cryptedPass = pwd.getpwnam(self.name)[1] # password
except KeyError: # no such user
return defer.fail(Unauthorized('no such user'))
else:
if cryptedPass not in ['*', 'x']:
if verifyCryptedPassword(cryptedPass, password):
return defer.succeed('')
return defer.fail(error.ConchError('bad password'))
if shadow:
gid = os.getegid()
uid = os.geteuid()
os.setegid(0)
os.seteuid(0)
try:
shadowPass = shadow.getspnam(self.name)[1]
except KeyError:
os.setegid(gid)
os.seteuid(uid)
return defer.fail(Unauthorized('no such user'))
os.setegid(gid)
os.seteuid(uid)
if verifyCryptedPassword(shadowPass, password):
return defer.succeed('')
return defer.fail(error.ConchError('bad password'))
return defer.fail(error.ConchError('cannot do password auth')) # can't do password auth with out this now