diff --git a/app/models/auth_source_ldap.rb b/app/models/auth_source_ldap.rb
index d009ae33..1e2bf243 100644
--- a/app/models/auth_source_ldap.rb
+++ b/app/models/auth_source_ldap.rb
@@ -101,10 +101,17 @@ class AuthSourceLdap < AuthSource
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", "*" )
- attrs = {}
+ custom_ldap_filter = custom_filter_to_ldap
- ldap_con.search( :base => self.base_dn,
- :filter => object_filter & login_filter,
+ if custom_ldap_filter.present?
+ search_filters = object_filter & login_filter & custom_ldap_filter
+ else
+ search_filters = object_filter & login_filter
+ end
+ attrs = {}
+
+ ldap_con.search( :base => self.base_dn,
+ :filter => search_filters,
:attributes=> search_attributes) do |entry|
if onthefly_register?
@@ -119,6 +126,17 @@ class AuthSourceLdap < AuthSource
attrs
end
+ def custom_filter_to_ldap
+ return nil unless custom_filter.present?
+
+ begin
+ return Net::LDAP::Filter.construct(custom_filter)
+ rescue Net::LDAP::LdapError # Filter syntax error
+ logger.debug "LDAP custom filter syntax error for: #{custom_filter}" if logger && logger.debug?
+ return nil
+ end
+ end
+
def self.get_attr(entry, attr_name)
if !attr_name.blank?
entry[attr_name].is_a?(Array) ? entry[attr_name].first : entry[attr_name]
diff --git a/app/views/ldap_auth_sources/_form.rhtml b/app/views/ldap_auth_sources/_form.rhtml
index 9ffffafc..ef0fd5b1 100644
--- a/app/views/ldap_auth_sources/_form.rhtml
+++ b/app/views/ldap_auth_sources/_form.rhtml
@@ -25,6 +25,9 @@
<%= check_box 'auth_source', 'onthefly_register' %>
+
+
+<%= text_field 'auth_source', 'custom_filter', :size => 60 %>