I'm using LDAP for authentication and want to use autoenrollment. I think I have a grasp of the basics but I am having a problem with the terminology. The uid for MS active directory that must match moodles uid-can these be directly identified. I think uid for ms active directory would be samacountname? what would be the moodle uid. If users are auto enrolled isn't moodle id taken from active directory?
Chet
I have couple of questions though is a posixGroup a security or distribution group?
Active directory only lets me create one group with the same name. Can't create math101 twice in two seperate ou's.
Thanks for your help.
Chet
So you have to use 'member' (instead of memberUid) for any *_memberattribute that appears in the Howto, and use 'group' (instead of posixGroup) for the objectclass values.
You can create the same group in different OUs as long as they have a different pre-Windows 2000 name (their saMAccountName).
Saludos. Iñaki.
Chet
Saludos. Iñaki.
line 1 ?php: No such file or directory (I am in the ldap directory with execute rights)
line 3: syntax error near unexpected token '_SERVER['GATEWAY_INTERFACE']'
line 3: 'if(empty($_SERVER['GATEWAY_INTERFACE'])){'
Any ideas?
Chet
php -f enrol_ldap_sync.php
(assuming php.exe is in your execution path, and that your working directory is ...moodle/enrol/ldap/).
Saludos. Iñaki.
Thanks for all your help.
Chet
Then paste your LDAP enrolmente configuration settings, and a few of the errors you get when you run the sync script. Again, mask your data as much as you want, but keep the syntax and structure of it, so we can make sense of it
Saludos. Iñaki.
I am trying to run a test of the ldap howto. The OU's are the same as
the example, studentEnrollment, teacherEnrollment with groups for Math
and english in each. Test teachers and students as per the ldap
autoenrol howto.
*LDAP** server
ldap_host url: ldap://server ip
ldap_version: 3
ldap_preventpassindb: yes
ldap_bind_dn: CN=user,ou=TestMoodle,DC=domain,DC=local
ldap_bind_pw: *******
ldap_user_type: MS ActiveDirectory
ldap_contexts: OU=TeacherEnrollment,DC=domainDC=local;OU=StudentEnrollment,DC=domain,DC=local
ldap_search_sub: Yes
ldap_opt_deref: NO
ldap_user_attribute: sAMAccountName
ldap_memberattribute:
ldap_objectclass:
DataMapping
First Name: givenName
Last Name: sn
ID number: SAMAccountName
Enrollment settings
LDAP Server
enrol_ldap_host
ldap://ipaddress_of_LDAP_Server
enrol_ldap_version: 3
enrol_ldap_bind_dn: cn=username,OU=container,DC=domain,DC=local
ldap_bind_pw: *************
ldap_search_sub: Yes
Student enrolment settings
enrol_ldap_student_contexts: ou=StudentEnrollment,DC=domain,DC=local;ou=TeacherEnrollment,DC=domain,DC=local
enrol_ldap_student_memberattribute: member
Teacher enrolment settings
enrol_ldap_teacher_contexts: ou=TeacherEnrollment,DC=domain,DC=local
enrol_ldap_teacher_memberattribute: member
Course enrolment settings
enrol_ldap_objectclass: group
enrol_ldap_course_idnumber: cn
Update local data Yes
Lock value Yes
enrol_ldap_course_shortname: cn
Update local data Yes
Lock value Yes
enrol_ldap_course_fullname: description
Update local data Yes
Lock value Yes
enrol_ldap_course_summary: description
Update local data Yes
Lock value Yes
Automatic course creation settings
enrol_ldap_autocreate: Yes
enrol_ldap_category: AutoEnrol
enrol_ldap_template:
General Options
enrol_allowinternal: not checked
I am trying to run a test of the ldap howto. The OU's are the same as
the example, studentEnrollment, teacherEnrollment with groups for Math
and english in each. Test teachers and students as per the ldap
autoenrol howto.
*LDAP** Auth Settings
ldap_host url: ldap://server ip
ldap_version: 3
ldap_preventpassindb: yes
ldap_bind_dn: CN=user,ou=TestMoodle,DC=domain,DC=local
ldap_bind_pw: *******
ldap_user_type: MS ActiveDirectory
ldap_contexts: OU=TeacherEnrollment,DC=domainDC=local;OU=StudentEnrollment,DC=domain,DC=local
ldap_search_sub: Yes
ldap_opt_deref: NO
ldap_user_attribute: sAMAccountName
ldap_memberattribute:
ldap_objectclass:
DataMapping
First Name: givenName
Last Name: sn
ID number: SAMAccountName
Enrollment settings
LDAP Server
enrol_ldap_host
ldap://ipaddress_of_LDAP_Server
enrol_ldap_version: 3
enrol_ldap_bind_dn: cn=username,OU=container,DC=domain,DC=local
ldap_bind_pw: *************
ldap_search_sub: Yes
Student enrolment settings
enrol_ldap_student_contexts: ou=StudentEnrollment,DC=domain,DC=local;ou=TeacherEnrollment,DC=domain,DC=local
enrol_ldap_student_memberattribute: member
Teacher enrolment settings
enrol_ldap_teacher_contexts: ou=TeacherEnrollment,DC=domain,DC=local
enrol_ldap_teacher_memberattribute: member
Course enrolment settings
enrol_ldap_objectclass: group
enrol_ldap_course_idnumber: cn
Update local data Yes
Lock value Yes
enrol_ldap_course_shortname: cn
Update local data Yes
Lock value Yes
enrol_ldap_course_fullname: description
Update local data Yes
Lock value Yes
enrol_ldap_course_summary: description
Update local data Yes
Lock value Yes
Automatic course creation settings
enrol_ldap_autocreate: Yes
enrol_ldap_category: AutoEnrol
enrol_ldap_template:
General Options
enrol_allowinternal: not checked
The problem is the find_ext_enrolments() function. It receives a $memberuid parameter with the idnumber of the user, and uses it to search the groups where a member of the groups matches that idnumber value. But is uses the value as is, which in the case of Active Directory doesn't work, because AD uses the full DN of the user in the member attribute, and not just the CN.
So unless you patch ldap/enrol.php, you won't go very far with Active Directory and LDAP enrollment.
Saludos. Iñaki.
You can map Moodle's ID number field to AD's 'distinguishedName' attribute. This way, you have a fully qualified DN value in Moodle, and the search works.
One note though: ID Number is just 64 characters wide, so if your AD users' 'distinguishedName' s are longer than that, you'll be in trouble.
Big Red Warning: I haven't tested all this with auth_ldap_sync.php and/or enrol_ldap_sync.php, so I offer no warranty at all.
Saludos. Iñaki.

