diff --git a/plugins/ldap/Gemfile b/plugins/ldap/Gemfile index 7a7eb4a..0508b1d 100644 --- a/plugins/ldap/Gemfile +++ b/plugins/ldap/Gemfile @@ -1,2 +1,2 @@ -gem "net-ldap" +gem "net-ldap", "~> 0.12.1" gem "magic", ">= 0.2.8" diff --git a/plugins/ldap/dependencies.rb b/plugins/ldap/dependencies.rb deleted file mode 100644 index 8fa1559..0000000 --- a/plugins/ldap/dependencies.rb +++ /dev/null @@ -1 +0,0 @@ -require 'net/ldap' diff --git a/plugins/ldap/lib/ldap_authentication.rb b/plugins/ldap/lib/ldap_authentication.rb index e403171..b0ab307 100644 --- a/plugins/ldap/lib/ldap_authentication.rb +++ b/plugins/ldap/lib/ldap_authentication.rb @@ -15,7 +15,6 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -require 'iconv' require 'net/ldap' require 'net/ldap/dn' require 'magic' @@ -111,7 +110,14 @@ class LdapAuthentication else ldap_con = initialize_ldap_con(self.account, self.account_password) end - login_filter = Net::LDAP::Filter.eq( self.attr_login, login ) + login_filter = nil + (self.attr_login || []).split.each do |attr| + if(login_filter.nil?) + login_filter = Net::LDAP::Filter.eq( attr, login ) + else + login_filter = login_filter | Net::LDAP::Filter.eq( attr, login ) + end + end object_filter = Net::LDAP::Filter.eq( "objectClass", "*" ) attrs = {} diff --git a/plugins/ldap/lib/ldap_plugin.rb b/plugins/ldap/lib/ldap_plugin.rb index 09428f3..306743b 100644 --- a/plugins/ldap/lib/ldap_plugin.rb +++ b/plugins/ldap/lib/ldap_plugin.rb @@ -55,7 +55,7 @@ class LdapPlugin < Noosfero::Plugin end if attrs - user.login = login + user.login = get_login(attrs, ldap.attr_login, login) user.email = get_email(attrs, login) user.name = attrs[:fullname] user.password = password @@ -94,6 +94,11 @@ class LdapPlugin < Noosfero::Plugin user end + def get_login(attrs, attr_login, login) + user_login = Array.wrap(attrs[attr_login.split.first.to_sym]) + user_login.empty? ? login : user_login.first + end + def get_email(attrs, login) return attrs[:mail] unless attrs[:mail].blank? diff --git a/plugins/ldap/test/unit/ldap_plugin_test.rb b/plugins/ldap/test/unit/ldap_plugin_test.rb index d8e2475..0e3ac67 100644 --- a/plugins/ldap/test/unit/ldap_plugin_test.rb +++ b/plugins/ldap/test/unit/ldap_plugin_test.rb @@ -14,4 +14,24 @@ class LdapPluginTest < ActiveSupport::TestCase refute plugin.allow_password_recovery end + should 'return login when exists a login attribute returned by ldap' do + plugin = LdapPlugin.new + assert_equal 'test', plugin.get_login({:uid => 'test'}, 'uid', 'test2') + end + + should 'return the attribute configured by attr_login when the attribute exists' do + plugin = LdapPlugin.new + assert_equal 'test', plugin.get_login({:uid => 'test'}, 'uid', 'test2') + end + + should 'return login when the ldap attribute does not exists' do + plugin = LdapPlugin.new + assert_equal 'test2', plugin.get_login({:uid => 'test'}, 'mail', 'test2') + end + + should 'use the first word at attr_login as the login key' do + plugin = LdapPlugin.new + assert_equal 'test', plugin.get_login({:uid => 'test', :mail => 'test@test'}, 'uid mail', 'test2') + end + end -- libgit2 0.21.2