浏览代码

auto dispatch auth config

Bastien Sevajol 9 年前
父节点
当前提交
224608eb7b

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

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

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

@@ -25,11 +25,14 @@ skip_authentication = True
25 25
 
26 26
 [app:ldap]
27 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 36
 use = config:development.ini
34 37
 
35 38
 # Add additional test specific configuration options as necessary.

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

@@ -1,2 +1,19 @@
1 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,7 +16,6 @@ convert them into boolean, for example, you should use the
16 16
 import tg
17 17
 from paste.deploy.converters import asbool
18 18
 
19
-from tg.configuration import AppConfig
20 19
 from tgext.pluggable import plug
21 20
 from tgext.pluggable import replace_template
22 21
 
@@ -24,13 +23,14 @@ from tg.i18n import lazy_ugettext as l_
24 23
 
25 24
 import tracim
26 25
 from tracim import model
26
+from tracim.config import TracimAppConfig
27 27
 from tracim.lib import app_globals, helpers
28 28
 from tracim.lib.auth.wrapper import AuthConfigWrapper
29 29
 from tracim.lib.base import logger
30 30
 from tracim.model.data import ActionDescription
31 31
 from tracim.model.data import ContentType
32 32
 
33
-base_config = AppConfig()
33
+base_config = TracimAppConfig()
34 34
 base_config.renderers = []
35 35
 base_config.use_toscawidgets = False
36 36
 base_config.use_toscawidgets2 = True
@@ -73,21 +73,6 @@ base_config['flash.template'] = '''
73 73
 # YOU MUST CHANGE THIS VALUE IN PRODUCTION TO SECURE YOUR APP 
74 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 76
 # INFO - This is the way to specialize the resetpassword email properties
92 77
 # plug(base_config, 'resetpassword', None, mail_subject=reset_password_email_subject)
93 78
 plug(base_config, 'resetpassword', 'reset_password')

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

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

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

@@ -4,6 +4,7 @@ from who_ldap import LDAPAttributesPlugin, LDAPGroupsPlugin
4 4
 from who_ldap import LDAPSearchAuthenticatorPlugin as BaseLDAPSearchAuthenticatorPlugin
5 5
 
6 6
 from tracim.lib.auth.base import Auth
7
+from tracim.lib.helpers import ini_conf_to_bool
7 8
 from tracim.lib.user import UserApi
8 9
 from tracim.model import auth, DBSession, User
9 10
 
@@ -44,7 +45,7 @@ class LDAPAuth(Auth):
44 45
             returned_id='login',
45 46
             # the LDAP attribute that holds the user name:
46 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 50
         auth_plug.set_auth(self)
50 51
         return auth_plug
@@ -58,7 +59,7 @@ class LDAPAuth(Auth):
58 59
             # map from LDAP attributes to TurboGears user attributes:
59 60
             attributes=self._config.get('ldap_user_attributes', 'mail=email'),
60 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 65
     def _get_ldap_groups_provider(self):
@@ -69,7 +70,7 @@ class LDAPAuth(Auth):
69 70
             bind_pass=self._config.get('ldap_bind_pass'),
70 71
             filterstr=self._config.get('ldap_group_filter', '(&(objectClass=group)(member=%(dn)s))'),
71 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,3 +198,15 @@ def shorten(text: str, maxlength: int, add_three_points=True) -> str:
198 198
             result += '…'
199 199
 
200 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)