Thank you for any help!
amer
you will also need to change it in lib\moodlelib.php
Mdl_user -> idnumber varchar(64) to varchar(255)
Dan
amer
I am trying to get LDAP enrolment to work in 1.6+ with AD but having problems.
Is it still the case that I have to either hack the find_ext_enrolments() function or extend the fieldlength in the database and hack two lib.php files?
Regards
Steve
http://moodle.org/bugs/bug.php?op=show&bugid=5882
It's a single line in the file course/enrol.php.
But beware the warning in the comments.
I did extend the length of my idnumber field (and the two lib php files), but, looking at my idnumber column, I don't think I needed it. None of my idnumber values are greater than 64.
Thanks for this. I will have to extend mine as our values gou beyond 127 chars.
Regards
Steve
Ryan
I have a problem now when I run auth_ldap_sync_users.php. All of my users are deleted and then revived. This does not cause too much problem for students as running enrol_ldap_sync.php re-enrols them in their courses. Unfortunately I cannot use the same enrolment process to assign teachers so the net result is that all my teachers are removed. Do you see this problem in your setup?
Iñaki has identified the problem as being related to the non use of sAMAccountName in this post http://moodle.org/mod/forum/discuss.php?d=40111&parent=185569.
Overall this leaves me wondering if anyone is actually using LDAP authentication and enrolment with Microsoft Active Directory as the process does not seem to match AD fields and is prescriptive of the way data is stored in AD.
I will keep puzzling to see if I can work out a way to resolve this
Regards
Steve
Why not? If I remember correctly, enrol_ldap_sync.php assigns both students and teachers.
On the other hand, the "trick" to use LDAP enrolment with Active Directory (using the distinguishedName as the ID number of the users) breaks auth_ldap_sync.php, as you have already seen. I warned about this (in big red bold face) in a couple of the threads (and this is one of them), but it seems nobody noticed
Currently the LDAP enrolment code only works for rfc2307 compatible LDAP servers (Novell eDir and OpenLDAP, where it was developed, AFAIK) and the trick mentionned above is just a "dirty hack" to make it work. But it's not a real fix, as it breaks other things (the *_ldap_sync.php scripts).
Saludos. Iñakil
Iñaki
Thank you for this reply. I did see the big red warning so I am only experimenting on my development server at the moment.
I cannot use the enrolment for teachers since it requires a group with the same name as the student group but in a different OU. Our AD is already well established and all groups are stored in a single OU with different names for staff groups and student groups. Unfortunately the configuration settings within Moodle do not have sufficient flexibility to fit in with an established directory system that cannot be changed to suit one element of our complete MLE, network telephone system etc.
I am now looking into rewriting the enrol_ldap_sync.php matches to see if I can match distinguished name as returned by AD for group membership to another field in mdl_users so that I can keep sAMAcountName in idnumber. A rather challenging first PHP project
Regards
Steve
Not pretty. :\ (The distinguishedName v sAMAccountName issue.)
For now, I will try to use the sync script only between semesters to clear out the old accounts.
As always, thanks to Inaki, Martin and other PHP programmers (not me) for all their efforts in development and assistance.
I'm afraid it is.
Saludos. Iñaki.
Hi, Iñaki Arenaza
Is that quite safe to run moodle/enrol/ldap/enrol_ldap_sync.php at any time? Even it is on the busy time?
So what i understand is that I should create 2 different ou, 1 for teacher and 1 for student and create inside each ou the courses. I will end up having same group names. You say this can be done if they have a pre windows 2000 name.
My question:
Can someone just check if what i understood is correct coz i want to face the person responsible for ldap and i wanna be sure i am on the right track.
Thank you all for your help and wish me luck
Just like the examples in the image.
Saludos. Iñaki.

