Example #1
0
	def ldap_auth(self, user, pwd, server_details):
		from webnotes import set_ldap_connection
		import ldap

		status = True	
		mail = None
		user_id = None	
		dn = None

		connect, user_dn, base_dn = set_ldap_connection()
		filters = "uid=*"+user+"*"
		
		try:
			connect.simple_bind_s(user_dn, server_details.get('pwd'))
			result = connect.search_s(base_dn, ldap.SCOPE_SUBTREE, filters)
			for dn, r in result:
				dn = str(dn)	
				mail = str(r['mail'][0])
				user_id = str(r['uid'][0])
				role = str(r['description'][0])

			if dn:
				connect.simple_bind_s(dn,pwd)
				status = True
			else:
				self.fail("Not a valid LDAP user")

		except ldap.LDAPError, e:
			connect.unbind_s()
			status = False
def ldap_connect():
	from webnotes import get_details, set_ldap_connection
	server_details = get_details()

	connect, user_dn, base_dn = set_ldap_connection()
	filters =  "uid=*"

	new_created = [] 
	enabled_profiles = []

	try:
		#if authentication successful, get the full user data	
		connect.simple_bind_s(user_dn, server_details.get('pwd'))

	except ldap.LDAPError, e:
		connect.unbind_s()