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


Python error.Unauthorized方法代码示例

本文整理汇总了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' 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:24,代码来源:wrapper.py

示例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' 
开发者ID:kuri65536,项目名称:python-for-android,代码行数:22,代码来源:wrapper.py

示例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 
开发者ID:pixelated,项目名称:pixelated-user-agent,代码行数:25,代码来源:auth.py

示例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')) 
开发者ID:kenorb-contrib,项目名称:BitTorrent,代码行数:27,代码来源:identity.py

示例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) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:16,代码来源:wrapper.py

示例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' 
开发者ID:wistbean,项目名称:learn_python3_spider,代码行数:29,代码来源:wrapper.py

示例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) 
开发者ID:wistbean,项目名称:learn_python3_spider,代码行数:17,代码来源:wrapper.py

示例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) 
开发者ID:kenorb-contrib,项目名称:BitTorrent,代码行数:37,代码来源:guard.py

示例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 
开发者ID:kenorb-contrib,项目名称:BitTorrent,代码行数:16,代码来源:authorizer.py

示例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 
开发者ID:kenorb-contrib,项目名称:BitTorrent,代码行数:32,代码来源:identity.py


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