Browse Source

auths: use config as a dict

Bastien Sevajol 9 years ago
parent
commit
1a0e9a768e

+ 6 - 6
tracim/tracim/config/__init__.py View File

1
 # -*- coding: utf-8 -*-
1
 # -*- coding: utf-8 -*-
2
-from tg import AppConfig, config
2
+from tg import AppConfig
3
 
3
 
4
 from tracim.lib.auth.wrapper import AuthConfigWrapper
4
 from tracim.lib.auth.wrapper import AuthConfigWrapper
5
 
5
 
10
     """
10
     """
11
 
11
 
12
     def after_init_config(self, conf):
12
     def after_init_config(self, conf):
13
-        self._set_up_auth()
14
-        # Fix an tg2 strange thing: auth_backend is set in config, but instance
13
+        self._set_up_auth(conf)
14
+        #  Fix an tg2 strange thing: auth_backend is set in config, but instance
15
         #  of AppConfig has None in auth_backend attr
15
         #  of AppConfig has None in auth_backend attr
16
-        self.auth_backend = config.auth_backend
16
+        self.auth_backend = conf['auth_backend']
17
 
17
 
18
-    def _set_up_auth(self, ):
19
-        AuthConfigWrapper.wrap(config)
18
+    def _set_up_auth(self, conf):
19
+        AuthConfigWrapper.wrap(conf)

+ 3 - 3
tracim/tracim/lib/auth/base.py View File

11
     def wrap_config(self):
11
     def wrap_config(self):
12
         # override this if you would like to provide a different who plugin for
12
         # override this if you would like to provide a different who plugin for
13
         # managing login and logout of your application
13
         # managing login and logout of your application
14
-        self._config.sa_auth.form_plugin = None
14
+        self._config['sa_auth'].form_plugin = None
15
 
15
 
16
         # You may optionally define a page where you want users to be redirected to
16
         # You may optionally define a page where you want users to be redirected to
17
         # on login:
17
         # on login:
18
-        self._config.sa_auth.post_login_url = '/post_login'
18
+        self._config['sa_auth'].post_login_url = '/post_login'
19
 
19
 
20
         # You may optionally define a page where you want users to be redirected to
20
         # You may optionally define a page where you want users to be redirected to
21
         # on logout:
21
         # on logout:
22
-        self._config.sa_auth.post_logout_url = '/post_logout'
22
+        self._config['sa_auth'].post_logout_url = '/post_logout'

+ 4 - 4
tracim/tracim/lib/auth/internal.py View File

13
     def wrap_config(self):
13
     def wrap_config(self):
14
         super().wrap_config()
14
         super().wrap_config()
15
 
15
 
16
-        self._config.sa_auth.user_class = User
17
-        self._config.auth_backend = 'sqlalchemy'
18
-        self._config.sa_auth.dbsession = DBSession
19
-        self._config.sa_auth.authmetadata = InternalApplicationAuthMetadata(self._config.sa_auth)
16
+        self._config['sa_auth'].user_class = User
17
+        self._config['auth_backend'] = 'sqlalchemy'
18
+        self._config['sa_auth'].dbsession = DBSession
19
+        self._config['sa_auth'].authmetadata = InternalApplicationAuthMetadata(self._config.get('sa_auth'))
20
 
20
 
21
 
21
 
22
 class InternalApplicationAuthMetadata(TGAuthMetadata):
22
 class InternalApplicationAuthMetadata(TGAuthMetadata):

+ 4 - 4
tracim/tracim/lib/auth/ldap.py View File

26
 
26
 
27
     def wrap_config(self):
27
     def wrap_config(self):
28
         super().wrap_config()
28
         super().wrap_config()
29
-        self._config.auth_backend = 'ldapauth'
30
-        self._config.sa_auth.authenticators = [('ldapauth', self.ldap_auth)]
29
+        self._config['auth_backend'] = 'ldapauth'
30
+        self._config['sa_auth'].authenticators = [('ldapauth', self.ldap_auth)]
31
 
31
 
32
         mdproviders = [('ldapuser', self.ldap_user_provider)]
32
         mdproviders = [('ldapuser', self.ldap_user_provider)]
33
         if self._config.get('ldap_group_enabled', False):
33
         if self._config.get('ldap_group_enabled', False):
34
             mdproviders.append(('ldapgroups', self.ldap_groups_provider))
34
             mdproviders.append(('ldapgroups', self.ldap_groups_provider))
35
-        self._config.sa_auth.mdproviders = mdproviders
35
+        self._config['sa_auth'].mdproviders = mdproviders
36
 
36
 
37
-        self._config.sa_auth.authmetadata = LDAPApplicationAuthMetadata(self._config.sa_auth)
37
+        self._config['sa_auth'].authmetadata = LDAPApplicationAuthMetadata(self._config.get('sa_auth'))
38
 
38
 
39
     def _get_ldap_auth(self):
39
     def _get_ldap_auth(self):
40
         auth_plug = LDAPSearchAuthenticatorPlugin(
40
         auth_plug = LDAPSearchAuthenticatorPlugin(

+ 2 - 2
tracim/tracim/lib/auth/wrapper.py View File

21
         for wrapper_class in cls.AUTH_WRAPPERS:
21
         for wrapper_class in cls.AUTH_WRAPPERS:
22
             if wrapper_class.name is NotImplemented:
22
             if wrapper_class.name is NotImplemented:
23
                 raise Exception("\"name\" attribute of %s is required" % str(wrapper_class))
23
                 raise Exception("\"name\" attribute of %s is required" % str(wrapper_class))
24
-            if config.auth_type == wrapper_class.name:
24
+            if config.get('auth_type') == wrapper_class.name:
25
                 return wrapper_class
25
                 return wrapper_class
26
-        raise Exception("No auth config wrapper found for \"%s\" auth_type config" % config.auth_type)
26
+        raise Exception("No auth config wrapper found for \"%s\" auth_type config" % config.get('auth_type'))