source: TI05-delivery/trunk/lib/python/ndg/delivery/common/auth_plugin.py @ 1540

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/TI05-delivery/trunk/lib/python/ndg/delivery/common/auth_plugin.py@1540
Revision 1540, 2.5 KB checked in by spascoe, 13 years ago (diff)

Split the distribution into 3 eggs: server, client and common.

These eggs aren't quite built correctly because they all share a build
directory. To fix this I will split setup.py into 3 in the next commit.

Line 
1"""
2Sample authentication/authorisation plugin.
3
4@copyright Copyright (C) 2006 CCLRC & NERC
5@license This software may be distributed under the terms of the Q Public Licenc
6e, version 1.0 or later.
7
8@author Stephen Pascoe
9"""
10
11from ndg.delivery.common import auth
12import logging, os, stat
13
14
15
16NDG_HANDSHAKE = 'NDG-Delivery demo'
17logger = logging.getLogger('ndg.delivery.server')
18   
19
20
21#--------------------------------------------------------------------------------------------------------------
22# Server implementation
23
24class AuthHandler(auth.AuthHandler):
25
26    def authenticate(self):
27        msg = self.server.recv()
28        logger.debug('AuthContext received Auth message: %s' % msg)
29               
30        self.server.send(NDG_HANDSHAKE)
31
32        privatestr = self.server.recv()
33        logger.debug("AuthContext received privatestr: %s" % privatestr)
34       
35        return self.makeAuthzHandler(msg, "TestCaseUser")
36
37    def makeAuthzHandler(self, msg, user):
38        return AuthzHandler(self.server, msg, "TestCaseUser")
39
40class AuthzHandler(auth.AuthzHandler):
41    def __init__(self, serverConnector, version, username):
42        super(AuthzHandler, self).__init__(serverConnector)
43        self.username = username
44        self.version = version
45
46    def authzControl(self, msgcode, transferopt, path):
47        logger.debug('AuthzHandler.authzControl: msgcode = %s' % hex(msgcode))
48        return self.authzPath(path)
49
50    def authzRetr(self, path):
51        return self.authzPath(path)
52
53    def authzStore(self, path):
54        return self.authzPath(path)
55
56    def authzPath(self, path):
57        # For dir commands the path will end with '*'
58        if path[-2:] == '/*':
59            path = path[:-2]
60        if os.access(path, os.R_OK):
61            logger.debug('AuthzHandler OK')
62            return True
63        else:
64            logger.debug('AuthzHandler FAIL')
65            raise auth.AuthorisationFailure, "AuthzHandler: no read perms"
66
67
68#--------------------------------------------------------------------------------------------------------------
69# Client implementation
70
71class AuthClientHandler(auth.AuthClientHandler):
72    def __init__(self, clientConnector, privatestr="none"):
73        super(AuthClientHandler, self).__init__(clientConnector)
74        self.privatestr = privatestr
75
76    def authenticate(self):
77        self.client.send(NDG_HANDSHAKE)
78        resp = self.client.recv()
79
80        print "Received Auth handshake: %s" % resp
81
82        self.client.send(self.privatestr)
83
84        return True
Note: See TracBrowser for help on using the repository browser.