Class: LdapServer

Inherits:
ApplicationRecord
  • Object
show all
Includes:
Api::LdapServer, RailsAdmin::LdapServer
Defined in:
app/models/ldap_server.rb

Instance Method Summary collapse

Instance Method Details

#test_connectionObject



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'app/models/ldap_server.rb', line 16

def test_connection
  # Test the connection to the LDAP server
  ldap = Net::LDAP.new(
    host: host,
    port: port,
    encryption: use_ssl ? :simple_tls : nil,
    auth: {
      method: :simple,
      username: admin_user,
      password: admin_password
    }
  )
  # Perform a simple bind to check the connection
  if ldap.bind
    # Connection successful
    Rails.logger.info "Connection to LDAP server #{host} successful."
  else
    # Connection failed
    Rails.logger.info "Connection to LDAP server #{host} failed: #{ldap.get_operation_result.message}"
  end
end