source: fedd/federation/deter_impl.py @ 1819839

Last change on this file since 1819839 was 1819839, checked in by Ted Faber <faber@…>, 11 years ago

Works with null swapin. Check connectivity next

  • Property mode set to 100644
File size: 4.4 KB
Line 
1#!/usr/local/bin/python
2
3import sys
4
5import emulab_access
6import dragon_access
7import protogeni_access
8import deter_internal_access
9import benito_access
10import desktop_access
11import skeleton_access
12
13from experiment_control import experiment_control_local
14from ns2topdl import ns2topdl_local
15from util import read_simple_accessdb
16from deter import fedid
17
18from authorizer import authorizer, abac_authorizer
19
20class deter_impl:
21    """
22    The implementation of access control based on mapping users to projects.
23
24    Users can be mapped to existing projects or have projects created
25    dynamically.  This implements both direct requests and proxies.
26    """
27    # Used by the SOAP caller
28    soap_namespaces = ('http://www.isi.edu/fedd.wsdl',
29            'http://www.isi.edu/fedd_internal.wsdl')
30
31    def __init__(self, config=None):
32        """
33        Initializer.  Uses the parsed configuration to create appropriate
34        components.
35        """
36        self.soap_services = { }
37        self.xmlrpc_services = { }
38        self.auth = None
39
40        if config:
41            self.cert_file = config.get("globals", "cert_file");
42            self.cert_pwd = config.get("globals", "cert_pwd");
43            self.trusted_certs = config.get("globals", "trusted_certs");
44            self.access_type = config.get("globals", "access_type", "emulab")
45            self.auth_type = config.get("globals", "auth_type", "legacy")
46
47            for mp in config.get("globals", "module_path","").split(":"):
48                sys.path.append(mp)
49
50            if self.auth_type == 'legacy':
51                self.auth = authorizer()
52            elif self.auth_type == 'abac':
53                auth_url = config.get('globals', 'auth_url')
54                if not auth_url:
55                    raise RuntimeError("auth_url required for ABAC " + \
56                            "authorization")
57                if self.cert_file:
58                    me = fedid(file=self.cert_file)
59                else:
60                    raise RuntimeError("ABAC authorization needs a " +\
61                            "certificate file")
62                self.auth= abac_authorizer(url=auth_url, 
63                        cert_file=self.cert_file, cert_pwd=self.cert_pwd,
64                        trusted_certs=self.trusted_certs, me=me)
65            else:
66                raise RuntimeError("Unknown authorizer type %s" % \
67                        self.auth_type)
68
69            access_db = config.get("globals", "accessdb")
70
71            if access_db:
72                try:
73                    read_simple_accessdb(access_db, self.auth)
74                except EnvironmentError, e:
75                    raise RuntimeError(
76                            "Error reading accessDB %s: %s" % (access_db, e))
77                except ValueError, e:
78                    raise RuntimeError("%s" % e)
79
80            if config.has_section("access"):
81                if self.access_type == "emulab":
82                    self.access = emulab_access.access(config, self.auth)
83                elif self.access_type == "dragon":
84                    self.access = dragon_access.access(config, self.auth)
85                elif self.access_type == "protogeni":
86                    self.access = protogeni_access.access(config, self.auth)
87                elif self.access_type == "deter_internal":
88                    self.access = deter_internal_access.access(config,
89                            self.auth)
90                elif self.access_type == "benito":
91                    self.access = benito_access.access(config, self.auth)
92                elif self.access_type == "desktop":
93                    self.access = desktop_access.access(config, self.auth)
94                elif self.access_type == "skel":
95                    self.access = skeleton_access.access(config, self.auth)
96                else:
97                    try:
98                        exec 'from %s import access as plugin_access' \
99                                % self.access_type
100                        self.access = plugin_access(config, self.auth)
101                    except ImportError, e:
102                        raise RuntimeError(
103                                "Unknown access_type: %s (import failed: %s)" \
104                                        % (self.access_type, e))
105                self.soap_services.update(self.access.soap_services) 
106                self.xmlrpc_services.update(self.access.xmlrpc_services) 
107            else:
108                self.access = None
109
110            if config.has_section("experiment_control"):
111                self.experiment = \
112                        experiment_control_local(config, self.auth)
113                # Tell the experiment control where local access control is and
114                # what testbeds it pertains to.
115                if getattr(self, 'access', None):
116                    for t in self.access.testbed:
117                        self.experiment.local_access[t] = self.access
118
119                self.soap_services.update(self.experiment.soap_services) 
120                self.xmlrpc_services.update(self.experiment.xmlrpc_services) 
121                self.get_handler = self.experiment.get_handler
122            else:
123                if self.access and getattr(self.access, 'get_handler', None):
124                    self.get_handler = self.access.get_handler
125                else:
126                    self.get_handler = None
127
128            if config.has_section("ns2topdl"):
129                self.ns2topdl = ns2topdl_local(config, self.auth)
130                self.soap_services.update(self.ns2topdl.soap_services) 
131                self.xmlrpc_services.update(self.ns2topdl.xmlrpc_services) 
132
133def new_feddservice(config):
134    return deter_impl(config)
Note: See TracBrowser for help on using the repository browser.