Changeset 5830


Ignore:
Timestamp:
09/10/09 16:37:44 (10 years ago)
Author:
pjkersha
Message:

Initial code for a HTTPS WSGI interface to front a MyProxy? service.

Location:
TI12-security/trunk/python/ndg_security_server/ndg/security/server/wsgi
Files:
1 added
1 edited

Legend:

Unmodified
Added
Removed
  • TI12-security/trunk/python/ndg_security_server/ndg/security/server/wsgi/authn.py

    r5786 r5830  
    519519 
    520520 
     521class AuthnInterfaceBase(object): 
     522    def logon(self, environ, username, password): 
     523        raise NotImplementedError() 
     524    
     525  
     526class EnvironAuthnInterface(AuthnInterfaceBase): 
     527    """Implementation of HTTP Basic Auth authentication plugin which simply 
     528    passes the username to downstream middleware via environ 
     529    """ 
     530    def logon(self, environ, username, password): 
     531        # TODO: implement... 
     532        raise NotImplementedError() 
     533     
     534     
     535class HTTPBasicAuthMiddleware(NDGSecurityMiddlewareBase): 
     536    '''HTTP Basic Authentication Middleware 
     537     
     538    TODO: implement authN interface and username/password retrieval from 
     539    HTTP header.''' 
     540     
     541    def __init__(self, app, app_conf, **local_conf): 
     542 
     543        self.__authnInterface = None 
     544        super(HTTPBasicAuthMiddleware).__init__(self,  
     545                                                app,  
     546                                                app_conf,  
     547                                                **local_conf) 
     548         
     549    def __call__(self, environ, start_response): 
     550        """Authenticate based HTTP header elements as specified by the HTTP 
     551        Basic Authentication spec.""" 
     552        log.debug("HTTPBasicAuthNMiddleware.__call__ ...") 
     553         
     554        try: 
     555            self.authnInterface.logon(environ, username, password) 
     556                 
     557        except Exception, e: 
     558            return self._errorResponse(code=401) 
     559        else: 
     560            return self._app(environ, start_response) 
     561 
    521562# AuthKit based HTTP basic authentication not currently needed but may need 
    522563# resurrecting 
     
    525566#from ndg.security.server.wsgi.utils.sessionmanagerclient import \ 
    526567#    WSGISessionManagerClient 
    527 #class HTTPBasicAuthNMiddleware(NDGSecurityMiddlewareBase): 
    528 #    '''HTTP Basic Authentication Middleware 
    529 #     
    530 #    TODO: implement authN interface and username/password retrieval from 
    531 #    HTTP header.''' 
    532 #     
    533 #    def __init__(self, app, app_conf, **local_conf): 
    534 # 
    535 #        super(HTTPBasicAuthentication).__init__(self,  
    536 #                                                app,  
    537 #                                                app_conf,  
    538 #                                                **local_conf) 
    539 #         
    540 #    def __call__(self, environ, start_response): 
    541 #        """Authenticate based HTTP header elements as specified by the HTTP 
    542 #        Basic Authentication spec.""" 
    543 #        log.debug("HTTPBasicAuthNMiddleware.__call__ ...") 
    544 #         
    545 #        try: 
    546 #            self.authNInterface.logon(username, password) 
    547 #                 
    548 #        except Exception, e: 
    549 #            return self._errorResponse(code=401) 
    550 #        else: 
    551 #            return self._app(environ, start_response) 
    552568#             
    553569#class HTTPBasicAuthentication(object): 
Note: See TracChangeset for help on using the changeset viewer.