source: TI03-DataExtractor/branches/titania_install/pygss/ResourceAccess.py~ @ 1524

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/TI03-DataExtractor/branches/titania_install/pygss/ResourceAccess.py~@1610
Revision 1524, 1.8 KB checked in by astephen, 14 years ago (diff)

Titania installed version latest.

Line 
1#   Copyright (C) 2004 CCLRC & NERC( Natural Environment Research Council ).
2#   This software may be distributed under the terms of the
3#   Q Public License, version 1.0 or later. http://ndg.nerc.ac.uk/public_docs/QPublic_license.txt
4
5"""
6ResourceAccess.py
7=================
8
9ResourceAccess class works out if a user is allowed to access a particular
10resource URI (typically a file).
11
12"""
13
14# Import library modules
15import os, sys
16
17# Import package modules
18from serverConfig import *
19from common import overlap
20from GSErrors import *
21
22
23class ResourceAccess:
24    """
25    ResourceAccess class works out if a user is allowed to access a particular
26    resource URI (typically a file).
27    """
28     
29    def __init__(self, username, userRoles, resourceURI):
30        """
31        Sets up instance variables and runs checks.
32        """
33        uri=resourceURI
34        print uri
35        self.username=username
36        self.userRoles=userRoles
37        if uri.find("file://")>-1:
38            uri=uri.split("//")[0]
39 
40        if uri.find("//")<0:
41            self.status=self.checkAccess(uri)
42        else:
43            raise "Remote file and service-based access not yet implemented."
44           
45    def checkAccess(self, uri):
46        """
47        Returns 1 if user is allowed to see the file and 0 otherwise.
48        If cannot get to file then raises an error.
49        """
50        if not os.path.isfile(uri):
51            raise GSFileIOError, ("File '%s' does not exist." % uri)
52
53        if SECURITY_MODEL=="badc":
54            sys.path.append("/home/badc/software/pythonlib/badc")
55            import getPermissions
56            (allowedRoles, allowedUsers)=getPermissions.getPermissions(uri)
57            if self.username in allowedUsers or overlap(self.userRoles, allowedRoles):
58                return 1
59       
60        print allowedUsers, self.username, self.username in allowedUsers
61        return 0
Note: See TracBrowser for help on using the repository browser.