Ignore:
Timestamp:
12 Aug 2013, 08:52:26 (11 years ago)
Author:
uli
Message:

Kofa authenticator now really contacts Kofa instances for authentication.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.cas/trunk/waeup/cas/authenticators.py

    r10475 r10478  
    33import re
    44from pkg_resources import iter_entry_points
     5try:
     6    import xmlrpclib                     # Python 2.x
     7except ImportError:                      # pragma: no cover
     8    import xmlrpc.client as xmlrpclib    # Python 3.x
    59
    610
     
    112116
    113117
     118#: Regular expression matching a starting university marker like
     119#: the string 'MA-' in 'MA-M121212' or 'MA-' in 'MA-APP-13123'
     120RE_SCHOOL_MARKER = re.compile('^[^\-]+-')
     121
     122
    114123class KofaAuthenticator(Authenticator):
    115124    """Authenticate against a running Kofa instance.
     
    148157        """Do the real check.
    149158        """
    150         return False, 'Not implemented.'
     159        for backend_name, backend in self.backends.items():
     160            if not re.match(backend['marker'], username):
     161                continue
     162            # remove school marker
     163            username = RE_SCHOOL_MARKER.sub('', username)
     164            proxy = xmlrpclib.ServerProxy(
     165                backend['url'], allow_none=True)
     166            valid = proxy.check_credentials(username, password)
     167            if valid is not None:
     168                return (True, '')
     169        return (False, 'Invalid username or password.')
Note: See TracChangeset for help on using the changeset viewer.