瀏覽代碼

auto dispatch auth config

Bastien Sevajol 9 年之前
父節點
當前提交
224608eb7b

+ 3 - 0
tracim/development.ini.base 查看文件

38
 beaker.session.key = tracim
38
 beaker.session.key = tracim
39
 beaker.session.secret = 3283411b-1904-4554-b0e1-883863b53080
39
 beaker.session.secret = 3283411b-1904-4554-b0e1-883863b53080
40
 
40
 
41
+# Auth type
42
+auth_type = internal
43
+
41
 #By default session is store in cookies to avoid the overhead
44
 #By default session is store in cookies to avoid the overhead
42
 #of having to manage a session storage. On production you might
45
 #of having to manage a session storage. On production you might
43
 #want to switch to a better session storage.
46
 #want to switch to a better session storage.

+ 8 - 5
tracim/test.ini 查看文件

25
 
25
 
26
 [app:ldap]
26
 [app:ldap]
27
 sqlalchemy.url = postgresql://postgres:dummy@127.0.0.1:5432/tracim_test?client_encoding=utf8
27
 sqlalchemy.url = postgresql://postgres:dummy@127.0.0.1:5432/tracim_test?client_encoding=utf8
28
-auth_type = 'ldap'
29
-ldap_url = 'ldaps://ad.my-company.org'
30
-ldap_base_dn = 'ou=users,dc=ad,dc=my-company,dc=com'
31
-ldap_bind_dn = 'cn=bind,cn=users,dc=ad,dc=my-company,dc=com'
32
-ldap_bind_pass = 'toor2'
28
+auth_type = ldap
29
+ldap_url = ldap://localhost:3333
30
+ldap_base_dn = dc=directory,dc=fsf,dc=org
31
+ldap_bind_dn = cn=admin,dc=directory,dc=fsf,dc=org
32
+ldap_bind_pass = toor
33
+ldap_ldap_naming_attribute = uid
34
+ldap_user_attributes = mail=email
35
+ldap_tls = False
33
 use = config:development.ini
36
 use = config:development.ini
34
 
37
 
35
 # Add additional test specific configuration options as necessary.
38
 # Add additional test specific configuration options as necessary.

+ 17 - 0
tracim/tracim/config/__init__.py 查看文件

1
 # -*- coding: utf-8 -*-
1
 # -*- coding: utf-8 -*-
2
+from tg import AppConfig, config
2
 
3
 
4
+from tracim.lib.auth.wrapper import AuthConfigWrapper
5
+
6
+
7
+class TracimAppConfig(AppConfig):
8
+    """
9
+    Tracim specific config processes.
10
+    """
11
+
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
15
+        #  of AppConfig has None in auth_backend attr
16
+        self.auth_backend = config.auth_backend
17
+
18
+    def _set_up_auth(self, ):
19
+        AuthConfigWrapper.wrap(config)

+ 2 - 17
tracim/tracim/config/app_cfg.py 查看文件

16
 import tg
16
 import tg
17
 from paste.deploy.converters import asbool
17
 from paste.deploy.converters import asbool
18
 
18
 
19
-from tg.configuration import AppConfig
20
 from tgext.pluggable import plug
19
 from tgext.pluggable import plug
21
 from tgext.pluggable import replace_template
20
 from tgext.pluggable import replace_template
22
 
21
 
24
 
23
 
25
 import tracim
24
 import tracim
26
 from tracim import model
25
 from tracim import model
26
+from tracim.config import TracimAppConfig
27
 from tracim.lib import app_globals, helpers
27
 from tracim.lib import app_globals, helpers
28
 from tracim.lib.auth.wrapper import AuthConfigWrapper
28
 from tracim.lib.auth.wrapper import AuthConfigWrapper
29
 from tracim.lib.base import logger
29
 from tracim.lib.base import logger
30
 from tracim.model.data import ActionDescription
30
 from tracim.model.data import ActionDescription
31
 from tracim.model.data import ContentType
31
 from tracim.model.data import ContentType
32
 
32
 
33
-base_config = AppConfig()
33
+base_config = TracimAppConfig()
34
 base_config.renderers = []
34
 base_config.renderers = []
35
 base_config.use_toscawidgets = False
35
 base_config.use_toscawidgets = False
36
 base_config.use_toscawidgets2 = True
36
 base_config.use_toscawidgets2 = True
73
 # YOU MUST CHANGE THIS VALUE IN PRODUCTION TO SECURE YOUR APP 
73
 # YOU MUST CHANGE THIS VALUE IN PRODUCTION TO SECURE YOUR APP 
74
 base_config.sa_auth.cookie_secret = "3283411b-1904-4554-b0e1-883863b53080"
74
 base_config.sa_auth.cookie_secret = "3283411b-1904-4554-b0e1-883863b53080"
75
 
75
 
