0

I am creating a django application that need to authenticate against our organization's LDAP server which I have successfully done using django-auth-ldap. After authentication, I need to authorize each authenticated user against a local database to check if they have privileges to use the application. How do I go about doing this? I've tried to go through the documentation for django-auth-ldap but cannot find anything relevant.

tks
  • 55
  • 6

1 Answers1

0

In you login view I would check the local database and add permissions programmatically after the user has been authenticated, see https://docs.djangoproject.com/en/dev/topics/auth/default/#topic-authorization

 if user.is_active:
     login(request, user)
     #your code to query database and add permissions
     _check_and_set_permissions(request)

     return redirect('login_success')

If the database you need to check differs from the database you specified for use by the Django ORM

 DATABASES = {
     'default': {
        'NAME': 'DEMODATABASE',
        'ENGINE': 'sqlserver_ado',
        'HOST': '127.0.0.1',
     }
   }

Then just create a connection to the database using your favorite driver/SQL expression language (pymssql, SA, pyMySQLdb, etc.) and query the table containing the permissions you need.

jugovich
  • 123
  • 2
  • 8