Thank you alot,this made things very clear.
I have another question:
Every course has around 30 students and only 1 teacher. Is it logical to create 1 group having 1 teacher's name only? This is what Moodle requires? There's no other way?Thank you for reply and advice.
Yes, this is what Moodle requires. I don't know another way to do it.
Saludos. Iñaki.
I have done everything you clarified. I added a demo student to a demo course. When i logged in using the student account, and clicked the course's name, it says: This course doesnt allow internal enrollment. So i think the connection between moodle and ldap is still not there yet. Any hints?
Please correct me if i am wrong:
if a student is already added inside a group which is in this case the course, once he login he should see the course's title right?
Thank you in advance
Saludos. Iñaki.
Hi Inaki,
I do have the following settings, and I am still stuck. Do you have any way around this or point for me where is my error?
enrol_ldap_version:3
enrol_ldap_bind_dn:moodle1@win2k.aub.edu.lb
ldap_bind_pw: test
enrol_ldap_student_contexts:ou=allgroups,ou=security groups,ou=resource groups,ou=aub resources groups,ou=aubrg-acc,dc=win2k,dc=aub,dc=edu,dc=lb
enrol_ldap_student_memberattribute:memberUid
Course enrolment settings
enrol_ldap_objectclass: Group
enrol_ldap_course_idnumber:cn
enrol_ldap_autocreate: Yes
More over the authentication is working fine with "enrol_ldap_bind_dn:moodle1@win2k.aub.edu.lb", I have also tested using the absolute path "cn=moodle1,ou=allusers,dc=win2k,dc=aub,dc=edu,dc=lb" and I am still stuck.
Any suggestions for the above?
Mostafa Itani
LDAP Auth settings:
ldap_host_url: ldap://server.janne.com
ldap_version: 3
ldap_preventpassindb: yes
ldap_bind_dn: cn=Ldap Browser,cn=Users,dc=janne,dc=com
ldap_bind_pw: ***********
ldap_user_type: MS ActiveDirectory
ldap_contexts: ou=opettajat,dc=janne,dc=com;ou=oppilaat,dc=janne,dc=com
ldap_search_sub: no
ldap_opt_deref: no
ldap_user_attribute: sAMAccountName
ldap_memberattribute: member
ldap_objectclass:
force change password: no
use standard... : no
ldap_expiration: no
ldap_expiration_warning: 10
ldap_expireattr:
ldap_gracelogins: no
ldap_greceattr:
ldap_create_context:
ldap_creators:
First name: givenName
Update local: On creation
Update external: never
Lock value: locked
Surname: sn
Update local: On creation
Update external: never
Lock value: locked
Email address: mail
Update local: On creation
Update external: never
Lock value: Unlocked
Phone1: telephoneNumber
Update local: On creation
Update external: never
Lock value: Unlocked
Phone2: mobile
Update local: On creation
Update external: never
Lock value: Unlocked
ID number: distinguishedName
Update local: On every login
Update external: never
Lock value: locked
LDAP enrolments settings:
enrol_ldap_host_url: ldap://server.janne.com
enrol_ldap_version: 3
enrol_ldap_bind_dn: cn=Ldap Browser,cn=Users,dc=janne,dc=com
enrol_ldap_bind_pw: **********
ldap_search_sub: no
enrol_ldap_student_contexts: ou=oppilaat,dc=janne,dc=com
enrol_ldap_student_memeberattribute: member
enrol_ldap_teacher_contexts: ou=opettajat,dc=janne,dc=com
enrol_ldap_teacher_memeberattribute: member
enrol_ldap_objectclass: group
enrol_ldap_course_idnumber: cn
update local data: no
lock value: no
enrol_ldap_course_shortname: cn
update local data: no
lock value: no
enrol_ldap_course_fullname: description
update local data: no
lock value: no
enrol_ldap_course_summary: info
update local data: no
lock value: no
enrol_ldap_autocreate: yes
enrol_ldap_category: misc
enrol_ldap_template:
enrol_allowinternal: checked
Only hack that I did was change database user table's idnumber field length to 255 nothing else ( if you manage with that default length 64 then you don't have to hack that either).
I'm using same value in course shortname and idnumber.
- Janne -
I have the correct path for the enrol_ldap_student_contexts for students and teachers.
For enrol_ldap_teacher_memberattribute, i am using "member"
enrol_ldap_objectclass : group
enrol_ldap_course_idnumber: cn.
What i did is created a group in the active directory under the student OU and called it "course1".I added a student in it.
Same done under the teacher OU.
I login using the student id, when i find the course and click on the course, it says:
Manual enrolments are currently not enabled.
Step 2 was:
I created the course manually on Moodle. Then i logged in again, same message as above.
So i think the problem is that either LDAP and Moodle not communicating concerning enrollment OR something wrong going on when moodle is checking the user logging in against the user found inside the group.
Any hints?I am unable to progress at all.
Thank you for your help.
- Janne -
Thank you for your help. I appreciate your support
Just one thing for those of you running into ldap enrolment issues on v1.6. If you've got LDAP authentication working and enrolment is eluding you, this bug set me back and the proposed "improper" fix resolved the issue for me. http://moodle.org/bugs/bug.php?op=show&bugid=5882
I had tried everything in the above thread before finally trying this. Hopefully, there'll be a "proper" fix soon.
None of my distinguished names are over 63 characters (wow that was close) so I haven't had to hack any files.
Auto enrollment with LDAP including course creation works fine and when logging in as a user with LDAP I don't get asked to confirm enrolment as well.
It might be worth udating the HOWTO to reflect these changes (and also putting a note against the ID Number field in LDAP authentication to tell AD users to use distinguishedName and watch for the 64 char limit)
Colin
Hola Iñaki,
Al parecer creo que manejas un poco el tema de matriculación con LDAP, tengo unas dudas al respecto.
Tengo un moodle que esta funcionan con la autentificación LDAP para el ingreso de los estudiantes a la plataforma.
Ahora mi duda es que si ya tengo creado los cursos bajo una codificación que los identifique, tengo entendido por lo que he leido en los foros que la matricula de los alumnos seria identificando algun campo en la BD de LDAP que coincida con la codificación del curso, es decir, si el curso como identificador posee un codigo 001, el alumno dentro de los datos que entrega la BD LDAP, deberia traer algun campo identificatorio igual a 001, con lo cual el alumno quedaria matriculado en ese curso.
De esa forma funciona la automatricula por LDAP.
agradeciendo tu ayuda
saludos desde Chile
things are a bit more complicated than what you say. You need a very specific LDAP structure to represent teacher enrolments and student enrolments, using LDAP groups.
Have a look at this page for the specific details: http://docs.moodle.org/22/en/LDAP_enrolment
(Now in Spanish)
Hola Nicole,
las cosas son un poco más complicadas de lo que indicas. Necesitas una estructura determinada en tu LDAP para representar las matriculaciones de los profesores y las matriculaciones de los alumnos, usando grupos de LDAP para ello.
Echa una ojeada a esta página para detalles más concretos: http://docs.moodle.org/22/en/LDAP_enrolment
Saludos.
Iñaki.
Hola Iñaki,
Gracias por la respuesta, en realidad ya había visto el enlaces.
Pero , si en el caso que el LDAP lo configurara para entregar el código de la carrera, y en mi moodle tuviera un curso por cada carrera con ese código de identificación del curso que me esta entregando el LDAP, con eso bastaría para configurar el moodle para que recibiera ese dato y dejara matriculado al alumno en ese curso.
Ahora lo otro es necesario indicar el profesor, o no es necesario si solo quieres matricular al alumno en el curso.
Agradeciendo tu respuesta,
Saludos desde Chile
Nicole
Had many proplems with auto enrollment, but it just about works now.
The problem i am having is that the user is assigned to all courses as a teacher, even if they're not in the group for that course.
Any suggestions?
How do I change the field size for my MySQL database?
*EDIT*
I have opened up the moodle database using Webmin but it says there are too many tables to display, what is the table I need to open that has the ID field that needs to be changed to more than 64 characters?
Saludos. Iñaki.
Open up a console and type:
mysql -u root -p moodledb
You'll be prompted for the 'root' password (this is the MySQL root user, not the operating system root user). If the mysql root user doesn't have a password just press ENTER. 'moodledb' is the name of your Moodle database.
Once you are in, type the following query:
ALTER TABLE mdl_user CHANGE COLUMN idnumber idnumber VARCHAR(255);
(if you want to widen the idnumber field to 255 characters).
Saludos. Iñaki.
Saludos. Iñaki.
Eric
Eric
Yes, 1.9.x already has the idnumber field 255 characters wide.
Saludos. Iñaki.
Hi there
I'm a new one. José Cruz from Portugal.
(sory my english)
My situation: LDAP Windows Server 2003. Moodle 1.8
I have a OU container (schoolserver), with subOUs (students and teachers).
I have a OU (moodle) with subOUs (students and teachers) for moodle groups.
I have LDAP authentication like that and working.
LDAP server settings
Host URL: ldap://minhaescola.servidorescola.local
Version : 3
LDAP encoding : utf-8
Bind Settings
Hide passwords: yes
Distinguished Name: CN=moodle esmcastilho,CN=Users,DC=minhaescola,DC=servidorescola,DC=local
password.
User lookup settingsUser type: MS ActiveDirectory
Contexts: OU=SchoolServer,DC=minhaescola,DC=servidorescola,DC=local
search sub: yes
dereference alias: no
user attribute: sAMAccountName
Member attribute:
Member attribute uses dn:
Object class: user
Force change password
force: no
use standard: no
LDAP password expiration settings
expiration: LDAP
Enable user creation
create user externally: no
course creators
creators:
Cron synchronization script
Removed ext user: Full delete internal
first name: givenName
ID number: sAMAccountName
I can't say the same about enrol and i don't know why.
Here are my settings:
LDAP Server Settings
enrol_ldap_host_url: ldap://minhaescola.servidorescola.local
enrol_ldap_version: 3
enrol_ldap_bind_dn: CN=moodle esmcastilho,CN=Users,DC=minhaescola,DC=servidorescola,DC=local
ldap_bind_pw: *********
ldap_search_sub: yes
Role mapping
Teacher
LDAP contexts: OU=profs,OU=Moodle,DC=minhaescola,DC=servidorescola,DC=local
LDAP member attribute: member
students
LDAP contexts: OU=alunos,OU=Moodle,DC=minhaescola,DC=servidorescola,DC=local
LDAP member attribute: member
Course enrolment settings
enrol_ldap_objectclass: group
enrol_ldap_course_idnumber: cn, no, no
enrol_ldap_course_shortname: cn, no, no
enrol_ldap_course_shortname: cn, no, no
Automatic course creation settings
enrol_ldap_autocreate: yes
enrol_ldap_category: Geral
If anyone can help, please...
Best wishes from Portugal
Has anyone ever got LDAP enrollment really working with MS AD? I'm using Moodle 2.02 and still experiencing the same issues described here as far as I can tell. LDAP Authentication works fine, but none of the enrollment data in Active Directory seems to do anything. Auto Course creation doesn't create new courses lited in AD and if the user clicks on a course that matches one in AD, they get a "You can not enrol yourself in this course." message even though they should be enrolled.
I've searched and read all the info I can find on LDAP enrollement here and it all seems rather dated.. circa 2006-2007. Where can I find current documentation for this?
I would also like to know of some current documentation on this. I am going to make a new post about my current situation too, so maybe we can get something going.
Hello,
In line with LDAP auto enrolment, can you also make it so that it unenrols the student when they withdraw? I have posted this question here as well https://moodle.org/mod/forum/discuss.php?d=274073
Would appreciate any suggestions.