Project

General

Profile

Feature #1060 » ldap_filter.x3n.patch

Lionel Molinier, 2008-04-15 09:01

View differences:

redmine-0.6.3-patched/app/models/auth_source.rb 2008-04-14 11:44:53.000000000 +0200
22 22
  validates_uniqueness_of :name
23 23
  validates_length_of :name, :host, :maximum => 60
24 24
  validates_length_of :account_password, :maximum => 60, :allow_nil => true
25
  validates_length_of :account, :base_dn, :maximum => 255
25
  validates_length_of :account, :base_dn, :filter, :maximum => 255
26 26
  validates_length_of :attr_login, :attr_firstname, :attr_lastname, :attr_mail, :maximum => 30
27 27

  
28 28
  def authenticate(login, password)
redmine-0.6.3-patched/app/models/auth_source_ldap.rb 2008-04-14 11:44:53.000000000 +0200
19 19
require 'iconv'
20 20

  
21 21
class AuthSourceLdap < AuthSource 
22
  validates_presence_of :host, :port, :attr_login
22
  validates_presence_of :host, :port, :filter, :attr_login
23 23
  validates_presence_of :attr_firstname, :attr_lastname, :attr_mail, :if => Proc.new { |a| a.onthefly_register? }
24 24
  
25 25
  def after_initialize
26 26
    self.port = 389 if self.port == 0
27
		self.filter = "()" if self.filter == ""
27 28
  end
28 29
  
29 30
  def authenticate(login, password)
......
32 33
    ldap_con = initialize_ldap_con(self.account, self.account_password)
33 34
    login_filter = Net::LDAP::Filter.eq( self.attr_login, login ) 
34 35
    object_filter = Net::LDAP::Filter.eq( "objectClass", "*" ) 
36

  
37
		# Add the user defined filter
38
		custom_filter = Net::LDAP::Filter.construct( self.filter )
39

  
35 40
    dn = String.new
36 41
    ldap_con.search( :base => self.base_dn, 
37
                     :filter => object_filter & login_filter, 
42
                     :filter => object_filter & login_filter & custom_filter, 
38 43
                     # only ask for the DN if on-the-fly registration is disabled
39 44
                     :attributes=> (onthefly_register? ? ['dn', self.attr_firstname, self.attr_lastname, self.attr_mail] : ['dn'])) do |entry|
40 45
      dn = entry.dn
redmine-0.6.3-patched/app/views/auth_sources/_form.rhtml 2008-04-14 11:44:53.000000000 +0200
22 22

  
23 23
<p><label for="auth_source_base_dn"><%=l(:field_base_dn)%> <span class="required">*</span></label>
24 24
<%= text_field 'auth_source', 'base_dn', :size => 60 %></p>
25

  
26
<p><label for="auth_source_filter"><%=l(:field_filter)%></label>
27
<%= text_field 'auth_source', 'filter', :size => 60 %></p>
25 28
</div>
26 29

  
27 30
<div class="box">
redmine-0.6.3-patched/db/migrate/001_setup.rb 2008-04-14 11:44:53.000000000 +0200
42 42
      t.column "account", :string, :limit => 60
43 43
      t.column "account_password", :string, :limit => 60
44 44
      t.column "base_dn", :string, :limit => 255
45
      t.column "filter", :string, :limit => 255
45 46
      t.column "attr_login", :string, :limit => 30
46 47
      t.column "attr_firstname", :string, :limit => 30
47 48
      t.column "attr_lastname", :string, :limit => 30
redmine-0.6.3-patched/lang/en.yml 2008-04-14 11:45:24.000000000 +0200
145 145
field_port: Port
146 146
field_account: Account
147 147
field_base_dn: Base DN
148
field_filter: Filter
148 149
field_attr_login: Login attribute
149 150
field_attr_firstname: Firstname attribute
150 151
field_attr_lastname: Lastname attribute
redmine-0.6.3-patched/lang/fr.yml 2008-04-14 11:45:24.000000000 +0200
145 145
field_port: Port
146 146
field_account: Compte
147 147
field_base_dn: Base DN
148
field_filter: Filtre
148 149
field_attr_login: Attribut Identifiant
149 150
field_attr_firstname: Attribut Prénom
150 151
field_attr_lastname: Attribut Nom
(1-1/4)