Hi,
I've been trying to get AD authentication working for access control to my Jam application.
I've installed ldap3 and this script;
# import class and constants
from ldap3 import Server, Connection, ALL
def on_login(task, login, password, ip, session_uuid):
users = task.app.admin.sys_users.copy(handlers=False)
users.set_where(f_login=login, f_password=password)
users.set_where(f_login=login)
users.open()
if users.record_count() == 1:
return {
'user_id': users.id.value,
'user_name': users.f_name.value,
'role_id': users.f_role.value,
'role_name': users.f_role.display_text
}
users = task.users.copy(handlers=False)
users.set_where(login=login, password=password)
users.open()
if users.record_count() == 1:
return {
'user_id': users.id.value,
'user_name': users.name.value,
'role_id': users.role.value,
'role_name': users.role.display_text
}
result = None
# define the server
s = Server('10.79.1.2', port=389, use_ssl=False) #define an unsecure LDAP server, requesting info on DSE and schema
# define the connection
try:
c = Connection(s, user='CN=%s,OU=Users,OU=...,DC=...,DC=com' % login, password=password)
# perform the Bind operation
if not c.bind():
#print('error in bind', c.result)
raise Exception('You are not allowed!')
print('You are not allowed!')
else:
result = {
'user_id': login,
'user_name': login,
#'user_id': login,
#'user_name': login,
'role_id': 1,
'role_name': 'Admin'
}
# below except is not working
except Exception as e:
print("authentication error")
return result
(obviously with the correct OU and DC, tested with ldapsearch and working.)
When trying to login this is the error produced (logging in with a 'local' Jam account still works!);
Traceback (most recent call last):
File "/usr/local/lib/python3.7/dist-packages/jam.py-5.4.114-py3.7.egg/jam/wsgi.py", line 387, in login
user_info = task.on_login(task, form_data, {'ip': ip, 'session_uuid': session_uuid})
TypeError: on_login() missing 2 required positional arguments: 'ip' and 'session_uuid'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/local/lib/python3.7/dist-packages/jam.py-5.4.114-py3.7.egg/jam/wsgi.py", line 391, in login
user_info = task.on_login(task, form_data['login'], form_data['password'], ip, session_uuid)
File "prints", line 17, in on_login
users = task.users.copy(handlers=False)
AttributeError: 'Task' object has no attribute 'users'
Any help is much appreciated!
Ian.