Class: LdapQuery::Filter
- Inherits:
-
Object
- Object
- LdapQuery::Filter
- Defined in:
- lib/ldap_query/filter.rb
Overview
Used to create return LDAP query stings depending on what attribute you want to filter
Class Method Summary collapse
-
.auth(username) ⇒ Object
Filter used to authenticate a validate CN & Person entry.
-
.clean_str(str, wildcard: false) ⇒ String
If you want to wildcard it this turns all spaces into '' and adds '' at the beginning and end of the str as well.
-
.object_class(str = 'person', wildcard: false) ⇒ Object
Generally most ldap queries are again person, sometimes other types will be used for service accounts.
-
.other(attr, val, wildcard: false) ⇒ Object
Used to filter LDAP accounts against a custom attribute and valuess.
-
.person(username, wildcard: false) ⇒ Object
Filter user based on CN attribute (CN is a required attribute).
Class Method Details
.auth(username) ⇒ Object
Filter used to authenticate a validate CN & Person entry
52 53 54 |
# File 'lib/ldap_query/filter.rb', line 52 def self.auth(username) Net::LDAP::Filter.join(cn(username), object_class) end |
.clean_str(str, wildcard: false) ⇒ String
If you want to wildcard it this turns all spaces into '' and adds '' at the beginning and end of the str as well
61 62 63 64 65 66 67 |
# File 'lib/ldap_query/filter.rb', line 61 def self.clean_str(str, wildcard: false) str = str&.strip return str unless wildcard && str.is_a?(String) str = str.split(/\s/).compact.join('*').squeeze('*') "*#{str}*" end |
.object_class(str = 'person', wildcard: false) ⇒ Object
Generally most ldap queries are again person, sometimes other types will be used for service accounts
26 27 28 |
# File 'lib/ldap_query/filter.rb', line 26 def self.object_class(str = 'person', wildcard: false) Net::LDAP::Filter.eq('objectClass', clean_str(str, wildcard: wildcard)) end |
.other(attr, val, wildcard: false) ⇒ Object
Used to filter LDAP accounts against a custom attribute and valuess
35 36 37 |
# File 'lib/ldap_query/filter.rb', line 35 def self.other(attr, val, wildcard: false) Net::LDAP::Filter.eq(attr, clean_str(val, wildcard: wildcard)) end |
.person(username, wildcard: false) ⇒ Object
Filter user based on CN attribute (CN is a required attribute)
43 44 45 46 47 |
# File 'lib/ldap_query/filter.rb', line 43 def self.person(username, wildcard: false) cn_filter = LdapQuery::Filter.cn(username, wildcard: wildcard) user_filter = LdapQuery::Filter.object_class Net::LDAP::Filter.join(cn_filter, user_filter) end |