Re: Django and LDAP

227 views
Skip to first unread message

Mike Dewhirst

unread,
Sep 10, 2012, 6:36:56 PM9/10/12
to django...@googlegroups.com
On 11/09/2012 4:14am, Tony wrote:
> Hi everybody,
>
> I am new to Django and Python, and right now, i am going through the
> documentation. I have an assignment at my Faculty, where i need to
> install Django, 389ds LDAP server (where i have to store my users) and i
> need to somehow connect them two, so i can auth users from LDAP when
> logging into Django. i have read some documentation, and i saw a massive
> lines of code, add this, add that, and i don't get any of that.

I think the best first step is to tightly specify your requirements.
There are lots of different approaches and your choice of available open
source depends a lot on what you want to do. For example, you may be
interested in ldap group membership being related to Django groups.

Being new to Python and Django isn't a problem. Look at Mark Pilgrim's
Dive into Python (the first one which covers Python 2.x) then do the
Django tutorials up to the point where the Django Admin is working for
you. That will demonstrate "add this, add that" and make it easier for
you. Also, install pip for fetching this and that!

The Django Admin auth will happily/easily accept external auth backends.

I have stopped using ldap nowadays but when I had it working the general
principle employed was to query the ldap server and if it authenticated
the offered userid and password AND the userid didn't exist in the
Django user table, the backend inserted a new record.

From my own experience I can recommend you start with a plan to unit
test absolutely everything. The ldap side of things is tricky. Once you
get your head around Python and Django you will really appreciate the
nth degree of flexibility.

Good luck

Mike

>
> Can someone please help me with this issue, i'll be very grateful.
>
> Thank you
>
> --
> You received this message because you are subscribed to the Google
> Groups "Django users" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/django-users/-/7ArlkeKjY0YJ.
> To post to this group, send email to django...@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.

Ivan Pavlović

unread,
Sep 11, 2012, 5:49:49 PM9/11/12
to django...@googlegroups.com
Thank you Mike for your answer. I started this topic, because i have an assignment at my Faculty, which requires connection between Django and an LDAP (assistant insisted on 389ds). I installed Django, enabled admin, logged in through Firefox. I can't make up my mind, do i need to connect Django and LDAP like so that all users from LDAP can login through e.g. localhost:8000/admin, or do i need to make a register/login page, where users from LDAP server can login and onlu admin can login from admin page? The second is mpre logical to me, but i don't know, because i am new to Django and Python.




For more options, visit this group at
http://groups.google.com/group/django-users?hl=en.
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django...@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.

Mike Dewhirst

unread,
Sep 11, 2012, 6:05:49 PM9/11/12
to django...@googlegroups.com
On 12/09/2012 7:49am, Ivan Pavlovi� wrote:
> Thank you Mike for your answer. I started this topic, because i have an
> assignment at my Faculty, which requires connection between Django and
> an LDAP (assistant insisted on 389ds). I installed Django, enabled
> admin, logged in through Firefox. I can't make up my mind, do i need to
> connect Django and LDAP like so that all users from LDAP can login
> through e.g. localhost:8000/admin, or do i need to make a register/login
> page, where users from LDAP server can login and onlu admin can login
> from admin page? The second is mpre logical to me, but i don't know,
> because i am new to Django and Python.

It is immaterial where it is hosted except localhost:8000 is usually the
development machine running the development server. It comes with a
caveat "not for production use". You really need a production web server
for production.

Your other questions are unanswerable without a set of specs. You can
use the admin or not and you can use the login/auth with your own app
and/or the admin depending on the url you use. Users can be permitted to
use the admin or not depending on user.is_staff

