コード例 #1
0
ファイル: cred.py プロジェクト: ShadowJonathan/twisted
 def cmd_ANON(self):
     if self.portal:
         self.portal.login(credentials.Anonymous(), None,
                           IProtocolUser).addCallbacks(
                               self._cbLogin, self._ebLogin)
     else:
         self.sendLine(b"DENIED")
コード例 #2
0
ファイル: test_pb.py プロジェクト: kusoof/wprof
    def test_anonymousLoginWithMultipleCheckers(self):
        """
        Like L{test_anonymousLogin} but against a portal with a checker for
        both IAnonymous and IUsernamePassword.
        """
        self.portal.registerChecker(checkers.AllowAnonymousAccess())
        self.portal.registerChecker(
            checkers.InMemoryUsernamePasswordDatabaseDontUse(user='******'))
        factory = pb.PBClientFactory()
        d = factory.login(credentials.Anonymous(), "BRAINS!")

        def cbLogin(perspective):
            return perspective.callRemote('echo', 123)

        d.addCallback(cbLogin)

        d.addCallback(self.assertEqual, 123)

        def cleanup(passthrough):
            factory.disconnect()
            return passthrough

        d.addBoth(cleanup)

        reactor.connectTCP('127.0.0.1', self.portno, factory)
        return d
コード例 #3
0
ファイル: test_pb.py プロジェクト: kusoof/wprof
    def test_anonymousLogin(self):
        """
        Verify that a PB server using a portal configured with an checker which
        allows IAnonymous credentials can be logged into using IAnonymous
        credentials.
        """
        self.portal.registerChecker(checkers.AllowAnonymousAccess())
        factory = pb.PBClientFactory()
        d = factory.login(credentials.Anonymous(), "BRAINS!")

        def cbLoggedIn(perspective):
            return perspective.callRemote('echo', 123)

        d.addCallback(cbLoggedIn)

        d.addCallback(self.assertEqual, 123)

        def cleanup(passthrough):
            factory.disconnect()
            d = Deferred()
            reactor.callLater(1.0, d.callback, None)
            return d

        d.addBoth(cleanup)

        reactor.connectTCP("127.0.0.1", self.portno, factory)
        return d
コード例 #4
0
    def ftp_PASS(self, password):
        """
        Second part of login.  Get the password the peer wants to
        authenticate with.
        """
        if self.factory.allowAnonymous and self._user == self.factory.userAnonymous:
            # anonymous login
            creds = credentials.Anonymous()
            reply = ftp.GUEST_LOGGED_IN_PROCEED
        else:
            # user login
            creds = credentials.UsernamePassword(self._user, password)
            reply = ftp.USR_LOGGED_IN_PROCEED

        def _cbLogin((interface, avatar, logout)):
            assert interface is ftp.IFTPShell, "The realm is busted, jerk."
            self.shell = avatar
            self.logout = logout
            self.workingDirectory = []
            self.state = self.AUTHED
            return reply

        def _ebLogin(failure):
            failure.trap(credError.UnauthorizedLogin, credError.UnhandledCredentials)
            self.state = self.UNAUTH
            raise ftp.AuthorizationError

        d = self.portal.login(creds, None, ftp.IFTPShell)
        d.addCallbacks(_cbLogin, _ebLogin)
        return d
コード例 #5
0
    def process_change(self, payload, user, repo, repo_url, project, request):
        """
        Consumes the JSON as a python object and actually starts the build.

        :arguments:
            payload
                Python Object that represents the JSON sent by GitHub Service
                Hook.
        """
        changes = None
        branch = '/'.join(payload['ref'].split('/')[2:])

        if payload['deleted'] is True:
            logging.info("Branch %r deleted, ignoring", branch)
        elif branch != 'master':
            logging.info("Branch %r not master, ignoring", branch)
        else:
            changes = []

            for change in payload['commits']:
                files = change['added'] + change['removed'] + change['modified']

                who = change['author']['email']
                if 'username' in change['author']:
                    who = "%s <%s>" % (change['author']['username'],
                                       change['author']['email'])

                changes.append({
                    'revision': change['id'],
                    'revlink': change['url'],
                    'who': who,
                    'comments': change['message'],
                    'repository': payload['repository']['url'],
                    'files': files,
                    'project': project,
                    'branch': branch
                })

        if not changes:
            logging.warning("No changes found")
            request.setResponseCode(OK)
            request.write(json.dumps({"result": "No changes found."}))
            request.finish()
            return

        host, port = self.master.split(':')
        port = int(port)

        if self.auth is not None:
            auth = credentials.UsernamePassword(*self.auth.split(":"))
        else:
            auth = credentials.Anonymous()

        factory = pb.PBClientFactory()
        deferred = factory.login(auth)
        reactor.connectTCP(host, port, factory)
        deferred.addErrback(self.connectFailed, request)
        deferred.addCallback(self.connected, changes, request)
コード例 #6
0
ファイル: test_strcred.py プロジェクト: emragins/tribal
 def testAnonymousAccessSucceeds(self):
     """
     Test that we can log in anonymously using this checker.
     """
     checker = strcred.makeChecker('anonymous')
     request = checker.requestAvatarId(credentials.Anonymous())
     def _gotAvatar(avatar):
         self.assertIdentical(checkers.ANONYMOUS, avatar)
     return request.addCallback(_gotAvatar)
