Class: HolmanActiveDirectory::Directory
- Inherits:
-
Object
- Object
- HolmanActiveDirectory::Directory
- Defined in:
- lib/holman_active_directory/directory.rb
Constant Summary collapse
- SSO_AUTH =
{ auth: { method: :sasl, mechanism: 'GSS-SPNEGO' } }
Instance Attribute Summary collapse
-
#base ⇒ Object
readonly
Returns the value of attribute base.
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
- #active_account?(dn) ⇒ Boolean
- #connection(service = Net::LDAP) ⇒ Object
- #employee_id_filter(employee_id) ⇒ Object
-
#initialize(name, employee_id_filter, configs = HolmanActiveDirectory.server_configs) ⇒ Directory
constructor
A new instance of Directory.
- #last_operation_message ⇒ Object
- #last_operation_result ⇒ Object
- #last_operation_status ⇒ Object
-
#last_operation_success? ⇒ Boolean
Last Operation helpers.
- #search(options) ⇒ Object
- #search_for_employee_id(employee_id, options = {}) ⇒ Object
- #search_for_username(username, options = {}) ⇒ Object
- #sso_config ⇒ Object
- #sso_connection(service = Net::LDAP) ⇒ Object
- #test_active_account? ⇒ Boolean
-
#test_bind ⇒ Object
Some simple tests to check connections.
- #test_search_for_employee_id ⇒ Object
- #test_search_for_username ⇒ Object
- #updatable? ⇒ Boolean
- #update(dn, operations) ⇒ Object
- #valid_password?(dn, password) ⇒ Boolean
Constructor Details
#initialize(name, employee_id_filter, configs = HolmanActiveDirectory.server_configs) ⇒ Directory
Returns a new instance of Directory.
5 6 7 8 9 10 |
# File 'lib/holman_active_directory/directory.rb', line 5 def initialize(name, employee_id_filter, configs=HolmanActiveDirectory.server_configs) @name = name @employee_id_filter = employee_id_filter @config = configs[name] @base = config[:base] end |
Instance Attribute Details
#base ⇒ Object (readonly)
Returns the value of attribute base.
3 4 5 |
# File 'lib/holman_active_directory/directory.rb', line 3 def base @base end |
#config ⇒ Object (readonly)
Returns the value of attribute config.
3 4 5 |
# File 'lib/holman_active_directory/directory.rb', line 3 def config @config end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
3 4 5 |
# File 'lib/holman_active_directory/directory.rb', line 3 def name @name end |
Instance Method Details
#active_account?(dn) ⇒ Boolean
24 25 26 |
# File 'lib/holman_active_directory/directory.rb', line 24 def active_account?(dn) !!search(base: dn, filter: Filter.active_user, attributes: '') end |
#connection(service = Net::LDAP) ⇒ Object
46 47 48 |
# File 'lib/holman_active_directory/directory.rb', line 46 def connection(service=Net::LDAP) @connection ||= service.new config end |
#employee_id_filter(employee_id) ⇒ Object
42 43 44 |
# File 'lib/holman_active_directory/directory.rb', line 42 def employee_id_filter(employee_id) @employee_id_filter.(employee_id) end |
#last_operation_message ⇒ Object
66 67 68 |
# File 'lib/holman_active_directory/directory.rb', line 66 def last_operation_result. end |
#last_operation_result ⇒ Object
74 75 76 |
# File 'lib/holman_active_directory/directory.rb', line 74 def last_operation_result connection.get_operation_result end |
#last_operation_status ⇒ Object
70 71 72 |
# File 'lib/holman_active_directory/directory.rb', line 70 def last_operation_status last_operation_result.code end |
#last_operation_success? ⇒ Boolean
Last Operation helpers
62 63 64 |
# File 'lib/holman_active_directory/directory.rb', line 62 def last_operation_success? last_operation_status == 0 end |
#search(options) ⇒ Object
12 13 14 |
# File 'lib/holman_active_directory/directory.rb', line 12 def search() connection.search({ base: base }.merge()) end |
#search_for_employee_id(employee_id, options = {}) ⇒ Object
16 17 18 |
# File 'lib/holman_active_directory/directory.rb', line 16 def search_for_employee_id(employee_id, ={}) search({ filter: employee_id_filter(employee_id) & Filter.user }.merge()) end |
#search_for_username(username, options = {}) ⇒ Object
20 21 22 |
# File 'lib/holman_active_directory/directory.rb', line 20 def search_for_username(username, ={}) search({ filter: Filter.eq('samaccountname', username) & Filter.user }.merge ) end |
#sso_config ⇒ Object
56 57 58 |
# File 'lib/holman_active_directory/directory.rb', line 56 def sso_config config.merge SSO_AUTH end |
#sso_connection(service = Net::LDAP) ⇒ Object
50 51 52 |
# File 'lib/holman_active_directory/directory.rb', line 50 def sso_connection(service=Net::LDAP) @sso_connection ||= service.new sso_config end |
#test_active_account? ⇒ Boolean
95 96 97 98 99 100 101 |
# File 'lib/holman_active_directory/directory.rb', line 95 def test_active_account? results = search(filter: Filter.active_user, attributes: '', size: 1) user = results && results.first return if user.nil? active_account?(user.dn) end |
#test_bind ⇒ Object
Some simple tests to check connections
80 81 82 83 |
# File 'lib/holman_active_directory/directory.rb', line 80 def test_bind connection.bind end |
#test_search_for_employee_id ⇒ Object
85 86 87 88 |
# File 'lib/holman_active_directory/directory.rb', line 85 def test_search_for_employee_id search_for_employee_id(0) == [] end |
#test_search_for_username ⇒ Object
90 91 92 93 |
# File 'lib/holman_active_directory/directory.rb', line 90 def test_search_for_username search_for_username('arglebargle') == [] end |
#updatable? ⇒ Boolean
38 39 40 |
# File 'lib/holman_active_directory/directory.rb', line 38 def updatable? !!config[:updatable] end |
#update(dn, operations) ⇒ Object
32 33 34 35 36 |
# File 'lib/holman_active_directory/directory.rb', line 32 def update(dn, operations) return false unless updatable? connection.modify dn: dn, operations: operations last_operation_result end |
#valid_password?(dn, password) ⇒ Boolean
28 29 30 |
# File 'lib/holman_active_directory/directory.rb', line 28 def valid_password?(dn, password) connection.bind method: :simple, username: dn, password: password end |