Sometimes the hard part of a python application is to integrate sso because there is an unknown : what rules is defined to get the user !
In windows, apache mod_sspi or enfold proxy give to us an http header ( name X_REMOTE_USER) to deal with the active directory. This header is like that:
Domain\user
If you have one domain it’s pretty simple. Your userid is unique
But in big company there is multiple domain controler. And user is not unique ! So how retrieve an unique user id for active directory and use it in my windows python application !
The response is get UserPrincipalName with COM and NameTranslate interface.
import win32com.client
d = win32com.client.Dispatch('NameTranslate')
d.Init(3,'')
d.Set(3,'domain\\user')
userPrincipalName = d.Get(9)
Now if you use COM with zope as me , COM is not thread safe. So init the client at zope starting and lock yours calls to the API
import win32com.client
import threading
D = win32com.client.Dispatch('NameTranslate')
D.Init(3,'')
COMLOCK = threading.Lock()
And in a function use the global D
def getUserPrincipalName(sso_header):
try:
COMLOCK.acquire()
D.Set(3,sso_header)
userPrincipalName = D.Get(9)
finally:
COMLOCK.release()
return userPrincipalName
Youpi , thanks win32com !!