Changeset 10477


Ignore:
Timestamp:
10 Aug 2013, 01:10:04 (11 years ago)
Author:
uli
Message:

Add a (protected) XMLRPC service that tells about a student in exchange for valid credentials.

Location:
main/waeup.kofa/trunk/src/waeup/kofa
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.kofa/trunk/src/waeup/kofa/students/tests/test_webservices.py

    r10044 r10477  
    318318        self.assertEqual(xmlout, RESPONSE_XML)
    319319        return
     320
     321    def test_check_credentials(self):
     322        # make sure we can get student infos providing valid creds
     323        server = ServerProxy('http://mgr:mgrpw@localhost/app')
     324        self.setup_student(self.student)
     325        stud_id = self.student.student_id
     326        result = server.check_credentials('mykey', stud_id, 'spwd')
     327        self.assertEqual(
     328            result, {
     329                'description': 'Anna Tester',
     330                'email': 'aa@aa.ng',
     331                'id': 'K1000000',
     332                'type': 'student'}
     333            )
     334        return
  • main/waeup.kofa/trunk/src/waeup/kofa/students/webservices.py

    r10044 r10477  
    188188            return None
    189189        return payments_dict
     190
     191    @grok.require('waeup.xmlrpc')
     192    def check_credentials(self, key, username, password):
     193        """Returns student data if username and password are valid,
     194        None else.
     195
     196        We only query the students authenticator plugin in order not
     197        to mix up with other credentials (admins, staff, etc.).
     198
     199        All additional checks performed by usual student
     200        authentication apply. For instance for suspended students we
     201        won't get a successful response but `None`.
     202
     203        This method can be used by CAS to authentify students for
     204        external systems like moodle.
     205        """
     206        from zope.pluggableauth.interfaces import IAuthenticatorPlugin
     207        auth = getUtility(IAuthenticatorPlugin, name='students')
     208        creds = dict(login=username, password=password)
     209        principal = auth.authenticateCredentials(creds)
     210        if principal is None:
     211            return None
     212        return dict(email=principal.email, id=principal.id,
     213                    type=principal.user_type,
     214                    description=principal.description)
  • main/waeup.kofa/trunk/src/waeup/kofa/webservices.py

    r10033 r10477  
    3434    #ACCEPTED_IP = ('174.36.230.28', )
    3535    ACCEPTED_IP = ('127.0.0.1', )
    36    
     36
    3737    def update(self, P_ID=None):
    3838        if P_ID == None:
Note: See TracChangeset for help on using the changeset viewer.