ad 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 4bd4417ce6b70730a53c508683d9dc8e0d91cde5
4
+ data.tar.gz: bea2eb05bdae09de3463e819323dd9c6c6634980
5
+ SHA512:
6
+ metadata.gz: 7ff571090b447362238b6f5c954761cda1ba15145575cb61bac5a618de3bb1022d142507ed46869ffa84467784df0f217a39f722ec5e62ba8cbcee364d41e0f4
7
+ data.tar.gz: e2f1bfe0b6ae3451f02f02e153f77796bbf70d12d821de66efdfbcc4488f0a4d133de4a9f31648ddd332ee045dc009ffcb5ad9c5441a8ad5d7bf2c0fbdccdfe3
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "net/ldap"
4
+ require "net/ldap/dn"
5
+
6
+ require "active_support"
7
+ require "active_support/core_ext/object/blank"
8
+ require "active_support/core_ext/string/strip"
9
+
10
+ require "ad/version"
11
+ require "ad/connection_factory"
12
+ require "ad/authentication"
13
+ require "ad/record_finder"
14
+
15
+ module AD
16
+ CONFIG_ATTRS = [:host, :port, :service_user_dn, :service_user_password, :base_dn, :unique_id_attr, :instrumentation_service].freeze
17
+ DEFAULT_UNIQUE_ID_ATTR = "samaccountname"
18
+ DEFAULT_HOST = "127.0.0.1"
19
+ DEFAULT_PORT = 389
20
+ class << self
21
+ attr_accessor(*CONFIG_ATTRS)
22
+
23
+ def configure
24
+ yield self
25
+ end
26
+
27
+ def reset!
28
+ CONFIG_ATTRS.each do |attr|
29
+ send("#{attr}=", nil)
30
+ end
31
+ self.host = DEFAULT_HOST
32
+ self.port = DEFAULT_PORT
33
+ self.unique_id_attr = DEFAULT_UNIQUE_ID_ATTR
34
+ true
35
+ end
36
+ end
37
+ reset!
38
+ end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ module AD
4
+ class Authentication
5
+ def initialize(connection = AD::ConnectionFactory.service_user_connection)
6
+ @connection = connection
7
+ end
8
+
9
+ attr_reader :connection, :bind_user
10
+
11
+ def authenticate(username, password)
12
+ @bind_user = nil
13
+ return false if username.blank? || password.blank?
14
+ result = @connection.bind_as(
15
+ base: AD.base_dn,
16
+ filter: Net::LDAP::DN.new(AD.unique_id_attr, username.strip).to_s,
17
+ password: password.to_s
18
+ )
19
+ @bind_user = result[0] if result
20
+ @bind_user ? true : false
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ module AD
4
+ module ConnectionFactory
5
+ ServiceUserBindError = Class.new(StandardError)
6
+
7
+ def unauthenticated_connection
8
+ Net::LDAP.new(
9
+ host: AD.host,
10
+ port: AD.port,
11
+ instrumentation_service: AD.instrumentation_service
12
+ )
13
+ end
14
+
15
+ def service_user_connection
16
+ connection = unauthenticated_connection
17
+ connection.auth(
18
+ Net::LDAP::DN.new(AD.service_user_dn).to_s,
19
+ AD.service_user_password
20
+ )
21
+ unless connection.bind
22
+ raise ServiceUserBindError, connection.get_operation_result
23
+ end
24
+ connection
25
+ end
26
+
27
+ module_function :unauthenticated_connection
28
+ module_function :service_user_connection
29
+ end
30
+ end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ module AD
4
+ class RecordFinder
5
+ def initialize(connection = AD::ConnectionFactory.service_user_connection)
6
+ @connection = connection
7
+ end
8
+
9
+ attr_reader :connection, :result
10
+
11
+ def find_by_id(query)
12
+ @result = @connection.search(
13
+ base: AD.base_dn,
14
+ filter: Net::LDAP::Filter.eq(AD.unique_id_attr, query.to_s)
15
+ )
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module AD
4
+ VERSION = "1.0.0"
5
+ end
metadata ADDED
@@ -0,0 +1,148 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ad
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Krists Ozols
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-11-08 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: net-ldap
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.15.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.15.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: activesupport
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.15'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.15'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: minitest
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '5.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '5.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rubocop
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: 0.51.0
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: 0.51.0
97
+ - !ruby/object:Gem::Dependency
98
+ name: pry
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: 0.11.2
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: 0.11.2
111
+ description:
112
+ email:
113
+ - krists.ozols@gmail.com
114
+ executables: []
115
+ extensions: []
116
+ extra_rdoc_files: []
117
+ files:
118
+ - lib/ad.rb
119
+ - lib/ad/authentication.rb
120
+ - lib/ad/connection_factory.rb
121
+ - lib/ad/record_finder.rb
122
+ - lib/ad/version.rb
123
+ homepage:
124
+ licenses:
125
+ - MIT
126
+ metadata: {}
127
+ post_install_message:
128
+ rdoc_options: []
129
+ require_paths:
130
+ - lib
131
+ required_ruby_version: !ruby/object:Gem::Requirement
132
+ requirements:
133
+ - - ">="
134
+ - !ruby/object:Gem::Version
135
+ version: '0'
136
+ required_rubygems_version: !ruby/object:Gem::Requirement
137
+ requirements:
138
+ - - ">="
139
+ - !ruby/object:Gem::Version
140
+ version: '0'
141
+ requirements: []
142
+ rubyforge_project:
143
+ rubygems_version: 2.6.11
144
+ signing_key:
145
+ specification_version: 4
146
+ summary: A wrapper around Ruby's net-ldap library to ease authentication and record
147
+ finding
148
+ test_files: []