Strip LDAP attribute names before saving (#1890).
git-svn-id: http://redmine.rubyforge.org/svn/trunk@1894 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
parent
8a356baf3e
commit
b09a18972d
|
@ -25,6 +25,8 @@ class AuthSourceLdap < AuthSource
|
||||||
validates_length_of :attr_login, :attr_firstname, :attr_lastname, :attr_mail, :maximum => 30, :allow_nil => true
|
validates_length_of :attr_login, :attr_firstname, :attr_lastname, :attr_mail, :maximum => 30, :allow_nil => true
|
||||||
validates_numericality_of :port, :only_integer => true
|
validates_numericality_of :port, :only_integer => true
|
||||||
|
|
||||||
|
before_validation :strip_ldap_attributes
|
||||||
|
|
||||||
def after_initialize
|
def after_initialize
|
||||||
self.port = 389 if self.port == 0
|
self.port = 389 if self.port == 0
|
||||||
end
|
end
|
||||||
|
@ -71,7 +73,14 @@ class AuthSourceLdap < AuthSource
|
||||||
"LDAP"
|
"LDAP"
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
|
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?
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def initialize_ldap_con(ldap_user, ldap_password)
|
def initialize_ldap_con(ldap_user, ldap_password)
|
||||||
options = { :host => self.host,
|
options = { :host => self.host,
|
||||||
:port => self.port,
|
:port => self.port,
|
||||||
|
|
|
@ -0,0 +1,36 @@
|
||||||
|
# Redmine - project management software
|
||||||
|
# Copyright (C) 2006-2008 Jean-Philippe Lang
|
||||||
|
#
|
||||||
|
# This program is free software; you can redistribute it and/or
|
||||||
|
# modify it under the terms of the GNU General Public License
|
||||||
|
# as published by the Free Software Foundation; either version 2
|
||||||
|
# of the License, or (at your option) any later version.
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with this program; if not, write to the Free Software
|
||||||
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
|
||||||
|
require File.dirname(__FILE__) + '/../test_helper'
|
||||||
|
|
||||||
|
class AuthSourceLdapTest < Test::Unit::TestCase
|
||||||
|
|
||||||
|
def setup
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_create
|
||||||
|
a = AuthSourceLdap.new(:name => 'My LDAP', :host => 'ldap.example.net', :port => 389, :base_dn => 'dc=example,dc=net', :attr_login => 'sAMAccountName')
|
||||||
|
assert a.save
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_should_strip_ldap_attributes
|
||||||
|
a = AuthSourceLdap.new(:name => 'My LDAP', :host => 'ldap.example.net', :port => 389, :base_dn => 'dc=example,dc=net', :attr_login => 'sAMAccountName',
|
||||||
|
:attr_firstname => 'givenName ')
|
||||||
|
assert a.save
|
||||||
|
assert_equal 'givenName', a.reload.attr_firstname
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in New Issue