From 60741b3e1c025f50e93e6f5847716ed930b319a0 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Lang Date: Thu, 1 Mar 2012 16:26:10 +0000 Subject: [PATCH] Adds an optional LDAP filter (#1060). git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@9044 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- app/models/auth_source_ldap.rb | 24 +++++++++++++-- app/views/ldap_auth_sources/_form.html.erb | 3 ++ config/locales/ar.yml | 1 + config/locales/bg.yml | 1 + config/locales/bs.yml | 1 + config/locales/ca.yml | 1 + config/locales/cs.yml | 1 + config/locales/da.yml | 1 + config/locales/de.yml | 1 + config/locales/el.yml | 1 + config/locales/en-GB.yml | 1 + config/locales/en.yml | 1 + config/locales/es.yml | 1 + config/locales/et.yml | 1 + config/locales/eu.yml | 1 + config/locales/fa.yml | 1 + config/locales/fi.yml | 1 + config/locales/fr.yml | 1 + config/locales/gl.yml | 1 + config/locales/he.yml | 1 + config/locales/hr.yml | 1 + config/locales/hu.yml | 1 + config/locales/id.yml | 1 + config/locales/it.yml | 1 + config/locales/ja.yml | 1 + config/locales/ko.yml | 1 + config/locales/lt.yml | 1 + config/locales/lv.yml | 1 + config/locales/mk.yml | 1 + config/locales/mn.yml | 1 + config/locales/nl.yml | 1 + config/locales/no.yml | 1 + config/locales/pl.yml | 1 + config/locales/pt-BR.yml | 1 + config/locales/pt.yml | 1 + config/locales/ro.yml | 1 + config/locales/ru.yml | 1 + config/locales/sk.yml | 1 + config/locales/sl.yml | 1 + config/locales/sr-YU.yml | 1 + config/locales/sr.yml | 1 + config/locales/sv.yml | 1 + config/locales/th.yml | 1 + config/locales/tr.yml | 1 + config/locales/uk.yml | 1 + config/locales/vi.yml | 1 + config/locales/zh-TW.yml | 1 + config/locales/zh.yml | 1 + .../20120301153455_add_auth_sources_filter.rb | 9 ++++++ test/unit/auth_source_ldap_test.rb | 30 +++++++++++++++++++ 50 files changed, 110 insertions(+), 2 deletions(-) create mode 100644 db/migrate/20120301153455_add_auth_sources_filter.rb diff --git a/app/models/auth_source_ldap.rb b/app/models/auth_source_ldap.rb index 5c6d28cb2..bf8d70478 100644 --- a/app/models/auth_source_ldap.rb +++ b/app/models/auth_source_ldap.rb @@ -21,9 +21,10 @@ require 'net/ldap' class AuthSourceLdap < AuthSource validates_presence_of :host, :port, :attr_login validates_length_of :name, :host, :maximum => 60, :allow_nil => true - validates_length_of :account, :account_password, :base_dn, :maximum => 255, :allow_nil => true + validates_length_of :account, :account_password, :base_dn, :filter, :maximum => 255, :allow_blank => true validates_length_of :attr_login, :attr_firstname, :attr_lastname, :attr_mail, :maximum => 30, :allow_nil => true validates_numericality_of :port, :only_integer => true + validate :validate_filter before_validation :strip_ldap_attributes @@ -58,6 +59,20 @@ class AuthSourceLdap < AuthSource private + def ldap_filter + if filter.present? + Net::LDAP::Filter.construct(filter) + end + rescue Net::LDAP::LdapError + nil + end + + def validate_filter + if filter.present? && ldap_filter.nil? + errors.add(:filter, :invalid) + end + end + def strip_ldap_attributes [:attr_login, :attr_firstname, :attr_lastname, :attr_mail].each do |attr| write_attribute(attr, read_attribute(attr).strip) unless read_attribute(attr).nil? @@ -107,8 +122,13 @@ class AuthSourceLdap < AuthSource object_filter = Net::LDAP::Filter.eq( "objectClass", "*" ) attrs = {} + search_filter = object_filter & login_filter + if f = ldap_filter + search_filter = search_filter & f + end + ldap_con.search( :base => self.base_dn, - :filter => object_filter & login_filter, + :filter => search_filter, :attributes=> search_attributes) do |entry| if onthefly_register? diff --git a/app/views/ldap_auth_sources/_form.html.erb b/app/views/ldap_auth_sources/_form.html.erb index 9ffffafc7..3ddf43a9a 100644 --- a/app/views/ldap_auth_sources/_form.html.erb +++ b/app/views/ldap_auth_sources/_form.html.erb @@ -23,6 +23,9 @@

<%= text_field 'auth_source', 'base_dn', :size => 60 %>

+

+<%= text_field 'auth_source', 'filter', :size => 60 %>

+

<%= check_box 'auth_source', 'onthefly_register' %>

diff --git a/config/locales/ar.yml b/config/locales/ar.yml index 2e262f83e..4234d8426 100644 --- a/config/locales/ar.yml +++ b/config/locales/ar.yml @@ -1023,3 +1023,4 @@ ar: notice_issue_update_conflict: The issue has been updated by an other user while you were editing it. text_issue_conflict_resolution_cancel: Discard all my changes and redisplay %{link} permission_manage_related_issues: Manage related issues + field_ldap_filter: LDAP filter diff --git a/config/locales/bg.yml b/config/locales/bg.yml index 6ce7b7366..53c3cca1b 100644 --- a/config/locales/bg.yml +++ b/config/locales/bg.yml @@ -1021,3 +1021,4 @@ bg: description_date_range_interval: Изберете диапазон чрез задаване на начална и крайна дати description_date_from: Въведете начална дата description_date_to: Въведете крайна дата + field_ldap_filter: LDAP filter diff --git a/config/locales/bs.yml b/config/locales/bs.yml index 147b687c2..085434078 100644 --- a/config/locales/bs.yml +++ b/config/locales/bs.yml @@ -1037,3 +1037,4 @@ bs: notice_issue_update_conflict: The issue has been updated by an other user while you were editing it. text_issue_conflict_resolution_cancel: Discard all my changes and redisplay %{link} permission_manage_related_issues: Manage related issues + field_ldap_filter: LDAP filter diff --git a/config/locales/ca.yml b/config/locales/ca.yml index 86e997c2e..c0d554a82 100644 --- a/config/locales/ca.yml +++ b/config/locales/ca.yml @@ -1025,3 +1025,4 @@ ca: notice_issue_update_conflict: The issue has been updated by an other user while you were editing it. text_issue_conflict_resolution_cancel: Discard all my changes and redisplay %{link} permission_manage_related_issues: Manage related issues + field_ldap_filter: LDAP filter diff --git a/config/locales/cs.yml b/config/locales/cs.yml index f2e08f4d6..e5c1a5181 100644 --- a/config/locales/cs.yml +++ b/config/locales/cs.yml @@ -1026,3 +1026,4 @@ cs: notice_issue_update_conflict: The issue has been updated by an other user while you were editing it. text_issue_conflict_resolution_cancel: Discard all my changes and redisplay %{link} permission_manage_related_issues: Manage related issues + field_ldap_filter: LDAP filter diff --git a/config/locales/da.yml b/config/locales/da.yml index 386574965..9cc3a3e04 100644 --- a/config/locales/da.yml +++ b/config/locales/da.yml @@ -1040,3 +1040,4 @@ da: notice_issue_update_conflict: The issue has been updated by an other user while you were editing it. text_issue_conflict_resolution_cancel: Discard all my changes and redisplay %{link} permission_manage_related_issues: Manage related issues + field_ldap_filter: LDAP filter diff --git a/config/locales/de.yml b/config/locales/de.yml index aef545709..9dc02961a 100644 --- a/config/locales/de.yml +++ b/config/locales/de.yml @@ -1043,3 +1043,4 @@ de: notice_issue_update_conflict: The issue has been updated by an other user while you were editing it. text_issue_conflict_resolution_cancel: Discard all my changes and redisplay %{link} permission_manage_related_issues: Manage related issues + field_ldap_filter: LDAP filter diff --git a/config/locales/el.yml b/config/locales/el.yml index 50537d5aa..92d8e8c30 100644 --- a/config/locales/el.yml +++ b/config/locales/el.yml @@ -1023,3 +1023,4 @@ el: notice_issue_update_conflict: The issue has been updated by an other user while you were editing it. text_issue_conflict_resolution_cancel: Discard all my changes and redisplay %{link} permission_manage_related_issues: Manage related issues + field_ldap_filter: LDAP filter diff --git a/config/locales/en-GB.yml b/config/locales/en-GB.yml index 2cbd77065..2136b93b8 100644 --- a/config/locales/en-GB.yml +++ b/config/locales/en-GB.yml @@ -1025,3 +1025,4 @@ en-GB: notice_issue_update_conflict: The issue has been updated by an other user while you were editing it. text_issue_conflict_resolution_cancel: Discard all my changes and redisplay %{link} permission_manage_related_issues: Manage related issues + field_ldap_filter: LDAP filter diff --git a/config/locales/en.yml b/config/locales/en.yml index 2ca8582a3..21e12ba17 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -321,6 +321,7 @@ en: field_cvs_module: Module field_repository_is_default: Main repository field_multiple: Multiple values + field_ldap_filter: LDAP filter setting_app_title: Application title setting_app_subtitle: Application subtitle diff --git a/config/locales/es.yml b/config/locales/es.yml index 19531ca77..a30ffd87c 100644 --- a/config/locales/es.yml +++ b/config/locales/es.yml @@ -1060,3 +1060,4 @@ es: notice_issue_update_conflict: The issue has been updated by an other user while you were editing it. text_issue_conflict_resolution_cancel: Discard all my changes and redisplay %{link} permission_manage_related_issues: Manage related issues + field_ldap_filter: LDAP filter diff --git a/config/locales/et.yml b/config/locales/et.yml index 9ffe12e28..d77d9c09e 100644 --- a/config/locales/et.yml +++ b/config/locales/et.yml @@ -1039,3 +1039,4 @@ et: label_export_options: "%{export_format} ekspordi valikud" label_completed_versions: "Lõpetatud versioonid" error_attachment_too_big: "Seda faili ei saa üles laadida, kuna ületab maksimumsuurust (%{max_size})" + field_ldap_filter: LDAP filter diff --git a/config/locales/eu.yml b/config/locales/eu.yml index a85e7cd8b..8a02f2ffe 100644 --- a/config/locales/eu.yml +++ b/config/locales/eu.yml @@ -1026,3 +1026,4 @@ eu: notice_issue_update_conflict: The issue has been updated by an other user while you were editing it. text_issue_conflict_resolution_cancel: Discard all my changes and redisplay %{link} permission_manage_related_issues: Manage related issues + field_ldap_filter: LDAP filter diff --git a/config/locales/fa.yml b/config/locales/fa.yml index bd10913a3..efac7a131 100644 --- a/config/locales/fa.yml +++ b/config/locales/fa.yml @@ -1025,3 +1025,4 @@ fa: notice_issue_update_conflict: The issue has been updated by an other user while you were editing it. text_issue_conflict_resolution_cancel: Discard all my changes and redisplay %{link} permission_manage_related_issues: Manage related issues + field_ldap_filter: LDAP filter diff --git a/config/locales/fi.yml b/config/locales/fi.yml index 2da468723..afafc51ca 100644 --- a/config/locales/fi.yml +++ b/config/locales/fi.yml @@ -1044,3 +1044,4 @@ fi: notice_issue_update_conflict: The issue has been updated by an other user while you were editing it. text_issue_conflict_resolution_cancel: Discard all my changes and redisplay %{link} permission_manage_related_issues: Manage related issues + field_ldap_filter: LDAP filter diff --git a/config/locales/fr.yml b/config/locales/fr.yml index 2a149a0e3..8fd18c3b1 100644 --- a/config/locales/fr.yml +++ b/config/locales/fr.yml @@ -320,6 +320,7 @@ fr: field_commit_logs_encoding: Encodage des messages de commit field_repository_is_default: Dépôt principal field_multiple: Valeurs multiples + field_ldap_filter: Filtre LDAP setting_app_title: Titre de l'application setting_app_subtitle: Sous-titre de l'application diff --git a/config/locales/gl.yml b/config/locales/gl.yml index 17b583a08..8e8d30ec5 100644 --- a/config/locales/gl.yml +++ b/config/locales/gl.yml @@ -1034,3 +1034,4 @@ gl: notice_issue_update_conflict: The issue has been updated by an other user while you were editing it. text_issue_conflict_resolution_cancel: Discard all my changes and redisplay %{link} permission_manage_related_issues: Manage related issues + field_ldap_filter: LDAP filter diff --git a/config/locales/he.yml b/config/locales/he.yml index 0a5671302..af31a05e8 100644 --- a/config/locales/he.yml +++ b/config/locales/he.yml @@ -1028,3 +1028,4 @@ he: notice_issue_update_conflict: The issue has been updated by an other user while you were editing it. text_issue_conflict_resolution_cancel: Discard all my changes and redisplay %{link} permission_manage_related_issues: Manage related issues + field_ldap_filter: LDAP filter diff --git a/config/locales/hr.yml b/config/locales/hr.yml index 462615d28..3ce6f3012 100644 --- a/config/locales/hr.yml +++ b/config/locales/hr.yml @@ -1029,3 +1029,4 @@ hr: notice_issue_update_conflict: The issue has been updated by an other user while you were editing it. text_issue_conflict_resolution_cancel: Discard all my changes and redisplay %{link} permission_manage_related_issues: Manage related issues + field_ldap_filter: LDAP filter diff --git a/config/locales/hu.yml b/config/locales/hu.yml index 363575d44..b4cb98bce 100644 --- a/config/locales/hu.yml +++ b/config/locales/hu.yml @@ -1042,3 +1042,4 @@ notice_issue_update_conflict: The issue has been updated by an other user while you were editing it. text_issue_conflict_resolution_cancel: Discard all my changes and redisplay %{link} permission_manage_related_issues: Manage related issues + field_ldap_filter: LDAP filter diff --git a/config/locales/id.yml b/config/locales/id.yml index e6ab8d1a7..6dd2c81c1 100644 --- a/config/locales/id.yml +++ b/config/locales/id.yml @@ -1029,3 +1029,4 @@ id: notice_issue_update_conflict: The issue has been updated by an other user while you were editing it. text_issue_conflict_resolution_cancel: Discard all my changes and redisplay %{link} permission_manage_related_issues: Manage related issues + field_ldap_filter: LDAP filter diff --git a/config/locales/it.yml b/config/locales/it.yml index d415e668f..ae4514285 100644 --- a/config/locales/it.yml +++ b/config/locales/it.yml @@ -1024,3 +1024,4 @@ it: notice_issue_update_conflict: The issue has been updated by an other user while you were editing it. text_issue_conflict_resolution_cancel: Discard all my changes and redisplay %{link} permission_manage_related_issues: Manage related issues + field_ldap_filter: LDAP filter diff --git a/config/locales/ja.yml b/config/locales/ja.yml index f6635cbfe..1d7ebe2f0 100644 --- a/config/locales/ja.yml +++ b/config/locales/ja.yml @@ -1053,3 +1053,4 @@ ja: notice_issue_update_conflict: The issue has been updated by an other user while you were editing it. text_issue_conflict_resolution_cancel: Discard all my changes and redisplay %{link} permission_manage_related_issues: Manage related issues + field_ldap_filter: LDAP filter diff --git a/config/locales/ko.yml b/config/locales/ko.yml index 44ac0f363..740096240 100644 --- a/config/locales/ko.yml +++ b/config/locales/ko.yml @@ -1073,3 +1073,4 @@ ko: notice_issue_update_conflict: The issue has been updated by an other user while you were editing it. text_issue_conflict_resolution_cancel: Discard all my changes and redisplay %{link} permission_manage_related_issues: Manage related issues + field_ldap_filter: LDAP filter diff --git a/config/locales/lt.yml b/config/locales/lt.yml index 921e437f2..ec768783d 100644 --- a/config/locales/lt.yml +++ b/config/locales/lt.yml @@ -1083,3 +1083,4 @@ lt: notice_issue_update_conflict: The issue has been updated by an other user while you were editing it. text_issue_conflict_resolution_cancel: Discard all my changes and redisplay %{link} permission_manage_related_issues: Manage related issues + field_ldap_filter: LDAP filter diff --git a/config/locales/lv.yml b/config/locales/lv.yml index 05a1cc763..cef9174a2 100644 --- a/config/locales/lv.yml +++ b/config/locales/lv.yml @@ -1017,3 +1017,4 @@ lv: notice_issue_update_conflict: The issue has been updated by an other user while you were editing it. text_issue_conflict_resolution_cancel: Discard all my changes and redisplay %{link} permission_manage_related_issues: Manage related issues + field_ldap_filter: LDAP filter diff --git a/config/locales/mk.yml b/config/locales/mk.yml index 6f2fb2a0f..ea32c97de 100644 --- a/config/locales/mk.yml +++ b/config/locales/mk.yml @@ -1023,3 +1023,4 @@ mk: notice_issue_update_conflict: The issue has been updated by an other user while you were editing it. text_issue_conflict_resolution_cancel: Discard all my changes and redisplay %{link} permission_manage_related_issues: Manage related issues + field_ldap_filter: LDAP filter diff --git a/config/locales/mn.yml b/config/locales/mn.yml index c4f3ca752..8ce7c2148 100644 --- a/config/locales/mn.yml +++ b/config/locales/mn.yml @@ -1023,3 +1023,4 @@ mn: notice_issue_update_conflict: The issue has been updated by an other user while you were editing it. text_issue_conflict_resolution_cancel: Discard all my changes and redisplay %{link} permission_manage_related_issues: Manage related issues + field_ldap_filter: LDAP filter diff --git a/config/locales/nl.yml b/config/locales/nl.yml index 4db1f7425..00bcf3345 100644 --- a/config/locales/nl.yml +++ b/config/locales/nl.yml @@ -1005,3 +1005,4 @@ nl: notice_issue_update_conflict: The issue has been updated by an other user while you were editing it. text_issue_conflict_resolution_cancel: Discard all my changes and redisplay %{link} permission_manage_related_issues: Manage related issues + field_ldap_filter: LDAP filter diff --git a/config/locales/no.yml b/config/locales/no.yml index 18689cb92..027d66ba3 100644 --- a/config/locales/no.yml +++ b/config/locales/no.yml @@ -1013,3 +1013,4 @@ notice_issue_update_conflict: The issue has been updated by an other user while you were editing it. text_issue_conflict_resolution_cancel: Discard all my changes and redisplay %{link} permission_manage_related_issues: Manage related issues + field_ldap_filter: LDAP filter diff --git a/config/locales/pl.yml b/config/locales/pl.yml index 4aa418167..c7a4b230e 100644 --- a/config/locales/pl.yml +++ b/config/locales/pl.yml @@ -1040,3 +1040,4 @@ pl: notice_issue_update_conflict: The issue has been updated by an other user while you were editing it. text_issue_conflict_resolution_cancel: Discard all my changes and redisplay %{link} permission_manage_related_issues: Manage related issues + field_ldap_filter: LDAP filter diff --git a/config/locales/pt-BR.yml b/config/locales/pt-BR.yml index b26d13367..87520721d 100644 --- a/config/locales/pt-BR.yml +++ b/config/locales/pt-BR.yml @@ -1046,3 +1046,4 @@ pt-BR: notice_issue_update_conflict: The issue has been updated by an other user while you were editing it. text_issue_conflict_resolution_cancel: Discard all my changes and redisplay %{link} permission_manage_related_issues: Manage related issues + field_ldap_filter: LDAP filter diff --git a/config/locales/pt.yml b/config/locales/pt.yml index ecbca9431..775fe5596 100644 --- a/config/locales/pt.yml +++ b/config/locales/pt.yml @@ -1028,3 +1028,4 @@ pt: notice_issue_update_conflict: The issue has been updated by an other user while you were editing it. text_issue_conflict_resolution_cancel: Discard all my changes and redisplay %{link} permission_manage_related_issues: Manage related issues + field_ldap_filter: LDAP filter diff --git a/config/locales/ro.yml b/config/locales/ro.yml index 6b243c65e..2ac306642 100644 --- a/config/locales/ro.yml +++ b/config/locales/ro.yml @@ -1020,3 +1020,4 @@ ro: notice_issue_update_conflict: The issue has been updated by an other user while you were editing it. text_issue_conflict_resolution_cancel: Discard all my changes and redisplay %{link} permission_manage_related_issues: Manage related issues + field_ldap_filter: LDAP filter diff --git a/config/locales/ru.yml b/config/locales/ru.yml index f927abcf8..a4bbdc4d9 100644 --- a/config/locales/ru.yml +++ b/config/locales/ru.yml @@ -1138,3 +1138,4 @@ ru: notice_issue_update_conflict: The issue has been updated by an other user while you were editing it. text_issue_conflict_resolution_cancel: Discard all my changes and redisplay %{link} permission_manage_related_issues: Manage related issues + field_ldap_filter: LDAP filter diff --git a/config/locales/sk.yml b/config/locales/sk.yml index d8c71c6ab..1cfe719f3 100644 --- a/config/locales/sk.yml +++ b/config/locales/sk.yml @@ -1023,3 +1023,4 @@ sk: notice_issue_update_conflict: The issue has been updated by an other user while you were editing it. text_issue_conflict_resolution_cancel: Discard all my changes and redisplay %{link} permission_manage_related_issues: Manage related issues + field_ldap_filter: LDAP filter diff --git a/config/locales/sl.yml b/config/locales/sl.yml index 0016aceb1..0fc57856a 100644 --- a/config/locales/sl.yml +++ b/config/locales/sl.yml @@ -1023,3 +1023,4 @@ sl: notice_issue_update_conflict: The issue has been updated by an other user while you were editing it. text_issue_conflict_resolution_cancel: Discard all my changes and redisplay %{link} permission_manage_related_issues: Manage related issues + field_ldap_filter: LDAP filter diff --git a/config/locales/sr-YU.yml b/config/locales/sr-YU.yml index a98aaedb3..ea4e68c7a 100644 --- a/config/locales/sr-YU.yml +++ b/config/locales/sr-YU.yml @@ -1023,3 +1023,4 @@ sr-YU: notice_issue_update_conflict: The issue has been updated by an other user while you were editing it. text_issue_conflict_resolution_cancel: Discard all my changes and redisplay %{link} permission_manage_related_issues: Manage related issues + field_ldap_filter: LDAP filter diff --git a/config/locales/sr.yml b/config/locales/sr.yml index 7c5b0f249..2c8d3bcd1 100644 --- a/config/locales/sr.yml +++ b/config/locales/sr.yml @@ -1024,3 +1024,4 @@ sr: notice_issue_update_conflict: The issue has been updated by an other user while you were editing it. text_issue_conflict_resolution_cancel: Discard all my changes and redisplay %{link} permission_manage_related_issues: Manage related issues + field_ldap_filter: LDAP filter diff --git a/config/locales/sv.yml b/config/locales/sv.yml index e4a9dd893..c39e48289 100644 --- a/config/locales/sv.yml +++ b/config/locales/sv.yml @@ -1064,3 +1064,4 @@ sv: notice_issue_update_conflict: The issue has been updated by an other user while you were editing it. text_issue_conflict_resolution_cancel: Discard all my changes and redisplay %{link} permission_manage_related_issues: Manage related issues + field_ldap_filter: LDAP filter diff --git a/config/locales/th.yml b/config/locales/th.yml index 26e468c11..905a57fa8 100644 --- a/config/locales/th.yml +++ b/config/locales/th.yml @@ -1020,3 +1020,4 @@ th: notice_issue_update_conflict: The issue has been updated by an other user while you were editing it. text_issue_conflict_resolution_cancel: Discard all my changes and redisplay %{link} permission_manage_related_issues: Manage related issues + field_ldap_filter: LDAP filter diff --git a/config/locales/tr.yml b/config/locales/tr.yml index d73663adf..383f1fd01 100644 --- a/config/locales/tr.yml +++ b/config/locales/tr.yml @@ -1042,3 +1042,4 @@ tr: notice_issue_update_conflict: The issue has been updated by an other user while you were editing it. text_issue_conflict_resolution_cancel: Discard all my changes and redisplay %{link} permission_manage_related_issues: Manage related issues + field_ldap_filter: LDAP filter diff --git a/config/locales/uk.yml b/config/locales/uk.yml index 86d1d9e0c..6c16c7186 100644 --- a/config/locales/uk.yml +++ b/config/locales/uk.yml @@ -1020,3 +1020,4 @@ uk: notice_issue_update_conflict: The issue has been updated by an other user while you were editing it. text_issue_conflict_resolution_cancel: Discard all my changes and redisplay %{link} permission_manage_related_issues: Manage related issues + field_ldap_filter: LDAP filter diff --git a/config/locales/vi.yml b/config/locales/vi.yml index 0d2068be9..9419ef2f6 100644 --- a/config/locales/vi.yml +++ b/config/locales/vi.yml @@ -1074,3 +1074,4 @@ vi: notice_issue_update_conflict: The issue has been updated by an other user while you were editing it. text_issue_conflict_resolution_cancel: Discard all my changes and redisplay %{link} permission_manage_related_issues: Manage related issues + field_ldap_filter: LDAP filter diff --git a/config/locales/zh-TW.yml b/config/locales/zh-TW.yml index 8c373ad6c..7b67bf20f 100644 --- a/config/locales/zh-TW.yml +++ b/config/locales/zh-TW.yml @@ -1103,3 +1103,4 @@ zero: 0 問題 one: 1 問題 other: "%{count} 問題清單" + field_ldap_filter: LDAP filter diff --git a/config/locales/zh.yml b/config/locales/zh.yml index 9da84db9e..7be3096bc 100644 --- a/config/locales/zh.yml +++ b/config/locales/zh.yml @@ -1025,3 +1025,4 @@ zh: notice_issue_update_conflict: The issue has been updated by an other user while you were editing it. text_issue_conflict_resolution_cancel: Discard all my changes and redisplay %{link} permission_manage_related_issues: Manage related issues + field_ldap_filter: LDAP filter diff --git a/db/migrate/20120301153455_add_auth_sources_filter.rb b/db/migrate/20120301153455_add_auth_sources_filter.rb new file mode 100644 index 000000000..617b3b77e --- /dev/null +++ b/db/migrate/20120301153455_add_auth_sources_filter.rb @@ -0,0 +1,9 @@ +class AddAuthSourcesFilter < ActiveRecord::Migration + def self.up + add_column :auth_sources, :filter, :string + end + + def self.down + remove_column :auth_sources, :filter + end +end diff --git a/test/unit/auth_source_ldap_test.rb b/test/unit/auth_source_ldap_test.rb index 5dc532f23..55e1479b8 100644 --- a/test/unit/auth_source_ldap_test.rb +++ b/test/unit/auth_source_ldap_test.rb @@ -18,6 +18,7 @@ require File.expand_path('../../test_helper', __FILE__) class AuthSourceLdapTest < ActiveSupport::TestCase + include Redmine::I18n fixtures :auth_sources def setup @@ -44,6 +45,18 @@ class AuthSourceLdapTest < ActiveSupport::TestCase assert_equal 389, a.port end + def test_filter_should_be_validated + set_language_if_valid 'en' + + a = AuthSourceLdap.new(:name => 'My LDAP', :host => 'ldap.example.net', :port => 389, :attr_login => 'sn') + a.filter = "(mail=*@redmine.org" + assert !a.valid? + assert_equal "is invalid", a.errors[:filter].to_s + + a.filter = "(mail=*@redmine.org)" + assert a.valid? + end + if ldap_configured? context '#authenticate' do setup do @@ -83,6 +96,23 @@ class AuthSourceLdapTest < ActiveSupport::TestCase end end + context 'without filter' do + should 'return any user' do + assert @auth.authenticate('example1','123456') + assert @auth.authenticate('edavis', '123456') + end + end + + context 'with filter' do + setup do + @auth.filter = "(mail=*@redmine.org)" + end + + should 'return user who matches the filter only' do + assert @auth.authenticate('example1','123456') + assert_nil @auth.authenticate('edavis', '123456') + end + end end else puts '(Test LDAP server not configured)'