Authenticate against a list of users as well as ldap

54 views
Skip to first unread message

Adam Thomas

unread,
Jan 2, 2012, 12:11:46 PM1/2/12
to django-auth-ldap
Hi,

I have a particular setup I am trying to achieve. I have django-auth-
ldap working great at the moment. However, as well as authenticating
on the ldap server, I want to ensure the username is also in a list
within the DB. How do i do this?

Essentially, the admin can add a list of usernames on the ldap server
who can access the site. There should be no population of user fields
unless the username is on this list. If it isn't on the list, access
is denied.

I looked into extending the class - but it calls the _LDAPUser class
so I don't think I can do that?

Thanks,

Adam

Adam Thomas

unread,
Jan 2, 2012, 1:02:38 PM1/2/12
to django-a...@googlegroups.com
Solved it :).

from django_auth_ldap.backend import LDAPBackend, _LDAPUser
from django.core.exceptions import ObjectDoesNotExist
from accounts.models import AllowedUsername

class CustomLDAPBackend(LDAPBackend):
def authenticate(self, username, password):
user = super(CustomLDAPBackend, self).authenticate(username, password)
if user is not None:
try:
allowed_user = AllowedUsername.objects.get(username=username)
except ObjectDoesNotExist:
return None
return user

Jeff Schroeder

unread,
Jan 2, 2012, 1:13:08 PM1/2/12
to django-a...@googlegroups.com, django-a...@googlegroups.com
Django tip, ObjectDoesNotExist should be attached to every model. You should be able to do:

try:
foo
except ModelName.ObjectDoesNotExist:
bar

Sent from my iPhone

Fauzi Tsani Zharfan

unread,
Jan 30, 2013, 9:58:54 PM1/30/13
to django-a...@googlegroups.com
Hello Adams

now i'm learning django-auth-ldap

and i was intrested with this code.
but i don't know what is models for AllowedUsername

can you bring me the code :)

sorry for my bad english.. XD

Di majo

unread,
May 12, 2024, 2:07:16 PM5/12/24
to django-auth-ldap
MT103/202 DIRECT WIRE TRANSFER
PAYPAL TRANSFER
CASHAPP TRANSFER
ZELLE TRANSFER
LOAN DEAL
TRANSFER WISE
WESTERN UNION TRANSFER
BITCOIN FLASHING
BANK ACCOUNT LOADING/FLASHING
IBAN TO IBAN TRANSFER
MONEYGRAM TRANSFER
IPIP/DTC
SLBC PROVIDER
CREDIT CARD TOP UP
DUMPS/ PINS
SEPA TRANSFER
WIRE TRANSFER
BITCOIN TOP UP
GLOBALPAY INC US
SKRILL USA
UNIONPAY RECEIVER

Thanks.


NOTE; ONLY SERIOUS / RELIABLE RECEIVERS CAN CONTACT.

DM ME ON WHATSAPP
+44 7529 555638
Reply all
Reply to author
Forward
0 new messages