annotate MoinMoin/auth/interwiki.py @ 3426:79dd730d6455

common.css: added yellow and orange as background color
author Reimar Bauer <rb.proj AT googlemail DOT com>
date Sat, 29 Mar 2008 13:07:53 +0100
parents 8a1f1a9dd37f
children 9a3deab96cb7
rev   line source
776
ab9cd47eb066 teared auth code into single files, basic built-in moin_login method and also session handling code is still in auth/__init__.py
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1 # -*- coding: iso-8859-1 -*-
ab9cd47eb066 teared auth code into single files, basic built-in moin_login method and also session handling code is still in auth/__init__.py
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
2 """
ab9cd47eb066 teared auth code into single files, basic built-in moin_login method and also session handling code is still in auth/__init__.py
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
3 MoinMoin - authentication using a remote wiki
ab9cd47eb066 teared auth code into single files, basic built-in moin_login method and also session handling code is still in auth/__init__.py
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
4
1951
a05a3b447db5 interwiki auth fixed, added getUserData xmlrpc method
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1832
diff changeset
5 @copyright: 2005 by Florian Festi,
3125
40c4670c3410 refactored auth package to use own logger
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2728
diff changeset
6 2007-2008 by MoinMoin:ThomasWaldmann
776
ab9cd47eb066 teared auth code into single files, basic built-in moin_login method and also session handling code is still in auth/__init__.py
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
7 @license: GNU GPL, see COPYING for details.
ab9cd47eb066 teared auth code into single files, basic built-in moin_login method and also session handling code is still in auth/__init__.py
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
8 """
1953
97626bb218f4 interwiki auth: fixes and docs
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1951
diff changeset
9
97626bb218f4 interwiki auth: fixes and docs
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1951
diff changeset
10 verbose = False
97626bb218f4 interwiki auth: fixes and docs
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1951
diff changeset
11
776
ab9cd47eb066 teared auth code into single files, basic built-in moin_login method and also session handling code is still in auth/__init__.py
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
12 import xmlrpclib
3125
40c4670c3410 refactored auth package to use own logger
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2728
diff changeset
13
40c4670c3410 refactored auth package to use own logger
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2728
diff changeset
14 from MoinMoin import log
40c4670c3410 refactored auth package to use own logger
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2728
diff changeset
15 logging = log.getLogger(__name__)
40c4670c3410 refactored auth package to use own logger
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2728
diff changeset
16
3211
8a1f1a9dd37f fix. misc problems found by pydev (unused/double imports, unused attributes, ...)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3125
diff changeset
17 from MoinMoin import wikiutil, user
2025
d919b7b7b3e9 auth framework: login() methods return an object now
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2009
diff changeset
18 from MoinMoin.auth import BaseAuth, ContinueLogin, CancelLogin
776
ab9cd47eb066 teared auth code into single files, basic built-in moin_login method and also session handling code is still in auth/__init__.py
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
19
2009
1b14cc05a54a refactor authentication and split out session handling
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 1953
diff changeset
20 class InterwikiAuth(BaseAuth):
1b14cc05a54a refactor authentication and split out session handling
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 1953
diff changeset
21 name = 'interwiki'
1b14cc05a54a refactor authentication and split out session handling
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 1953
diff changeset
22 logout_possible = True
1b14cc05a54a refactor authentication and split out session handling
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 1953
diff changeset
23 login_inputs = ['username', 'password']
776
ab9cd47eb066 teared auth code into single files, basic built-in moin_login method and also session handling code is still in auth/__init__.py
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
24
2009
1b14cc05a54a refactor authentication and split out session handling
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 1953
diff changeset
25 def __init__(self, trusted_wikis):
1b14cc05a54a refactor authentication and split out session handling
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 1953
diff changeset
26 BaseAuth.__init__(self)
1b14cc05a54a refactor authentication and split out session handling
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 1953
diff changeset
27 self.trusted_wikis = trusted_wikis
1b14cc05a54a refactor authentication and split out session handling
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 1953
diff changeset
28
1b14cc05a54a refactor authentication and split out session handling
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 1953
diff changeset
29 def login(self, request, user_obj, **kw):
1b14cc05a54a refactor authentication and split out session handling
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 1953
diff changeset
30 username = kw.get('username')
1b14cc05a54a refactor authentication and split out session handling
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 1953
diff changeset
31 password = kw.get('password')
1b14cc05a54a refactor authentication and split out session handling
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 1953
diff changeset
32
1b14cc05a54a refactor authentication and split out session handling
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 1953
diff changeset
33 if not username or not password:
2025
d919b7b7b3e9 auth framework: login() methods return an object now
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2009
diff changeset
34 return ContinueLogin(user_obj)
2009
1b14cc05a54a refactor authentication and split out session handling
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 1953
diff changeset
35
3125
40c4670c3410 refactored auth package to use own logger
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2728
diff changeset
36 if verbose: logging.info("trying to auth %r" % username)
2728
59b3d8b8971f remove (un)quoteName, new functions split_interwiki() and resolve_interwiki(), cleanup interwiki mess, fix some link markup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2181
diff changeset
37 wikiname, username = username.split(' ', 1) # XXX Hack because ':' is not allowed in name field
59b3d8b8971f remove (un)quoteName, new functions split_interwiki() and resolve_interwiki(), cleanup interwiki mess, fix some link markup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2181
diff changeset
38 wikitag, wikiurl, name, err = wikiutil.resolve_interwiki(request, wikiname, username)
776
ab9cd47eb066 teared auth code into single files, basic built-in moin_login method and also session handling code is still in auth/__init__.py
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
39
3125
40c4670c3410 refactored auth package to use own logger
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2728
diff changeset
40 if verbose: logging.info("resolve wiki returned: %r %r %r %r" % (wikitag, wikiurl, name, err))
2009
1b14cc05a54a refactor authentication and split out session handling
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 1953
diff changeset
41 if err or wikitag not in self.trusted_wikis:
2025
d919b7b7b3e9 auth framework: login() methods return an object now
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2009
diff changeset
42 return ContinueLogin(user_obj)
948
28ea5b3802b1 whitespace-only cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 776
diff changeset
43
2181
340ae0e7529e replace xmlrpc getUser by getUserProfile, auth can be done by getAuthToken/applyAuthToken in the same multicall, use for interwiki auth
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2025
diff changeset
44 homewiki = xmlrpclib.ServerProxy(wikiurl + "?action=xmlrpc2")
340ae0e7529e replace xmlrpc getUser by getUserProfile, auth can be done by getAuthToken/applyAuthToken in the same multicall, use for interwiki auth
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2025
diff changeset
45 auth_token = homewiki.getAuthToken(name, password)
340ae0e7529e replace xmlrpc getUser by getUserProfile, auth can be done by getAuthToken/applyAuthToken in the same multicall, use for interwiki auth
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2025
diff changeset
46 if not auth_token:
3125
40c4670c3410 refactored auth package to use own logger
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2728
diff changeset
47 if verbose: logging.info("%r wiki did not return an auth token." % wikitag)
2181
340ae0e7529e replace xmlrpc getUser by getUserProfile, auth can be done by getAuthToken/applyAuthToken in the same multicall, use for interwiki auth
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2025
diff changeset
48 return ContinueLogin(user_obj)
340ae0e7529e replace xmlrpc getUser by getUserProfile, auth can be done by getAuthToken/applyAuthToken in the same multicall, use for interwiki auth
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2025
diff changeset
49
3125
40c4670c3410 refactored auth package to use own logger
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2728
diff changeset
50 if verbose: logging.info("successfully got an auth token for %r. trying to get user profile data..." % name)
2181
340ae0e7529e replace xmlrpc getUser by getUserProfile, auth can be done by getAuthToken/applyAuthToken in the same multicall, use for interwiki auth
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2025
diff changeset
51
340ae0e7529e replace xmlrpc getUser by getUserProfile, auth can be done by getAuthToken/applyAuthToken in the same multicall, use for interwiki auth
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2025
diff changeset
52 mc = xmlrpclib.MultiCall(homewiki)
340ae0e7529e replace xmlrpc getUser by getUserProfile, auth can be done by getAuthToken/applyAuthToken in the same multicall, use for interwiki auth
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2025
diff changeset
53 mc.applyAuthToken(auth_token)
340ae0e7529e replace xmlrpc getUser by getUserProfile, auth can be done by getAuthToken/applyAuthToken in the same multicall, use for interwiki auth
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2025
diff changeset
54 mc.getUserProfile()
340ae0e7529e replace xmlrpc getUser by getUserProfile, auth can be done by getAuthToken/applyAuthToken in the same multicall, use for interwiki auth
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2025
diff changeset
55 result, account_data = mc()
340ae0e7529e replace xmlrpc getUser by getUserProfile, auth can be done by getAuthToken/applyAuthToken in the same multicall, use for interwiki auth
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2025
diff changeset
56
340ae0e7529e replace xmlrpc getUser by getUserProfile, auth can be done by getAuthToken/applyAuthToken in the same multicall, use for interwiki auth
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2025
diff changeset
57 if result != "SUCCESS":
3125
40c4670c3410 refactored auth package to use own logger
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2728
diff changeset
58 if verbose: logging.info("%r wiki did not accept auth token." % wikitag)
2181
340ae0e7529e replace xmlrpc getUser by getUserProfile, auth can be done by getAuthToken/applyAuthToken in the same multicall, use for interwiki auth
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2025
diff changeset
59 return ContinueLogin(None)
340ae0e7529e replace xmlrpc getUser by getUserProfile, auth can be done by getAuthToken/applyAuthToken in the same multicall, use for interwiki auth
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2025
diff changeset
60
340ae0e7529e replace xmlrpc getUser by getUserProfile, auth can be done by getAuthToken/applyAuthToken in the same multicall, use for interwiki auth
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2025
diff changeset
61 if not account_data:
3125
40c4670c3410 refactored auth package to use own logger
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2728
diff changeset
62 if verbose: logging.info("%r wiki did not return a user profile." % wikitag)
2181
340ae0e7529e replace xmlrpc getUser by getUserProfile, auth can be done by getAuthToken/applyAuthToken in the same multicall, use for interwiki auth
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2025
diff changeset
63 return ContinueLogin(None)
340ae0e7529e replace xmlrpc getUser by getUserProfile, auth can be done by getAuthToken/applyAuthToken in the same multicall, use for interwiki auth
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2025
diff changeset
64
3125
40c4670c3410 refactored auth package to use own logger
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2728
diff changeset
65 if verbose: logging.info("%r wiki returned a user profile." % wikitag)
948
28ea5b3802b1 whitespace-only cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 776
diff changeset
66
2009
1b14cc05a54a refactor authentication and split out session handling
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 1953
diff changeset
67 # TODO: check remote auth_attribs
1b14cc05a54a refactor authentication and split out session handling
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 1953
diff changeset
68 u = user.User(request, name=name, auth_method=self.name, auth_attribs=('name', 'aliasname', 'password', 'email', ))
1b14cc05a54a refactor authentication and split out session handling
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 1953
diff changeset
69 for key, value in account_data.iteritems():
1b14cc05a54a refactor authentication and split out session handling
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 1953
diff changeset
70 if key not in request.cfg.user_transient_fields:
1b14cc05a54a refactor authentication and split out session handling
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 1953
diff changeset
71 setattr(u, key, value)
1b14cc05a54a refactor authentication and split out session handling
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 1953
diff changeset
72 u.valid = True
1b14cc05a54a refactor authentication and split out session handling
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 1953
diff changeset
73 u.create_or_update(True)
3125
40c4670c3410 refactored auth package to use own logger
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2728
diff changeset
74 if verbose: logging.info("successful interwiki auth for %r" % name)
2025
d919b7b7b3e9 auth framework: login() methods return an object now
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2009
diff changeset
75 return ContinueLogin(u)
2181
340ae0e7529e replace xmlrpc getUser by getUserProfile, auth can be done by getAuthToken/applyAuthToken in the same multicall, use for interwiki auth
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2025
diff changeset
76