How pass authentication using django_auth_ldap ?

79 views
Skip to first unread message

Fabio Surrage

unread,
Feb 25, 2014, 9:31:16 AM2/25/14
to django...@googlegroups.com
Greetings !

Im trying to code a Automated Deploy System to Applications using Zope/Plone and JBOSS/Java and I am having some issues with LDAP Authentication.

The authorization is OK, my problem is to make Django "user" know it...


from django_auth_ldap.backend import LDAPBackend
from django.http import HttpResponseRedirect


def LoginView(request):
    username = request.GET['username']
    password = request.GET['passwd']
    auth = LDAPBackend()
    user = auth.authenticate(username=username, password=password)
    #login(request, user)
    if user is not None:
        if user.is_authenticated():
            return HttpResponseRedirect(reverse('deployApp:deploy'))
        else:
            return HttpResponseRedirect('http://www.google.com.br')
    else:
        messages.add_message(request, messages.ERROR, 'Falha na Autenticacao.')
        return HttpResponseRedirect('/deployApp')


This code make the authentication of the user correctly, but in the deployApp:deploy view I got request.user = AnonymousUser

I tryed to use [login(request, user)] but I got the error 'User' object has no attribute 'backend'

I need to write my own login method or there is a easier way to populate de request.user ???

Thanks in advance

--
** Fábio Surrage de Medeiros **
http://google.com/+FabioSurrage

rush

unread,
Feb 25, 2014, 3:18:18 PM2/25/14
to django...@googlegroups.com
Hi,

I'm using grappelli and I have two files in it I need to modify:

admin/js/SelectBox.js
admin/js/SelectFilter2.js

I thought it would be a good idea to put it into my app static directory:

my_app/static/admin/js/SelectBox.js
my_app/static/admin/js/SelectFilter2.js

But whenever I try ./manage.py collectstatic files from my_app are overrided by original files from grappelli, however I need it vice versa.

I need just to add several strings in this files into existing functions, so I can't handle it within a new js files and include into Media class ( from my point of view ).

Is there any way to override grappelli files?

 
wbr,
rush.

Felipe Bessa Coelho

unread,
Feb 25, 2014, 3:52:29 PM2/25/14
to Django users
When collecting static files, if there are multiple files with the same name Django will pick the first one it finds. [1] What that means is, unless you've changed STATICFILES_FINDERS, files inside folders in STATICFILES_DIRS will have the highest priority. And if static files inside apps are used, Django will follow the INSTALLED_APPS order, meaning you probably have grappelli _above_ my_app.

If for whatever reason you don't want/can't change the order your apps appear in INSTALLED_APPS, you may consider placing those files in a folder using STATICFILES_DIRS.

[1] https://docs.djangoproject.com/en/dev/ref/settings/#std:setting-STATICFILES_FINDERS

Tom Evans

unread,
Feb 25, 2014, 4:19:45 PM2/25/14
to django...@googlegroups.com
Thats not how authentication works. You list
'django_auth_ldap.backend.LDAPBackend' in
settings.AUTHENTICATION_BACKENDS, and call
django.contrib.auth.authenticate() with the username and password.

This will return a user object correctly annotated with the backend
used to authenticate them; this can then be used in the call to
login(), which will set the appropriate session variables.

See the docs for more info:

https://docs.djangoproject.com/en/1.6/topics/auth/customizing/

https://docs.djangoproject.com/en/1.6/topics/auth/default/#auth-web-requests

Cheers

Tom

rush

unread,
Feb 25, 2014, 4:25:33 PM2/25/14
to django...@googlegroups.com
Wow, that's a great explanation. Thank you, Felipa!
 
wbr,
rush.
 
 
 
26.02.2014, 00:52, "Felipe Bessa Coelho" <fcoe...@gmail.com>:
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAP5dYfP7pmXZsR592gx%2Bp%3DND1w9__Jq%3Dyzxnok2BFj5Gsi1rsw%40mail.gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.
Reply all
Reply to author
Forward
0 new messages