source: fedd/federation/deter_impl.py @ 25930db

compt_changes
Last change on this file since 25930db was 25930db, checked in by Ted Faber <faber@…>, 12 years ago

Whoops. Needs to be elif

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