ChiliProject is not maintained anymore. Please be advised that there will be no more updates.

We do not recommend that you setup new ChiliProject instances and we urge all existing users to migrate their data to a maintained system, e.g. Redmine. We will provide a migration script later. In the meantime, you can use the instructions by Christian Daehn.

ldap_filter_r5657.patch

Florian Mutter, 2011-05-09 04:00 pm

Download (3.7 kB)

 
app/models/auth_source_ldap.rb (working copy)
21 21
require 'iconv'
22 22
class AuthSourceLdap < AuthSource 
23 23
  validates_presence_of :host, :port, :attr_login
24 24
  validates_length_of :name, :host, :account_password, :maximum => 60, :allow_nil => true
25
  validates_length_of :account, :base_dn, :maximum => 255, :allow_nil => true
25
  validates_length_of :account, :base_dn, :filter, :maximum => 255, :allow_nil => true
26 26
  validates_length_of :attr_login, :attr_firstname, :attr_lastname, :attr_mail, :maximum => 30, :allow_nil => true
27 27
  validates_numericality_of :port, :only_integer => true
28 28
  
......
104 104
    ldap_con = initialize_ldap_con(self.account, self.account_password)
105 105
    login_filter = Net::LDAP::Filter.eq( self.attr_login, login ) 
106 106
    object_filter = Net::LDAP::Filter.eq( "objectClass", "*" ) 
107

  
108
    ldap_filter = login_filter & object_filter
109
    if not self.filter.blank?
110
      begin
111
        custom_filter = Net::LDAP::Filter.construct( self.filter )
112
        ldap_filter = ldap_filter & custom_filter
113
      rescue Net::LDAP::LdapError => e
114
        logger.error "Error during authentication: #{e.message}"
115
        return nil
116
      end
117
    end
118

  
107 119
    attrs = {}
108 120
    
109 121
    ldap_con.search( :base => self.base_dn, 
110
                     :filter => object_filter & login_filter, 
122
                     :filter => ldap_filter,
111 123
                     :attributes=> search_attributes) do |entry|
112 124

  
113 125
      if onthefly_register?
app/views/ldap_auth_sources/_form.rhtml (working copy)
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 25

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

  
26 29
<p><label for="auth_source_onthefly_register"><%=l(:field_onthefly)%></label>
27 30
<%= check_box 'auth_source', 'onthefly_register' %></p>
28 31
</div>
db/migrate/001_setup.rb (working copy)
43 43
      t.column "account", :string, :limit => 60
44 44
      t.column "account_password", :string, :limit => 60
45 45
      t.column "base_dn", :string, :limit => 255
46
      t.column "filter", :string, :limit => 255
46 47
      t.column "attr_login", :string, :limit => 30
47 48
      t.column "attr_firstname", :string, :limit => 30
48 49
      t.column "attr_lastname", :string, :limit => 30
db/migrate/20110505224753_add_filter_to_auth_sources.rb (revision 0)
1
class AddFilterToAuthSources < ActiveRecord::Migration
2
  def self.up
3
    add_column :auth_sources, :filter, :string, :limit => 255
4
  end
5

  
6
  def self.down
7
    remove_column :auth_sources, :filter
8
  end
9
end
10

  
config/locales/en.yml (working copy)
265 265
  field_port: Port
266 266
  field_account: Account
267 267
  field_base_dn: Base DN
268
  field_filter: Filter
268 269
  field_attr_login: Login attribute
269 270
  field_attr_firstname: Firstname attribute
270 271
  field_attr_lastname: Lastname attribute