76
-base_config.auth_type = 'ldap'
77
-
78
-# ldap_base_dn = 'ou=users,dc=ad,dc=snake-oil-company,dc=com'
79
-# ldap_bind_dn = 'cn=bind,cn=users,dc=ad,dc=snake-oil-company,dc=com'
80
-
81
-base_config.ldap_url = 'ldap://localhost:3333'
82
-base_config.ldap_base_dn = 'dc=directory,dc=fsf,dc=org'
83
-base_config.ldap_bind_dn = 'cn=admin,dc=directory,dc=fsf,dc=org'
84
-base_config.ldap_bind_pass = 'toor'
85
-base_config.ldap_ldap_naming_attribute = 'uid'
86
-base_config.ldap_user_attributes = 'mail=email'
87
-base_config.ldap_tls = False
88
-
89
-AuthConfigWrapper.wrap(base_config)
90
-
91
 # INFO - This is the way to specialize the resetpassword email properties
76
 # INFO - This is the way to specialize the resetpassword email properties
92
 # plug(base_config, 'resetpassword', None, mail_subject=reset_password_email_subject)
77
 # plug(base_config, 'resetpassword', None, mail_subject=reset_password_email_subject)
93
 plug(base_config, 'resetpassword', 'reset_password')
78
 plug(base_config, 'resetpassword', 'reset_password')

+ 1 - 0
tracim/tracim/config/deployment.ini_tmpl 查看文件

27
 beaker.session.key = pod
27
 beaker.session.key = pod
28
 beaker.session.secret = ${app_instance_secret}
28
 beaker.session.secret = ${app_instance_secret}
29
 app_instance_uuid = ${app_instance_uuid}
29
 app_instance_uuid = ${app_instance_uuid}
30
+auth_type = internal
30
 
31
 
31
 # If you'd like to fine-tune the individual locations of the cache data dirs
32
 # If you'd like to fine-tune the individual locations of the cache data dirs
32
 # for the Cache data, or the Session saves, un-comment the desired settings
33
 # for the Cache data, or the Session saves, un-comment the desired settings

+ 4 - 3
tracim/tracim/lib/auth/ldap.py 查看文件

4
 from who_ldap import LDAPSearchAuthenticatorPlugin as BaseLDAPSearchAuthenticatorPlugin
4
 from who_ldap import LDAPSearchAuthenticatorPlugin as BaseLDAPSearchAuthenticatorPlugin
5
 
5
 
6
 from tracim.lib.auth.base import Auth
6
 from tracim.lib.auth.base import Auth
7
+from tracim.lib.helpers import ini_conf_to_bool
7
 from tracim.lib.user import UserApi
8
 from tracim.lib.user import UserApi
8
 from tracim.model import auth, DBSession, User
9
 from tracim.model import auth, DBSession, User
9
 
10
 
44
             returned_id='login',
45
             returned_id='login',
45
             # the LDAP attribute that holds the user name:
46
             # the LDAP attribute that holds the user name:
46
             naming_attribute=self._config.get('ldap_naming_attribute'),
47
             naming_attribute=self._config.get('ldap_naming_attribute'),
47
-            start_tls=self._config.get('ldap_tls', False),
48
+            start_tls=ini_conf_to_bool(self._config.get('ldap_tls', False)),
48
         )
49
         )
49
         auth_plug.set_auth(self)
50
         auth_plug.set_auth(self)
50
         return auth_plug
51
         return auth_plug
58
             # map from LDAP attributes to TurboGears user attributes:
59
             # map from LDAP attributes to TurboGears user attributes:
59
             attributes=self._config.get('ldap_user_attributes', 'mail=email'),
60
             attributes=self._config.get('ldap_user_attributes', 'mail=email'),
60
             flatten=True,
61
             flatten=True,
61
-            start_tls=self._config.get('ldap_tls', False)
62
+            start_tls=ini_conf_to_bool(self._config.get('ldap_tls', False)),
62
         )
63
         )
63
 
64
 
64
     def _get_ldap_groups_provider(self):
65
     def _get_ldap_groups_provider(self):
69
             bind_pass=self._config.get('ldap_bind_pass'),
70
             bind_pass=self._config.get('ldap_bind_pass'),
70
             filterstr=self._config.get('ldap_group_filter', '(&(objectClass=group)(member=%(dn)s))'),
71
             filterstr=self._config.get('ldap_group_filter', '(&(objectClass=group)(member=%(dn)s))'),
71
             name='groups',
72
             name='groups',
72
-            start_tls=self._config.get('ldap_tls', False)
73
+            start_tls=ini_conf_to_bool(self._config.get('ldap_tls', False)),
73
         )
74
         )
74
 
75
 
75
 
76
 

+ 12 - 0
tracim/tracim/lib/helpers.py 查看文件

198
             result += '…'
198
             result += '…'
199
 
199
 
200
     return result
200
     return result
201
+
202
+
203
+def ini_conf_to_bool(value):
204
+    """
205
+    Depending INI file interpreter, False values are simple parsed as string,
206
+    so use this function to consider them as boolean
207
+    :param value: value of ini parameter
208
+    :return: bollean value
209
+    """
210
+    if value in ('False', 'false', '0', 'off', 'no'):
211
+        return False
212
+    return bool(value)