コード例 #7
0
 def hello(self, service, username=None, password=None):
     """
     Client gretting.
     """
     creds = credentials.Anonymous()
     if username is not None:
         creds = credentials.UsernamePassword(username, password)
     authDeferred = self.portal.login(creds, None, IServiceFactory)
     authDeferred.addCallback(self.cbLogin, service)
     return authDeferred
コード例 #8
0
    def register(self, username, password):
        """Register user account on connected server."""
        def connectedAsAnonymousUser(avatar):
            """Register user account on server."""
            hash_ = sha1(password).hexdigest()
            d = avatar.callRemote('register', username, hash_)
            return d

        anon = credentials.Anonymous()
        d = self.factory.login(anon, client=None)
        d.addCallbacks(connectedAsAnonymousUser, self.errback)
        return d
コード例 #9
0
ファイル: guard.py プロジェクト: sajedel/testsage
 def requestAnonymousAuthentication(self, request, segments):
     """
     Anonymous authentication, the user can only see
     non-protected resources.
     """
     #log.msg("=== requestAnonymousAuthentication ===")
     def _success(avatar, request, segments):
         iface, resource, logout = avatar
         return resource, segments
     creds = credentials.Anonymous() #anonymous user.
     session, newCookie = self.sessionManager.createSession()
     session.set_authCreds(creds)
     mind = [newCookie, None, None]
     d = self.portal.login(creds, mind, self.credInterface)
     d.addCallback(_success, request, segments)
     return d
コード例 #10
0
ファイル: test_pb.py プロジェクト: kusoof/wprof
    def test_anonymousLoginNotPermitted(self):
        """
        Verify that without an anonymous checker set up, anonymous login is
        rejected.
        """
        self.portal.registerChecker(
            checkers.InMemoryUsernamePasswordDatabaseDontUse(user='******'))
        factory = pb.PBClientFactory()
        d = factory.login(credentials.Anonymous(), "BRAINS!")
        self.assertFailure(d, UnhandledCredentials)

        def cleanup(passthrough):
            self.flushLoggedErrors(UnhandledCredentials)
            factory.disconnect()
            return passthrough

        d.addBoth(cleanup)

        reactor.connectTCP('127.0.0.1', self.portno, factory)
        return d
コード例 #11
0
    def authenticate(self, request):
        """
        Attempt to authenticate the given request

        @param request: An L{IRequest} to be authenticated.
        """
        authHeader = request.headers.getHeader('authorization')

        if authHeader is None:
            return self.portal.login(credentials.Anonymous(), None,
                                     *self.interfaces).addCallbacks(
                                         self._loginSucceeded,
                                         self._loginFailed, (request, ), None,
                                         (request, ), None)

        elif authHeader[0] not in self.credentialFactories:
            return self._loginFailed(None, request)
        else:
            return self.login(self.credentialFactories[authHeader[0]],
                              authHeader[1], request)
コード例 #12
0
    def ftp_PASS(self, password):
        """
        Second part of login.  Get the password the peer wants to
        authenticate with.
        """
        if self.factory.allowAnonymous and self._user == self.factory.userAnonymous:
            # anonymous login
            creds = credentials.Anonymous()
            reply = GUEST_LOGGED_IN_PROCEED
        else:
            # user login
            creds = credentials.UsernamePassword(self._user, password)
            reply = USR_LOGGED_IN_PROCEED

        if self.transport.factory.canaryservice.maskpassword:
            logdata = {'USERNAME': self._user, 'PASSWORD': "******"}
        else:
            logdata = {'USERNAME': self._user, 'PASSWORD': password}

        self.factory.canaryservice.log(logdata, transport=self.transport)

        del self._user

        def _cbLogin((interface, avatar, logout)):
            assert interface is IFTPShell, "The realm is busted, jerk."
            self.shell = avatar
            self.logout = logout
            self.workingDirectory = []
            self.state = self.AUTHED
            return reply

        def _ebLogin(failure):
            failure.trap(cred_error.UnauthorizedLogin,
                         cred_error.UnhandledCredentials)
            self.state = self.UNAUTH
            raise AuthorizationError

        d = self.portal.login(creds, None, IFTPShell)
        d.addCallbacks(_cbLogin, _ebLogin)
        return d
コード例 #13
0
    def send_changes(self, changes, request):
        """
        Submit the changes, if any
        """
        if not changes:
            logging.warning("No changes found")
            request.setResponseCode(OK)
            request.write(json.dumps({"result": "No changes found."}))
            request.finish()
            return

        host, port = self.master.split(':')
        port = int(port)

        if self.auth is not None:
            auth = credentials.UsernamePassword(*self.auth.split(":"))
        else:
            auth = credentials.Anonymous()

        factory = pb.PBClientFactory()
        deferred = factory.login(auth)
        reactor.connectTCP(host, port, factory)
        deferred.addErrback(self.connectFailed, request)
        deferred.addCallback(self.connected, changes, request)
コード例 #14
0
 def connect(self, ip):
     factory = pb.PBClientFactory()
     reactor.connectTCP(ip, 8800, factory)
     d = factory.login(credentials.Anonymous())
     d.addCallback(self.connected)