remove trailing white-spaces from app/models/auth_source_ldap.rb.
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@6512 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
parent
ff8af0ea2e
commit
66a1504db6
|
@ -1,16 +1,16 @@
|
||||||
# redMine - project management software
|
# Redmine - project management software
|
||||||
# Copyright (C) 2006 Jean-Philippe Lang
|
# Copyright (C) 2006-2011 Jean-Philippe Lang
|
||||||
#
|
#
|
||||||
# This program is free software; you can redistribute it and/or
|
# This program is free software; you can redistribute it and/or
|
||||||
# modify it under the terms of the GNU General Public License
|
# modify it under the terms of the GNU General Public License
|
||||||
# as published by the Free Software Foundation; either version 2
|
# as published by the Free Software Foundation; either version 2
|
||||||
# of the License, or (at your option) any later version.
|
# of the License, or (at your option) any later version.
|
||||||
#
|
#
|
||||||
# This program is distributed in the hope that it will be useful,
|
# This program is distributed in the hope that it will be useful,
|
||||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
# GNU General Public License for more details.
|
# GNU General Public License for more details.
|
||||||
#
|
#
|
||||||
# You should have received a copy of the GNU General Public License
|
# You should have received a copy of the GNU General Public License
|
||||||
# along with this program; if not, write to the Free Software
|
# along with this program; if not, write to the Free Software
|
||||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
@ -18,23 +18,23 @@
|
||||||
require 'net/ldap'
|
require 'net/ldap'
|
||||||
require 'iconv'
|
require 'iconv'
|
||||||
|
|
||||||
class AuthSourceLdap < AuthSource
|
class AuthSourceLdap < AuthSource
|
||||||
validates_presence_of :host, :port, :attr_login
|
validates_presence_of :host, :port, :attr_login
|
||||||
validates_length_of :name, :host, :maximum => 60, :allow_nil => true
|
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, :maximum => 255, :allow_nil => true
|
||||||
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
|
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
|
||||||
|
|
||||||
def authenticate(login, password)
|
def authenticate(login, password)
|
||||||
return nil if login.blank? || password.blank?
|
return nil if login.blank? || password.blank?
|
||||||
attrs = get_user_dn(login)
|
attrs = get_user_dn(login)
|
||||||
|
|
||||||
if attrs && attrs[:dn] && authenticate_dn(attrs[:dn], password)
|
if attrs && attrs[:dn] && authenticate_dn(attrs[:dn], password)
|
||||||
logger.debug "Authentication successful for '#{login}'" if logger && logger.debug?
|
logger.debug "Authentication successful for '#{login}'" if logger && logger.debug?
|
||||||
return attrs.except(:dn)
|
return attrs.except(:dn)
|
||||||
|
@ -50,19 +50,19 @@ class AuthSourceLdap < AuthSource
|
||||||
rescue Net::LDAP::LdapError => text
|
rescue Net::LDAP::LdapError => text
|
||||||
raise "LdapError: " + text
|
raise "LdapError: " + text
|
||||||
end
|
end
|
||||||
|
|
||||||
def auth_method_name
|
def auth_method_name
|
||||||
"LDAP"
|
"LDAP"
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def strip_ldap_attributes
|
def strip_ldap_attributes
|
||||||
[:attr_login, :attr_firstname, :attr_lastname, :attr_mail].each do |attr|
|
[:attr_login, :attr_firstname, :attr_lastname, :attr_mail].each do |attr|
|
||||||
write_attribute(attr, read_attribute(attr).strip) unless read_attribute(attr).nil?
|
write_attribute(attr, read_attribute(attr).strip) unless read_attribute(attr).nil?
|
||||||
end
|
end
|
||||||
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,
|
||||||
|
@ -102,12 +102,12 @@ class AuthSourceLdap < AuthSource
|
||||||
# Get the user's dn and any attributes for them, given their login
|
# Get the user's dn and any attributes for them, given their login
|
||||||
def get_user_dn(login)
|
def get_user_dn(login)
|
||||||
ldap_con = initialize_ldap_con(self.account, self.account_password)
|
ldap_con = initialize_ldap_con(self.account, self.account_password)
|
||||||
login_filter = Net::LDAP::Filter.eq( self.attr_login, login )
|
login_filter = Net::LDAP::Filter.eq( self.attr_login, login )
|
||||||
object_filter = Net::LDAP::Filter.eq( "objectClass", "*" )
|
object_filter = Net::LDAP::Filter.eq( "objectClass", "*" )
|
||||||
attrs = {}
|
attrs = {}
|
||||||
|
|
||||||
ldap_con.search( :base => self.base_dn,
|
ldap_con.search( :base => self.base_dn,
|
||||||
:filter => object_filter & login_filter,
|
:filter => object_filter & login_filter,
|
||||||
:attributes=> search_attributes) do |entry|
|
:attributes=> search_attributes) do |entry|
|
||||||
|
|
||||||
if onthefly_register?
|
if onthefly_register?
|
||||||
|
@ -121,7 +121,7 @@ class AuthSourceLdap < AuthSource
|
||||||
|
|
||||||
attrs
|
attrs
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.get_attr(entry, attr_name)
|
def self.get_attr(entry, attr_name)
|
||||||
if !attr_name.blank?
|
if !attr_name.blank?
|
||||||
entry[attr_name].is_a?(Array) ? entry[attr_name].first : entry[attr_name]
|
entry[attr_name].is_a?(Array) ? entry[attr_name].first : entry[attr_name]
|
||||||
|
|
Loading…
Reference in New Issue