add a new app for ldap3-authentication (currently, it uses a testserver), login/logout from django, my own decorator
This commit is contained in:
27
fet2020/authentications/authentications.py
Normal file
27
fet2020/authentications/authentications.py
Normal file
@@ -0,0 +1,27 @@
|
||||
import ldap3
|
||||
|
||||
|
||||
def authentication(username, password):
|
||||
# no empty passwords
|
||||
if password is None or password.strip() == "":
|
||||
# messages.info("username:%s Login denied for blank password", username)
|
||||
return None
|
||||
|
||||
# username format
|
||||
new_username = 'uid={username}, cn=users, cn=accounts, dc=demo1, dc=freeipa, dc=org'
|
||||
userdn = new_username.format(username=username)
|
||||
|
||||
server_uri = 'ipa.demo1.freeipa.org'
|
||||
server = ldap3.Server(server_uri, get_info=ldap3.ALL)
|
||||
|
||||
try:
|
||||
ldap3.Connection(
|
||||
server,
|
||||
userdn,
|
||||
password,
|
||||
auto_bind=True,
|
||||
)
|
||||
except ldap3.core.exceptions.LDAPBindError:
|
||||
username = None
|
||||
|
||||
return username
|
||||
Reference in New Issue
Block a user