Module: AdDir

Defined in:
lib/ad_dir.rb,
lib/ad_dir/user.rb,
lib/ad_dir/entry.rb,
lib/ad_dir/group.rb,
lib/ad_dir/version.rb,
lib/ad_dir/utilities.rb,
lib/ad_dir/derived_attributes.rb,
lib/ad_dir/common_user_attributes.rb

Overview

User Model

Defined Under Namespace

Modules: CommonUserAttributes, DerivedAttributes, Utilities Classes: Entry, Group, User

Constant Summary collapse

VERSION =

ad_dir version

'0.9.10'

Class Method Summary collapse

Class Method Details

.connectionObject

Returns a Net::LDAP object (@see Net::LDAP ). If no connection was established it raises a RuntimeError.


56
57
58
59
60
61
# File 'lib/ad_dir.rb', line 56

def connection
  return @connection if @connection
  warn 'ERROR: Use \'AdDir#establish_connection\' first to connect \
to your Active Directory.'
  fail 'No connection set up!'
end

.establish_connection(host:, username:, password:, base:) ⇒ Object

Establishes a connection to the ActiveDirectory running on host using the credentials username/password.

The connection is a Net::LDAP.connection. As any ActiveDirectory is always run with encrypted connections, the following options are preset:

port: 636
encryption: { method: :simple_tls }
auth_method: :simple

(check out the net-ldap API for details).

Examples:

Initialize a connection to an ActiveDirectory

AdDir.establish_connection(
  host:     'my.nice.com',
  base:     'dc=my,dc=nice,dc=com',
  username: 'cn=manager,dc=example,dc=com',
  password: 'opensesame'
  )

42
43
44
45
46
47
48
49
50
51
52
# File 'lib/ad_dir.rb', line 42

def establish_connection(host:, username:, password:, base:)
  @connection = Net::LDAP.new(
    host: host, base: base,
    encryption: { method: :simple_tls },
    port: 636,
    auth: {
      username: username, password: password,
      method: :simple }
  )
  @connection.bind
end

.last_opObject

Get the status of the last operation. Alias/Shortcut for AdDir.connection.get_operation_result


65
66
67
# File 'lib/ad_dir.rb', line 65

def last_op
  @connection && @connection.get_operation_result
end