~ubuntu-branches/ubuntu/natty/moin/natty-updates

« back to all changes in this revision

Viewing changes to MoinMoin/auth/interwiki.py

  • Committer: Bazaar Package Importer
  • Author(s): Jonas Smedegaard
  • Date: 2008-06-22 21:17:13 UTC
  • mfrom: (0.9.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20080622211713-fpo2zrq3s5dfecxg
Tags: 1.7.0-3
Simplify /etc/moin/wikilist format: "USER URL" (drop unneeded middle
CONFIG_DIR that was wrongly advertised as DATA_DIR).  Make
moin-mass-migrate handle both formats and warn about deprecation of
the old one.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- coding: iso-8859-1 -*-
 
2
"""
 
3
    MoinMoin - authentication using a remote wiki
 
4
 
 
5
    @copyright: 2005 by Florian Festi,
 
6
                2007-2008 by MoinMoin:ThomasWaldmann
 
7
    @license: GNU GPL, see COPYING for details.
 
8
"""
 
9
 
 
10
import xmlrpclib
 
11
 
 
12
from MoinMoin import log
 
13
logging = log.getLogger(__name__)
 
14
 
 
15
from MoinMoin import wikiutil, user
 
16
from MoinMoin.auth import BaseAuth, ContinueLogin, CancelLogin
 
17
 
 
18
class InterwikiAuth(BaseAuth):
 
19
    name = 'interwiki'
 
20
    logout_possible = True
 
21
    login_inputs = ['username', 'password']
 
22
 
 
23
    def __init__(self, trusted_wikis):
 
24
        BaseAuth.__init__(self)
 
25
        self.trusted_wikis = trusted_wikis
 
26
 
 
27
    def login(self, request, user_obj, **kw):
 
28
        username = kw.get('username')
 
29
        password = kw.get('password')
 
30
 
 
31
        if not username or not password:
 
32
            return ContinueLogin(user_obj)
 
33
 
 
34
        logging.debug("trying to authenticate %r" % username)
 
35
        wikiname, username = username.split(' ', 1) # XXX Hack because ':' is not allowed in name field
 
36
        wikitag, wikiurl, name, err = wikiutil.resolve_interwiki(request, wikiname, username)
 
37
 
 
38
        logging.debug("resolve wiki returned: %r %r %r %r" % (wikitag, wikiurl, name, err))
 
39
        if err or wikitag not in self.trusted_wikis:
 
40
            return ContinueLogin(user_obj)
 
41
 
 
42
        homewiki = xmlrpclib.ServerProxy(wikiurl + "?action=xmlrpc2")
 
43
        auth_token = homewiki.getAuthToken(name, password)
 
44
        if not auth_token:
 
45
            logging.debug("%r wiki did not return an auth token." % wikitag)
 
46
            return ContinueLogin(user_obj)
 
47
 
 
48
        logging.debug("successfully got an auth token for %r. trying to get user profile data..." % name)
 
49
 
 
50
        mc = xmlrpclib.MultiCall(homewiki)
 
51
        mc.applyAuthToken(auth_token)
 
52
        mc.getUserProfile()
 
53
        result, account_data = mc()
 
54
 
 
55
        if result != "SUCCESS":
 
56
            logging.debug("%r wiki did not accept auth token." % wikitag)
 
57
            return ContinueLogin(None)
 
58
 
 
59
        if not account_data:
 
60
            logging.debug("%r wiki did not return a user profile." % wikitag)
 
61
            return ContinueLogin(None)
 
62
 
 
63
        logging.debug("%r wiki returned a user profile." % wikitag)
 
64
 
 
65
        # TODO: check remote auth_attribs
 
66
        u = user.User(request, name=name, auth_method=self.name, auth_attribs=('name', 'aliasname', 'password', 'email', ))
 
67
        for key, value in account_data.iteritems():
 
68
            if key not in request.cfg.user_transient_fields:
 
69
                setattr(u, key, value)
 
70
        u.valid = True
 
71
        u.create_or_update(True)
 
72
        logging.debug("successful interwiki auth for %r" % name)
 
73
        return ContinueLogin(u)
 
74