source: TI12-security/trunk/python/ndg.security.server/ndg/security/server/authnservice/basicauthn.py @ 4384

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/TI12-security/trunk/python/ndg.security.server/ndg/security/server/authnservice/basicauthn.py@4384
Revision 4384, 2.0 KB checked in by pjkersha, 12 years ago (diff)

SessionMgr? -> SessionManager?

Line 
1"""
2Basic Authentication interface - extending the SessionManager AbstractAuthNService
3interface - to allow use with SessionManager
4
5NERC Data Grid Project
6"""
7__author__ = "P J Kershaw"
8__date__ = "08/10/08"
9__copyright__ = "(C) 2008 STFC & NERC"
10__license__ = \
11"""This software may be distributed under the terms of the Q Public
12License, version 1.0 or later."""
13__contact__ = "P.J.Kershaw@rl.ac.uk"
14__revision__ = '$Id: $'
15import logging
16log = logging.getLogger(__name__)
17import hashlib
18
19from ndg.security.server.sessionmanager import SessionManager, \
20    AbstractAuthNService, AuthNServiceInvalidCredentials, AuthNServiceError
21from ndg.security.common.myproxy import MyProxyClient
22
23class BasicAuthN(AbstractAuthNService):
24    '''Provide a basic Authentication interface to the Session Manager
25    based on username/password entries in a config file'''
26   
27    def __init__(self, **prop):
28        '''Instantiate MyProxy client object taking in settings from the
29        properties file'''
30        accounts = prop.get('basicAuthN_accounts', []).split()
31        self.accounts = dict([tuple(account.split(':')) \
32                              for account in accounts])
33       
34    def logon(self, username, passphrase):
35        '''Implementation of AbstractAuthNService logon for a MyProxy client
36        @type username: basestring
37        @param username: username for account login
38        @type passphrase: basestring
39        @param passphrase: passphrase (or password) for user account
40        @rtype: None
41        @return: this interface doesn't return any user PKI credentials.
42        '''
43        try:
44            md5Passwd = hashlib.sha224(passphrase).hexdigest()
45        except Exception, e:
46            raise AuthNServiceError("%s exception raised making a digest of "
47                                    "the input passphrase: %s" % \
48                                    (e.__class__, e))
49
50        if self.accounts.get(username) != md5Passwd:
51            raise AuthNServiceInvalidCredentials()
Note: See TracBrowser for help on using the repository browser.