There is no substitute for getting started.
> https://groups.google.com/d/__msg/django-users/-/__7ArlkeKjY0YJ
> <https://groups.google.com/d/msg/django-users/-/7ArlkeKjY0YJ>.
> To post to this group, send email to
> django...@googlegroups.com
> <mailto:django...@googlegroups.com>.
> To unsubscribe from this group, send email to
> django-users+unsubscribe@__googlegroups.com
> <mailto:django-users%2Bunsu...@googlegroups.com>.
> For more options, visit this group at
> http://groups.google.com/__group/django-users?hl=en
> <http://groups.google.com/group/django-users?hl=en>.
>
>
> --
> You received this message because you are subscribed to the Google
> Groups "Django users" group.
> To post to this group, send email to django...@googlegroups.com
> <mailto:django...@googlegroups.com>.
> To unsubscribe from this group, send email to
> django-users+unsubscribe@__googlegroups.com
> <mailto:django-users%2Bunsu...@googlegroups.com>.
> For more options, visit this group at
> http://groups.google.com/__group/django-users?hl=en
> <http://groups.google.com/group/django-users?hl=en>.
>
>
> --
> You received this message because you are subscribed to the Google
> Groups "Django users" group.
> To post to this group, send email to django...@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users...@googlegroups.com.

Thomas Lockhart

unread,
Sep 11, 2012, 6:09:26 PM9/11/12
to django...@googlegroups.com
On 9/11/12 2:49 PM, Ivan Pavlović wrote:
> Thank you Mike for your answer. I started this topic, because i have
> an assignment at my Faculty, which requires connection between Django
> and an LDAP (assistant insisted on 389ds). I installed Django, enabled
> admin, logged in through Firefox. I can't make up my mind, do i need
> to connect Django and LDAP like so that all users from LDAP can login
> through e.g. localhost:8000/admin, or do i need to make a
> register/login page, where users from LDAP server can login and onlu
> admin can login from admin page? The second is mpre logical to me, but
> i don't know, because i am new to Django and Python.
I believe that you will write a (small) middleware function which will
be added to the tuple PASSWORD_HASHERS in your settings.py. The
middleware will take the username and password already provided by the
user from an existing login page and then access your LDAP server for
the authentication.

You can probably find example code for that middleware function in
Django; I needed to use existing Drupal (ugh) passwords for a content
conversion to Mezzanine and found an example, probably on django-snippets.

hth

- Tom

Ivan Pavlović

unread,
Sep 11, 2012, 6:11:58 PM9/11/12
to django...@googlegroups.com
Once again, thank you. If you have some advices or pointers where to start (besides the ones you've already mentioned), how to develop my knowledge, please feel free to share with me.

Grateful
Tony

On Wed, Sep 12, 2012 at 12:05 AM, Mike Dewhirst <mi...@dewhirst.com.au> wrote:
        <mailto:django-users@googlegroups.com>.

        To unsubscribe from this group, send email to
        django-users+unsubscribe@__googlegroups.com
        <mailto:django-users%2Bunsu...@googlegroups.com>.

        For more options, visit this group at
        http://groups.google.com/__group/django-users?hl=en
        <http://groups.google.com/group/django-users?hl=en>.



    --
    You received this message because you are subscribed to the Google
    Groups "Django users" group.
    To post to this group, send email to django...@googlegroups.com

    To unsubscribe from this group, send email to
    django-users+unsubscribe@__googlegroups.com
    <mailto:django-users%2Bunsu...@googlegroups.com>.

    For more options, visit this group at
    http://groups.google.com/__group/django-users?hl=en
    <http://groups.google.com/group/django-users?hl=en>.



--
You received this message because you are subscribed to the Google
Groups "Django users" group.
To post to this group, send email to django...@googlegroups.com.
To unsubscribe from this group, send email to

For more options, visit this group at
http://groups.google.com/group/django-users?hl=en.
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django...@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.

Ivan Pavlović

unread,
Sep 11, 2012, 6:13:05 PM9/11/12
to django...@googlegroups.com
I appreciate it Thomas :)

Mike Dewhirst

