add a new app for ldap3-authentication (currently, it uses a testserver), login/logout from django, my own decorator

This commit is contained in:
2020-08-25 17:09:08 +00:00
parent a8cd21b930
commit ffa248ce03
11 changed files with 224 additions and 0 deletions

View 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