- changed host and port to just a server uri
- added an option to connect with TLS - unbind after when done
This commit is contained in:
parent
c4513740bf
commit
11782c0061
@ -26,19 +26,26 @@ class LDAP(object):
|
|||||||
self.ldap_settings = mg_globals.global_config['plugins']['mediagoblin.plugins.ldap']
|
self.ldap_settings = mg_globals.global_config['plugins']['mediagoblin.plugins.ldap']
|
||||||
|
|
||||||
def _connect(self, server):
|
def _connect(self, server):
|
||||||
_log.info('Connecting to {0}.'.format(server['LDAP_HOST']))
|
_log.info('Connecting to {0}.'.format(server['LDAP_SERVER_URI']))
|
||||||
self.conn = ldap.initialize('ldap://{0}:{1}/'.format(
|
self.conn = ldap.initialize(server['LDAP_SERVER_URI'])
|
||||||
server['LDAP_HOST'], server['LDAP_PORT']))
|
|
||||||
|
if server['LDAP_START_TLS'] == 'true':
|
||||||
|
_log.info('Initiating TLS')
|
||||||
|
self.conn.start_tls_s()
|
||||||
|
|
||||||
def login(self, username, password):
|
def login(self, username, password):
|
||||||
for k, v in self.ldap_settings.iteritems():
|
for k, v in self.ldap_settings.iteritems():
|
||||||
try:
|
try:
|
||||||
self._connect(v)
|
self._connect(v)
|
||||||
user_dn = v['USER_DN_TEMPLATE'].format(username=username)
|
user_dn = v['LDAP_USER_DN_TEMPLATE'].format(username=username)
|
||||||
self.conn.simple_bind_s(user_dn, password.encode('utf8'))
|
self.conn.simple_bind_s(user_dn, password.encode('utf8'))
|
||||||
return username
|
return username
|
||||||
|
|
||||||
except ldap.LDAPError, e:
|
except ldap.LDAPError, e:
|
||||||
_log.info(e)
|
_log.info(e)
|
||||||
|
|
||||||
|
finally:
|
||||||
|
_log.info('Unbinding {0}.').format(v['LDAP_SERVER_URI'])
|
||||||
|
self.conn.unbind()
|
||||||
|
|
||||||
return False
|
return False
|
||||||
|
Loading…
x
Reference in New Issue
Block a user