Mercurial > moin > 1.9
changeset 4041:4a994a297ba3
replace cfg.user_autocreate setting by autocreate=<boolean> parameter of auth objects
author | Thomas Waldmann <tw AT waldmann-edv DOT de> |
---|---|
date | Sat, 30 Aug 2008 22:39:52 +0200 |
parents | 92c5fb24d88c |
children | 0f1886933f80 |
files | MoinMoin/auth/_tests/test_auth.py MoinMoin/auth/_tests/test_ldap_login.py MoinMoin/auth/http.py MoinMoin/auth/interwiki.py MoinMoin/auth/ldap_login.py MoinMoin/auth/php_session.py MoinMoin/auth/sslclientcert.py MoinMoin/config/multiconfig.py MoinMoin/user.py docs/CHANGES |
diffstat | 10 files changed, 30 insertions(+), 22 deletions(-) [+] |
line wrap: on
line diff
--- a/MoinMoin/auth/_tests/test_auth.py Sat Aug 30 21:27:30 2008 +0200 +++ b/MoinMoin/auth/_tests/test_auth.py Sat Aug 30 22:39:52 2008 +0200 @@ -156,8 +156,7 @@ class TestHttpAuthSession(AuthTest): class Config(wikiconfig.Config): from MoinMoin.auth.http import HTTPAuth - auth = [HTTPAuth()] - user_autocreate = True + auth = [HTTPAuth(autocreate=True)] def testHttpAuthSession(self): """ run some requests with http auth, check whether session works """
--- a/MoinMoin/auth/_tests/test_ldap_login.py Sat Aug 30 21:27:30 2008 +0200 +++ b/MoinMoin/auth/_tests/test_ldap_login.py Sat Aug 30 22:39:52 2008 +0200 @@ -51,9 +51,8 @@ from MoinMoin.auth.ldap_login import LDAPAuth server_uri = self.ldap_env.slapd.url # XXX no self base_dn = self.ldap_env.basedn - ldap_auth1 = LDAPAuth(server_uri=server_uri, base_dn=base_dn) + ldap_auth1 = LDAPAuth(server_uri=server_uri, base_dn=base_dn, autocreate=True) auth = [ldap_auth1, ] - user_autocreate = True def testMoinLDAPLogin(self): """ Just try accessing the LDAP server and see if usera and userb are in LDAP. """ @@ -95,10 +94,9 @@ from MoinMoin.auth import MoinAuth server_uri = self.ldap_env.slapd.url # XXX no self base_dn = self.ldap_env.basedn - ldap_auth = LDAPAuth(server_uri=server_uri, base_dn=base_dn) + ldap_auth = LDAPAuth(server_uri=server_uri, base_dn=base_dn, autocreate=True) moin_auth = MoinAuth() auth = [ldap_auth, moin_auth] - user_autocreate = True def teardown_class(self): """ Stop slapd, remove LDAP server environment """ @@ -191,10 +189,10 @@ server_uri = ldap_env.slapd.url base_dn = ldap_env.basedn ldap_auth = LDAPAuth(server_uri=server_uri, base_dn=base_dn, + autocreate=True, timeout=1) # short timeout, faster testing authlist.append(ldap_auth) auth = authlist - user_autocreate = True def setup_class(self): """ Create LDAP servers environment, start slapds """
--- a/MoinMoin/auth/http.py Sat Aug 30 21:27:30 2008 +0200 +++ b/MoinMoin/auth/http.py Sat Aug 30 22:39:52 2008 +0200 @@ -22,6 +22,10 @@ """ authenticate via http basic/digest/ntlm auth """ name = 'http' + def __init__(self, autocreate=False): + self.autocreate = autocreate + BaseAuth.__init__(self) + def request(self, request, user_obj, **kw): u = None _ = request.getText @@ -72,7 +76,7 @@ u = user.User(request, auth_username=username, auth_method=self.name, auth_attribs=('name', 'password')) - if u: + if u and self.autocreate: u.create_or_update() if u and u.valid: return u, True # True to get other methods called, too
--- a/MoinMoin/auth/interwiki.py Sat Aug 30 21:27:30 2008 +0200 +++ b/MoinMoin/auth/interwiki.py Sat Aug 30 22:39:52 2008 +0200 @@ -20,9 +20,10 @@ logout_possible = True login_inputs = ['username', 'password'] - def __init__(self, trusted_wikis): + def __init__(self, trusted_wikis, autocreate=False): BaseAuth.__init__(self) self.trusted_wikis = trusted_wikis + self.autocreate = autocreate def login(self, request, user_obj, **kw): username = kw.get('username') @@ -68,7 +69,8 @@ if key not in request.cfg.user_transient_fields: setattr(u, key, value) u.valid = True - u.create_or_update(True) + if self.autocreate: + u.create_or_update(True) logging.debug("successful interwiki auth for %r" % name) return ContinueLogin(u)
--- a/MoinMoin/auth/ldap_login.py Sat Aug 30 21:27:30 2008 +0200 +++ b/MoinMoin/auth/ldap_login.py Sat Aug 30 22:39:52 2008 +0200 @@ -81,6 +81,7 @@ tls_keyfile='', tls_require_cert=0, # 0 == ldap.OPT_X_TLS_NEVER (needed for self-signed certs) bind_once=False, # set to True to only do one bind - useful if configured to bind as the user on the first attempt + autocreate=False, # set to True if you want to autocreate user profiles ): self.server_uri = server_uri self.bind_dn = bind_dn @@ -107,7 +108,7 @@ self.tls_require_cert = tls_require_cert self.bind_once = bind_once - + self.autocreate = autocreate def login(self, request, user_obj, **kw): username = kw.get('username') @@ -231,7 +232,7 @@ logging.debug("invalid credentials (wrong password?) for dn %r (username: %r)" % (dn, username)) return CancelLogin(_("Invalid username or password.")) - if u: + if u and self.autocreate: u.create_or_update(True) return ContinueLogin(u)
--- a/MoinMoin/auth/php_session.py Sat Aug 30 21:27:30 2008 +0200 +++ b/MoinMoin/auth/php_session.py Sat Aug 30 22:39:52 2008 +0200 @@ -21,7 +21,7 @@ name = 'php_session' - def __init__(self, apps=['egw'], s_path="/tmp", s_prefix="sess_"): + def __init__(self, apps=['egw'], s_path="/tmp", s_prefix="sess_", autocreate=False): """ @param apps: A list of the enabled applications. See above for possible keys. @param s_path: The path where the PHP sessions are stored. @@ -31,6 +31,7 @@ self.s_path = s_path self.s_prefix = s_prefix self.apps = apps + self.autocreate = autocreate def request(self, request, user_obj, **kw): def handle_egroupware(session): @@ -72,7 +73,7 @@ u.email = email changed = True - if u: + if u and self.autocreate: u.create_or_update(changed) if u and u.valid: return u, True # True to get other methods called, too
--- a/MoinMoin/auth/sslclientcert.py Sat Aug 30 21:27:30 2008 +0200 +++ b/MoinMoin/auth/sslclientcert.py Sat Aug 30 22:39:52 2008 +0200 @@ -21,13 +21,15 @@ def __init__(self, authorities=None, email_key=True, name_key=True, - use_email=False, use_name=False): + use_email=False, use_name=False, + autocreate=False): self.use_email = use_email self.authorities = authorities self.email_key = email_key self.name_key = name_key self.use_email = use_email self.use_name = use_name + self.autocreate = autocreate BaseAuth.__init__(self) def request(self, request, user_obj, **kw): @@ -87,7 +89,7 @@ elif user_obj and user_obj.auth_method == self.name: user_obj.valid = False return user_obj, False - if u: + if u and self.autocreate: u.create_or_update(changed) if u and u.valid: return u, True
--- a/MoinMoin/config/multiconfig.py Sat Aug 30 21:27:30 2008 +0200 +++ b/MoinMoin/config/multiconfig.py Sat Aug 30 22:39:52 2008 +0200 @@ -1080,8 +1080,6 @@ )), 'user': ('Users / User settings', None, ( - ('autocreate', False, - "if True, user accounts are created automatically (see HelpOnAuthentication)."), ('email_unique', True, "if True, check email addresses for uniqueness and don't accept duplicates."), ('jid_unique', True,
--- a/MoinMoin/user.py Sat Aug 30 21:27:30 2008 +0200 +++ b/MoinMoin/user.py Sat Aug 30 22:39:52 2008 +0200 @@ -300,7 +300,7 @@ if name: self.name = name - elif auth_username: # this is needed for user_autocreate + elif auth_username: # this is needed for user autocreate self.name = auth_username # create checkbox fields (with default 0) @@ -379,9 +379,8 @@ @param changed: bool, set this to True if you updated the user profile values """ - if self._cfg.user_autocreate: - if not self.valid and not self.disabled or changed: # do we need to save/update? - self.save() # yes, create/update user profile + if not self.valid and not self.disabled or changed: # do we need to save/update? + self.save() # yes, create/update user profile def __filename(self): """ Get filename of the user's file on disk
--- a/docs/CHANGES Sat Aug 30 21:27:30 2008 +0200 +++ b/docs/CHANGES Sat Aug 30 22:39:52 2008 +0200 @@ -83,6 +83,10 @@ * @EMAIL@ expands to a MailTo macro call with the obfuscated email address of the current user. + Other Changes: + * user_autocreate setting was removed from wiki configuration and replaced + by a autocreate=<boolean> parameter of the auth objects that support user + profile auto creation. Version 1.7.1: New features: