<s> import logging <EOL> import os <EOL> from django . conf import settings <EOL> from keystoneclient import auth <EOL> from keystoneclient_kerberos import v3 as v3_kerb_auth <EOL> from openstack_auth import plugin <EOL> ENV_NAME = '<STR_LIT>' <EOL> AUTH_SETTING_NAME = '<STR_LIT>' <EOL> LOG = logging . getLogger ( __name__ ) <EOL> class _HackedKerbAuth ( v3_kerb_auth . Kerberos ) : <EOL> def __init__ ( self , auth_url , original_auth_url , ticket ) : <EOL> super ( _HackedKerbAuth , self ) . __init__ ( auth_url = auth_url ) <EOL> self . original_auth_url = original_auth_url <EOL> self . ticket = ticket <EOL> def get_endpoint ( self , session , ** kwargs ) : <EOL> if kwargs . get ( '<STR_LIT>' ) == auth . AUTH_INTERFACE : <EOL> return self . original_auth_url <EOL> return super ( _HackedKerbAuth , self ) . get_endpoint ( session , ** kwargs ) <EOL> def get_auth_ref ( self , * args , ** kwargs ) : <EOL> os . environ [ ENV_NAME ] = self . ticket <EOL> try : <EOL> return super ( _HackedKerbAuth , self ) . get_auth_ref ( * args , ** kwargs ) <EOL> finally : <EOL> os . environ . pop ( ENV_NAME , None ) <EOL> class Kerberos ( plugin . BasePlugin ) : <EOL> def __init__ ( self , * args , ** kwargs ) : <EOL> super ( Kerberos , self ) . __init__ ( * args , ** kwargs ) <EOL> self . login_url = getattr ( settings , AUTH_SETTING_NAME , None ) <EOL> if not self . login_url : <EOL> LOG . warn ( '<STR_LIT>' <EOL> '<STR_LIT>' , AUTH_SETTING_NAME ) <EOL> def get_plugin ( self , request = None , auth_url = None , ** kwargs ) : <EOL> if not ( request and auth_url ) : <EOL> return None <EOL> if self . keystone_version < <NUM_LIT:3> : <EOL> return None <EOL> if not self . login_url : <EOL> return None <EOL> ticket = request . environ . get ( ENV_NAME ) <EOL> if not ticket : <EOL> return None <EOL> return _HackedKerbAuth ( self . login_url , auth_url , ticket ) </s>
