mirror of
https://github.com/redmine/redmine.git
synced 2026-03-06 12:31:40 +01:00
Fixed: Roadmap crashes when a version has a due date > 2037. r18646@gaspard (orig r1888): jplang | 2008-09-21 10:54:02 +0200 Fixed: invalid effective date (eg. 99999-01-01) causes an error on version edition screen. r18647@gaspard (orig r1889): jplang | 2008-09-21 10:54:50 +0200 Fixes VersionTest class. r18648@gaspard (orig r1890): jplang | 2008-09-21 14:07:44 +0200 Fixed: login filter providing incorrect back_url for Redmine installed in sub-directory (#1900). r18649@gaspard (orig r1891): winterheart | 2008-09-21 14:31:34 +0200 de.yml from #1745, thank to Sven Schuchmann and Thomas Löber for contribution r18650@gaspard (orig r1892): winterheart | 2008-09-21 14:32:16 +0200 #1928, update for Italian language r18651@gaspard (orig r1893): jplang | 2008-09-21 14:45:22 +0200 Unescape back_url param before calling redirect_to. r18652@gaspard (orig r1894): jplang | 2008-09-21 15:28:12 +0200 Strip LDAP attribute names before saving (#1890). r18653@gaspard (orig r1895): jplang | 2008-09-21 20:45:30 +0200 Switch order of current and previous revisions in side-by-side diff (#1903). r18654@gaspard (orig r1896): jplang | 2008-09-21 22:38:36 +0200 Typo in migration 97 name (#1929). r18655@gaspard (orig r1897): winterheart | 2008-09-22 16:49:18 +0200 #1921, pt translation git-svn-id: http://redmine.rubyforge.org/svn/branches/nbc@1898 e93f8b46-1217-0410-a6f0-8f06a7374b81
97 lines
3.7 KiB
Ruby
97 lines
3.7 KiB
Ruby
# redMine - project management software
|
|
# Copyright (C) 2006 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 'net/ldap'
|
|
require 'iconv'
|
|
|
|
class AuthSourceLdap < AuthSource
|
|
validates_presence_of :host, :port, :attr_login
|
|
validates_length_of :name, :host, :account_password, :maximum => 60, :allow_nil => true
|
|
validates_length_of :account, :base_dn, :maximum => 255, :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
|
|
|
|
before_validation :strip_ldap_attributes
|
|
|
|
def after_initialize
|
|
self.port = 389 if self.port == 0
|
|
end
|
|
|
|
def authenticate(login, password)
|
|
return nil if login.blank? || password.blank?
|
|
attrs = []
|
|
# get user's DN
|
|
ldap_con = initialize_ldap_con(self.account, self.account_password)
|
|
login_filter = Net::LDAP::Filter.eq( self.attr_login, login )
|
|
object_filter = Net::LDAP::Filter.eq( "objectClass", "*" )
|
|
dn = String.new
|
|
ldap_con.search( :base => self.base_dn,
|
|
:filter => object_filter & login_filter,
|
|
# only ask for the DN if on-the-fly registration is disabled
|
|
:attributes=> (onthefly_register? ? ['dn', self.attr_firstname, self.attr_lastname, self.attr_mail] : ['dn'])) do |entry|
|
|
dn = entry.dn
|
|
attrs = [:firstname => AuthSourceLdap.get_attr(entry, self.attr_firstname),
|
|
:lastname => AuthSourceLdap.get_attr(entry, self.attr_lastname),
|
|
:mail => AuthSourceLdap.get_attr(entry, self.attr_mail),
|
|
:auth_source_id => self.id ] if onthefly_register?
|
|
end
|
|
return nil if dn.empty?
|
|
logger.debug "DN found for #{login}: #{dn}" if logger && logger.debug?
|
|
# authenticate user
|
|
ldap_con = initialize_ldap_con(dn, password)
|
|
return nil unless ldap_con.bind
|
|
# return user's attributes
|
|
logger.debug "Authentication successful for '#{login}'" if logger && logger.debug?
|
|
attrs
|
|
rescue Net::LDAP::LdapError => text
|
|
raise "LdapError: " + text
|
|
end
|
|
|
|
# test the connection to the LDAP
|
|
def test_connection
|
|
ldap_con = initialize_ldap_con(self.account, self.account_password)
|
|
ldap_con.open { }
|
|
rescue Net::LDAP::LdapError => text
|
|
raise "LdapError: " + text
|
|
end
|
|
|
|
def auth_method_name
|
|
"LDAP"
|
|
end
|
|
|
|
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)
|
|
options = { :host => self.host,
|
|
:port => self.port,
|
|
:encryption => (self.tls ? :simple_tls : nil)
|
|
}
|
|
options.merge!(:auth => { :method => :simple, :username => ldap_user, :password => ldap_password }) unless ldap_user.blank? && ldap_password.blank?
|
|
Net::LDAP.new options
|
|
end
|
|
|
|
def self.get_attr(entry, attr_name)
|
|
entry[attr_name].is_a?(Array) ? entry[attr_name].first : entry[attr_name]
|
|
end
|
|
end
|