Exemplo n.º 1
0
def _fixed_cbLogin(self, xxx_todo_changeme):
    """
    Ensure that the avatar to be returned to the client is jellyable and
    set up disconnection notification to call the realm's logout object.
    """
    (interface, avatar, logout) = xxx_todo_changeme
    if not IJellyable.providedBy(avatar):
        avatar = pb.AsReferenceable(avatar, "perspective")

    puid = avatar.processUniqueID()

    # only call logout once, whether the connection is dropped (disconnect)
    # or a logout occurs (cleanup), and be careful to drop the reference to
    # it in either case
    logout = [logout]

    def maybeLogout():
        if not logout:
            return
        fn = logout[0]
        del logout[0]
        fn()
    self.broker._localCleanup[puid] = maybeLogout
    self.broker.notifyOnDisconnect(maybeLogout)

    return avatar
Exemplo n.º 2
0
 def getStateToCacheAndObserveFor(self, perspective, observer):
     self.observers.append(observer)
     state = self.__dict__.copy()
     for key in ("observers", "secured", "wall_pic", "ground_pic"):
         del state[key]
     state["local"] = False
     state["remote_ref"] = pb.AsReferenceable(self)
     return state
Exemplo n.º 3
0
 def loginResponse(result):
     self.log("loginResponse: result=%r", result)
     # if the result is a keycard, we're not yet ready
     if isinstance(result, keycards.Keycard):
         return result
     else:
         # authenticated, so the result is the tuple
         interface, perspective, logout = result
         self.broker.notifyOnDisconnect(logout)
         return pb.AsReferenceable(perspective, "perspective")
Exemplo n.º 4
0
class _PortalWrapper(Referenceable):
    """Root Referenceable object, used to login to portal."""
    def __init__(self, portal, broker):
        self.portal = portal
        self.broker = broker

    # Have to return two rhings
    def remote_login(self, creds, mind):
        """Start of username/password login."""

        username = creds['username']
        password = creds['password']
        self.mUPCred = credentials.UsernamePassword(username, password)

        if 'win32' == sys.platform:
            domain = creds['domain']
            import winchecker
            self.mWindowsCred = winchecker.WindowsUsernamePassword(
                username, password, domain)
            d = self.portal.login(self.mWindowsCred, mind, pb.IPerspective)
        else:
            import pamchecker
            conv = pamchecker.makeConv({1: password, 2: username, 3: ''})
            self.mPAMCred = credentials.PluggableAuthenticationModules(
                username, conv)
            d = self.portal.login(self.mPAMCred, mind, pb.IPerspective)

        d.addCallback(self._loggedIn, creds)
        #.addErrback(self.tryNext, mind)
        return d

    def tryNext(self, oldDeffered, mind):
        d = self.portal.login(self.mUPCred, mind, pb.IPerspective)
        d.addCallback(self._loggedIn)
        return d

    def _loggedIn(self, (interface, perspective, logout), creds):
        logging.getLogger('maestrod._PortalWrapper').info("Log-in successful.")
        perspective.setCredentials(creds)
        if not IJellyable.providedBy(perspective):
            perspective = pb.AsReferenceable(perspective, "perspective")
        self.broker.notifyOnDisconnect(logout)
        return perspective
Exemplo n.º 5
0
 def prepareAvatar(self, avatar):
     self.mBroker.notifyOnDisconnect(avatar.logout)
     if not IJellyable.providedBy(avatar):
         avatar = pb.AsReferenceable(avatar, "perspective")
     return avatar
Exemplo n.º 6
0
 def getStateToCacheAndObserveFor(self, perspective, observer):
     self.observers.append(observer)
     state = self.get_state()
     state["remote_ref"] = pb.AsReferenceable(self)
     return state
Exemplo n.º 7
0
def patch():
    log.msg("Applying patch for http://twistedmatrix.com/trac/ticket/5079")
    if not hasattr(pb, '_JellyableAvatarMixin'):
        log.msg("..patch not applicable; please file a bug at buildbot.net")
    else:
        pb._JellyableAvatarMixin._cbLogin = _fixed_cbLogin


def _fixed_cbLogin(self, (interface, avatar, logout)):
    """
    Ensure that the avatar to be returned to the client is jellyable and
    set up disconnection notification to call the realm's logout object.
    """
    if not IJellyable.providedBy(avatar):
        avatar = pb.AsReferenceable(avatar, "perspective")

    puid = avatar.processUniqueID()

    # only call logout once, whether the connection is dropped (disconnect)
    # or a logout occurs (cleanup), and be careful to drop the reference to
    # it in either case
    logout = [logout]

    def maybeLogout():
        if not logout: return
        fn = logout[0]
        del logout[0]
        fn()

    self.broker._localCleanup[puid] = maybeLogout