unread,
Sep 11, 2012, 10:47:37 PM9/11/12
to django...@googlegroups.com
On 12/09/2012 8:05am, Mike Dewhirst wrote:
> On 12/09/2012 7:49am, Ivan Pavlovi� wrote:
>> Thank you Mike for your answer. I started this topic, because i have an
>> assignment at my Faculty, which requires connection between Django and
>> an LDAP (assistant insisted on 389ds). I installed Django, enabled
>> admin, logged in through Firefox. I can't make up my mind, do i need to
>> connect Django and LDAP like so that all users from LDAP can login
>> through e.g. localhost:8000/admin, or do i need to make a register/login
>> page, where users from LDAP server can login and onlu admin can login
>> from admin page? The second is mpre logical to me, but i don't know,
>> because i am new to Django and Python.

<snip>

>
> There is no substitute for getting started.

https://github.com/mdewhirst/ldap-groups

I got a great start using Peter Herndon's django-ldap-groups which
completely satisfied my client's specifications at the time. I ended up
enhancing the Novell eDirectory backend somewhat for Django 1.3 and it
probably needs more attention for Django 1.4 - check the Django release
notes in the authentication backend area.

Anyway, I just uploaded it to github so you or anyone else can use it.
You should check Peter's site for licensing and to compare the original
with my adjustments.

http://pypi.python.org/pypi/django-ldap-groups/0.1.3

Also, google for "django ldap" to find a bunch of other ldap software.

hth

Mike

<snip>


Stephen Anto

unread,
Sep 12, 2012, 4:41:36 AM9/12/12
to django...@googlegroups.com
Hi,

Django instalation on ubuntu, I found key instructions on http://www.f2finterview.com/web/Django/4/

for more follow django instalation guide

On Mon, Sep 10, 2012 at 11:44 PM, Tony <pavlovic...@gmail.com> wrote:
Hi everybody,

I am new to Django and Python, and right now, i am going through the documentation. I have an assignment at my Faculty, where i need to install Django, 389ds LDAP server (where i have to store my users) and i need to somehow connect them two, so i can auth users from LDAP when logging into Django. i have read some documentation, and i saw a massive lines of code, add this, add that, and i don't get any of that.


Can someone please help me with this issue, i'll be very grateful.

Thank you


--
You received this message because you are subscribed to the Google Groups "Django users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/7ArlkeKjY0YJ.

To post to this group, send email to django...@googlegroups.com.
To unsubscribe from this group, send email to django-users...@googlegroups.com.

For more options, visit this group at http://groups.google.com/group/django-users?hl=en.



--
Thanks & Regards
Stephen S



Blog:      blog.f2finterview.com

sbrandt

unread,
Sep 13, 2012, 4:16:29 AM9/13/12
to django...@googlegroups.com
Did you know there is django-auth-ldap which is a custom backend for authenticating users through LDAP? http://pypi.python.org/pypi/django-auth-ldap/

I don't see the point why you fiddle around with writing code on your own. I'm using django-auth-ldap since one and a half year in production and it works like a charm.

Ivan Pavlović

unread,
Sep 13, 2012, 11:43:23 AM9/13/12
to django...@googlegroups.com
Thank you sbrandt. I found the same thing, but i don't know how to use it. Where do i need to copy the files and do i erase some lines of the code or not, to make them as comments. I'm trying but i am not succeeding at making it work...

Can you help me about that?

On Thu, Sep 13, 2012 at 10:16 AM, sbrandt <s.brand...@googlemail.com> wrote:
Did you know there is django-auth-ldap which is a custom backend for authenticating users through LDAP? http://pypi.python.org/pypi/django-auth-ldap/

I don't see the point why you fiddle around with writing code on your own. I'm using django-auth-ldap since one and a half year in production and it works like a charm.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/4Go12iWz_pEJ.

sbrandt

unread,
Sep 16, 2012, 1:33:15 PM9/16/12
to django...@googlegroups.com
Where exactly do you need help?

You can install it like every other python package via pip or easy_install: "pip install django-auth-ldap" or "easy_install django-auth-ldap".

Configuration is really easy and described in the documentation. They support groups and automatic extraction of LDAP data into user fields, even into the user profile: http://packages.python.org/django-auth-ldap/

I suggest you to read this documentation since it is really clear to understand and answer here if you have a particular problem :) Good luck!
Reply all
Reply to author
Forward
0 new messages