#NEWLINE# @ staticmethod #NEWLINE# def try_login( username , password ) : #NEWLINE# #INDENT# conn = get_ldap_connection ( configuration . get ( 'ldap' , 'bind_user' ) , configuration . get ( 'ldap' , 'bind_password' ) ) #NEWLINE# search_filter = '(&({0})({1}={2}))' . format ( configuration . get ( 'ldap' , 'user_filter' ) , configuration . get ( 'ldap' , 'user_name_attr' ) , username ) #NEWLINE# search_scopes = { #NEWLINE# #INDENT# 'LEVEL' : LEVEL , #NEWLINE# 'SUBTREE' : SUBTREE , #NEWLINE# 'BASE' : BASE , #NEWLINE# #UNINDENT# } #NEWLINE# search_scope = LEVEL #NEWLINE# if configuration . has_option ( 'ldap' , 'search_scope' ) : #NEWLINE# #INDENT# search_scope = ( SUBTREE if ( configuration . get ( 'ldap' , 'search_scope' ) == 'SUBTREE' ) else LEVEL ) #NEWLINE# #UNINDENT# res = conn . search ( configuration . get ( 'ldap' , 'basedn' ) , search_filter , search_scope = search_scope ) #NEWLINE# if ( not res ) : #NEWLINE# #INDENT# LOG . info ( 'Cannot find user %s' , username ) #NEWLINE# raise AuthenticationError ( 'Invalid username or password' ) #NEWLINE# #UNINDENT# entry = conn . response [ 0 ] #NEWLINE# conn . unbind ( ) #NEWLINE# if ( not ( 'dn' in entry ) ) : #NEWLINE# #INDENT# raise AuthenticationError ( 'Invalid username or password' ) #NEWLINE# #UNINDENT# try : #NEWLINE# #INDENT# conn = get_ldap_connection ( entry [ 'dn' ] , password ) #NEWLINE# #UNINDENT# except KeyError as e : #NEWLINE# #INDENT# LOG . error ( ( "\n            Unable to parse LDAP structure. If you're using Active Directory and not specifying an OU, you must set search_scope=SUBTREE in airflow.cfg.\n            %s\n            " % traceback . format_exc ( ) ) ) #NEWLINE# raise LdapException ( 'Could not parse LDAP structure. Try setting search_scope in airflow.cfg, or check logs' ) #NEWLINE# #UNINDENT# if ( not conn ) : #NEWLINE# #INDENT# LOG . info ( 'Password incorrect for user %s' , username ) #NEWLINE# raise AuthenticationError ( 'Invalid username or password' )