Module: LdapQuery::LdapHelper
- Defined in:
- lib/ldap_query/ldap_helper.rb
Overview
Methods to be included as helpers in the rails application
Class Method Summary collapse
Instance Method Summary collapse
-
#authenticate_user(credentials, username: nil, password: '') ⇒ Object
Used to authenticate a user against ldap.
-
#search_ldap_by_group(str, credentials = {}, wildcard: false, limit: 20) ⇒ Object
Query ldap based on memberof attribute.
-
#search_ldap_by_mail(str, credentials = {}, wildcard: false, limit: 20) ⇒ Object
Query ldap based on mail attribute.
-
#search_ldap_by_name(str, credentials = {}, wildcard: false, limit: 20) ⇒ Object
Query LDAP based on all users displayname attribute.
-
#search_ldap_by_other(credentials = {}, attr: nil, val: nil, wildcard: false, limit: 20) ⇒ Object
Query LDAP against a custome attribute and value.
-
#search_ldap_by_username(str, credentials = {}, wildcard: false, limit: 20) ⇒ Object
Search ldap based on users samaccountname attribute.
Class Method Details
.extended(base) ⇒ Object
7 |
# File 'lib/ldap_query/ldap_helper.rb', line 7 def self.extended(base); end |
.included(base) ⇒ Object
6 |
# File 'lib/ldap_query/ldap_helper.rb', line 6 def self.included(base); end |
Instance Method Details
#authenticate_user(credentials, username: nil, password: '') ⇒ Object
Used to authenticate a user against ldap
65 66 67 68 69 70 71 |
# File 'lib/ldap_query/ldap_helper.rb', line 65 def authenticate_user(credentials, username: nil, password: '') username, password = username.to_s, password.to_s credentials = determine_credentials(credentials) raise(AttributeError, 'an ldap username is required in order to authenticate.') if username.nil? LdapQuery::Authenticate.new(credentials).auth_user(username, password) end |
#search_ldap_by_group(str, credentials = {}, wildcard: false, limit: 20) ⇒ Object
Query ldap based on memberof attribute
32 33 34 35 |
# File 'lib/ldap_query/ldap_helper.rb', line 32 def search_ldap_by_group(str, credentials = {}, wildcard: false, limit: 20) credentials = determine_credentials(credentials) LdapQuery::Query.perform(credentials, attr: :memberof, val: str, wildcard: wildcard, limit: limit) end |
#search_ldap_by_mail(str, credentials = {}, wildcard: false, limit: 20) ⇒ Object
Query ldap based on mail attribute
55 56 57 58 |
# File 'lib/ldap_query/ldap_helper.rb', line 55 def search_ldap_by_mail(str, credentials = {}, wildcard: false, limit: 20) credentials = determine_credentials(credentials) LdapQuery::Query.perform(credentials, attr: :mail, val: str, wildcard: wildcard, limit: limit) end |
#search_ldap_by_name(str, credentials = {}, wildcard: false, limit: 20) ⇒ Object
Query LDAP based on all users displayname attribute
22 23 24 25 |
# File 'lib/ldap_query/ldap_helper.rb', line 22 def search_ldap_by_name(str, credentials = {}, wildcard: false, limit: 20) credentials = determine_credentials(credentials) LdapQuery::Query.perform(credentials, attr: :displayname, val: str, wildcard: wildcard, limit: limit) end |
#search_ldap_by_other(credentials = {}, attr: nil, val: nil, wildcard: false, limit: 20) ⇒ Object
Query LDAP against a custome attribute and value
43 44 45 46 47 48 |
# File 'lib/ldap_query/ldap_helper.rb', line 43 def search_ldap_by_other(credentials = {}, attr: nil, val: nil, wildcard: false, limit: 20) raise(AttributeError, 'a valid attribute name and value must be supplied to query against') if attr.nil? || val.nil? credentials = determine_credentials(credentials) LdapQuery::Query.perform(credentials, attr: attr, val: val, wildcard: wildcard, limit: limit) end |
#search_ldap_by_username(str, credentials = {}, wildcard: false, limit: 20) ⇒ Object
Search ldap based on users samaccountname attribute
13 14 15 16 |
# File 'lib/ldap_query/ldap_helper.rb', line 13 def search_ldap_by_username(str, credentials = {}, wildcard: false, limit: 20) credentials = determine_credentials(credentials) LdapQuery::Query.perform(credentials, attr: :cn, val: str, wildcard: wildcard, limit: limit) end |