On Tue, Feb 25, 2014 at 2:31 PM, Fabio Surrage <fabiosurrage@gmail.com> wrote:
> 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
>
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
--
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+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@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/CAFHbX1%2B4RMrVxBd54KHMBuKMJ0WN9S_5NGsU%3DTALTx%2B_tnQXcg%40mail.gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment