1 | ## $Id$ |
---|
2 | ## |
---|
3 | ## Copyright (C) 2013 Uli Fouquet & Henrik Bettermann |
---|
4 | ## This program is free software; you can redistribute it and/or modify |
---|
5 | ## it under the terms of the GNU General Public License as published by |
---|
6 | ## the Free Software Foundation; either version 2 of the License, or |
---|
7 | ## (at your option) any later version. |
---|
8 | ## |
---|
9 | ## This program is distributed in the hope that it will be useful, |
---|
10 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
11 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
12 | ## GNU General Public License for more details. |
---|
13 | ## |
---|
14 | ## You should have received a copy of the GNU General Public License |
---|
15 | ## along with this program; if not, write to the Free Software |
---|
16 | ## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
---|
17 | ## |
---|
18 | import grok |
---|
19 | from zope.component import getUtility |
---|
20 | from zope.pluggableauth.interfaces import IAuthenticatorPlugin |
---|
21 | from waeup.kofa.interfaces import IUniversity |
---|
22 | |
---|
23 | |
---|
24 | class ApplicantsXMLRPC(grok.XMLRPC): |
---|
25 | """Applicant related XMLRPC webservices. |
---|
26 | |
---|
27 | Please note, that XMLRPC does not support real keyword arguments |
---|
28 | but positional arguments only. |
---|
29 | """ |
---|
30 | grok.context(IUniversity) |
---|
31 | |
---|
32 | @grok.require('waeup.xmlrpc') |
---|
33 | def check_applicant_credentials(self, username, password): |
---|
34 | """Returns applicant data if username and password are valid, |
---|
35 | None else. |
---|
36 | |
---|
37 | We only query the applicants authenticator plugin in order not |
---|
38 | to mix up with other credentials (admins, staff, etc.). |
---|
39 | |
---|
40 | All additional checks performed by usual applicant |
---|
41 | authentication apply. |
---|
42 | |
---|
43 | This method can be used by CAS to authentify applicants for |
---|
44 | external systems like moodle. |
---|
45 | """ |
---|
46 | auth = getUtility(IAuthenticatorPlugin, name='applicants') |
---|
47 | creds = dict(login=username, password=password) |
---|
48 | principal = auth.authenticateCredentials(creds) |
---|
49 | if principal is None: |
---|
50 | return None |
---|
51 | return dict(email=principal.email, id=principal.id, |
---|
52 | type=principal.user_type, |
---|
53 | description=principal.description) |
---|