It's hard to be certain, but I'm fairly sure that you need to make
sure that the user in question (i.e. the one authenticated via
mod_authnz_ldap) has the "is_staff" flag set on the Django user
object.
Django requires that there be a User object in the database for each
user, so RemoteUserBackend creates missing User objects on demand (see
http://code.djangoproject.com/browser/django/trunk/django/contrib/auth/backends.py#L68
for the code). However, these automatically-created users won't have
any permissions or the "is_staff" flag set, so they won't be allowed
to log into the admin.
The solution is to subclass RemoteUserBackend and override the
"configure_user" method, setting permissions and staff/superuser flags
appropriately (perhaps via an LDAP query?) This is briefly mentioned
in the documentation (see
http://docs.djangoproject.com/en/dev/howto/auth-remote-user/#remoteuserbackend)
which has a few other details in case you need 'em.
Jacob
That's interesting - perhaps LDAP is reporting a different username?
You could check in the auth_user table to see what's getting created
when you authenticate; you should see a entry get created the first
time you authenticate as a given user.
> Any clever ideas for where to shim some debugging code to see what is
> happening in the native Django stuff?
I'd start by subclassing RemoteUserBackend and throwing some logging
code into the configure_user (and perhaps clean_username) callbacks.
After that you could try subclassing RemoeUserMiddleware and again
adding some logging callbacks (in process_request, I think).
Jacob
On Tue, May 17, 2011 at 2:00 PM, Jeff Blaine <cjbl...@gmail.com> wrote:
> That gets us somewhere, because authenticating to Apache/LDAP as jblaine
> did NOT make a Django user jblaine.That's interesting - perhaps LDAP is reporting a different username?
You could check in the auth_user table to see what's getting created
when you authenticate; you should see a entry get created the first
time you authenticate as a given user
Well the auth application has a rather large set of tests that exercises
both creating, specifying (in the AUTHENTICATION_BACKENDS setting) and
using custom auth backends:
and using django.contrib.auth.backends.RemoteUserBackend plus custom
subclasses of it that perform assorted extra actions using the provided
hooks:
So it would be surprising if things were in such a broken state.
I'd suggest to use that code as a guidance and try to play with what you
have, drilling down until you get some change in behavior that gives
some hint of the actual problem at hand.
Some ideas:
Specify an empty AUTHENTICATION_BACKENDS setting and see if your project
fails to start both with the development server and with you Apache
setup.
Make sure the string with which your specify your custom backend in
AUTHENTICATION_BACKENDS is a valid one considering the python module
search path available under you Apache setup
Change the strategy you use to really subclass from
django.contrib.auth.backends.ModelBackend, etc.
Regards,
--
Ramiro Morales