summaryrefslogtreecommitdiff
path: root/py/demo/Glacier2/callback/SessionServer.py
blob: f4e79c5ebe2cf729cd3b751107c05f8473bf4982 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/usr/bin/env python
# **********************************************************************
#
# Copyright (c) 2003-2008 ZeroC, Inc. All rights reserved.
#
# This copy of Ice is licensed to you under the terms described in the
# ICE_LICENSE file included in this distribution.
#
# **********************************************************************

import sys, traceback, Ice, Glacier2

class DummyPermissionsVerifierI(Glacier2.PermissionsVerifier):
    def checkPermissions(self, userId, password, current=None):
        print "verified user `" + userId + "' with password `" + password + "'"
        return (True, "")

class SessionI(Glacier2.Session):
    def __init__(self, userId):
        self.userId = userId

    def destroy(self, current=None):
        print "destroying session for user `" + self.userId + "'"
        current.adapter.remove(current.id)

class SessionManagerI(Glacier2.SessionManager):
    def create(self, userId, control, current=None):
        print "creating session for user `" + userId + "'"
        session = SessionI(userId)
        return Glacier2.SessionPrx.uncheckedCast(current.adapter.addWithUUID(session))

class SessionServer(Ice.Application):
    def run(self, args):
        if len(args) > 1:
            print self.appName() + ": too many arguments"
            return 1

        adapter = self.communicator().createObjectAdapter("SessionServer")
        adapter.add(DummyPermissionsVerifierI(), self.communicator().stringToIdentity("verifier"))
        adapter.add(SessionManagerI(), self.communicator().stringToIdentity("sessionmanager"))
        adapter.activate()
        self.communicator().waitForShutdown()
        return 0

app = SessionServer()
sys.exit(app.main(sys.argv, "config.sessionserver"))