socialcast_ldap_integration 1.1.10 → 1.1.11
Sign up to get free protection for your applications and to get access to all the features.
@@ -1,4 +1,5 @@
|
|
1
1
|
require "net/ldap"
|
2
|
+
require "active_support/core_ext"
|
2
3
|
|
3
4
|
module Socialcast
|
4
5
|
module LdapIntegration
|
@@ -15,18 +16,21 @@ module Socialcast
|
|
15
16
|
|
16
17
|
def self.available?
|
17
18
|
return false unless self.config
|
19
|
+
|
18
20
|
return self.config['connections'].all? do |connection|
|
19
|
-
|
21
|
+
self.connection_fields_present?(connection) && self.required_fields_present?(connection)
|
20
22
|
end
|
21
23
|
end
|
22
24
|
|
23
25
|
def self.scheduled?
|
24
|
-
self.config['enableLdapSchedule']
|
26
|
+
self.config['enableLdapSchedule'].to_s == 'true'
|
25
27
|
end
|
26
28
|
|
27
29
|
def self.mirror_lazily?
|
30
|
+
# should we really return true here if the connection is unavailable?
|
28
31
|
return true unless self.available?
|
29
|
-
|
32
|
+
|
33
|
+
self.config['lazy_mirroring'].to_s == 'true'
|
30
34
|
end
|
31
35
|
|
32
36
|
def self.schedule
|
@@ -56,6 +60,7 @@ module Socialcast
|
|
56
60
|
# - Connection settings for the connection
|
57
61
|
def self.connect(options={})
|
58
62
|
raise ArgumentError.new("connect requires a block, see connect_to") unless block_given?
|
63
|
+
|
59
64
|
config = options[:config] ? [options[:config]] : Socialcast::LdapIntegration.config['connections']
|
60
65
|
config.each do |connection_options|
|
61
66
|
ldap = connect_to(connection_options)
|
@@ -87,19 +92,35 @@ module Socialcast
|
|
87
92
|
|
88
93
|
return ldap
|
89
94
|
end
|
90
|
-
|
95
|
+
|
91
96
|
# Supported options
|
92
|
-
# [:filter] A string representing the search filter to use instead
|
93
|
-
#
|
94
|
-
#
|
95
|
-
# [:
|
97
|
+
# [:filter] A string representing the search filter to use instead
|
98
|
+
# of the default search filter. Overrides any :auxiliary_filter
|
99
|
+
# option.
|
100
|
+
# [:auxiliary_filter] A string representing a search filter to use
|
101
|
+
# in addition to the default search filter. The two filters
|
102
|
+
# will be combined using a logical AND.
|
103
|
+
# [:limit] A number representing the maxmimum number of records to
|
104
|
+
# return, defaults to unlimited.
|
96
105
|
def self.search(options={})
|
97
106
|
options.reverse_merge! :connect_options => {}
|
98
107
|
Socialcast::LdapIntegration.connect(options.delete(:connect_options) || {}) do |ldap, connection|
|
99
108
|
ldap_search_options = self.construct_filter_for_search(connection, options.delete(:filter), options.delete(:auxiliary_filter))
|
100
109
|
ldap_search_options[:size] = options[:limit] if options.has_key?(:limit)
|
101
|
-
|
102
|
-
|
110
|
+
ldap_search_options[:return_result] = false
|
111
|
+
|
112
|
+
options_for_search = [ldap_search_options]
|
113
|
+
|
114
|
+
if connection[:base].blank?
|
115
|
+
tree_root = ldap.search_root_dse
|
116
|
+
distinguished_names = Array.wrap(tree_root.namingcontexts)
|
117
|
+
options_for_search = distinguished_names.map { |dn| ldap_search_options.merge(:base => dn ) }
|
118
|
+
end
|
119
|
+
|
120
|
+
options_for_search.each do |options|
|
121
|
+
ldap.search(options) do |entry|
|
122
|
+
yield(entry, connection) if block_given?
|
123
|
+
end
|
103
124
|
end
|
104
125
|
end
|
105
126
|
end
|
@@ -109,6 +130,7 @@ module Socialcast
|
|
109
130
|
# Defaults to 'company_login'
|
110
131
|
def self.authenticated?(identifier, password, options = {})
|
111
132
|
return false if password.blank?
|
133
|
+
|
112
134
|
identifying_field = options.reverse_merge!({:identifying_field => 'company_login'}).delete(:identifying_field)
|
113
135
|
|
114
136
|
Socialcast::LdapIntegration.connect do |ldap, connection|
|
@@ -118,7 +140,13 @@ module Socialcast
|
|
118
140
|
host = connection['host']
|
119
141
|
port = connection['port']
|
120
142
|
map = connection['map']
|
121
|
-
connection_options.reverse_merge!
|
143
|
+
connection_options.reverse_merge!({
|
144
|
+
:host => host,
|
145
|
+
:port => port,
|
146
|
+
:base => base,
|
147
|
+
:filter => "#{map[identifying_field]}=#{identifier}",
|
148
|
+
:password => password
|
149
|
+
})
|
122
150
|
return true if !ldap.bind_as(connection_options).blank?
|
123
151
|
end
|
124
152
|
return false
|
@@ -130,7 +158,6 @@ module Socialcast
|
|
130
158
|
self.available? && (["password", "email"].include?(string_field))
|
131
159
|
end
|
132
160
|
|
133
|
-
|
134
161
|
def self.fetch_account_info(identifier, options = {})
|
135
162
|
identifying_field = options.delete(:identifying_field) || 'company_login'
|
136
163
|
matched_account = nil
|
@@ -148,10 +175,13 @@ module Socialcast
|
|
148
175
|
return mapped_account_info
|
149
176
|
end
|
150
177
|
end
|
178
|
+
|
151
179
|
nil
|
152
180
|
end
|
153
181
|
|
182
|
+
|
154
183
|
protected
|
184
|
+
|
155
185
|
def self.construct_filter_for_search(connection, filter_options=nil, auxiliary_filter=nil)
|
156
186
|
unless filter_options
|
157
187
|
search_filter = connection['filter_string'].blank? ? NULL_FILTER : Net::LDAP::Filter.construct(connection['filter_string'])
|
@@ -160,8 +190,22 @@ module Socialcast
|
|
160
190
|
end
|
161
191
|
{:filter => filter_options}
|
162
192
|
end
|
193
|
+
|
194
|
+
def self.required_fields_present?(connection)
|
195
|
+
self.required_fields.all? { |field| !connection['map'][field].blank? }
|
196
|
+
end
|
197
|
+
|
163
198
|
def self.required_fields
|
164
199
|
['email', 'company_login']
|
165
200
|
end
|
201
|
+
|
202
|
+
def self.connection_fields_present?(connection)
|
203
|
+
connection_fields.all? { |field| !connection[field].to_s.blank? }
|
204
|
+
end
|
205
|
+
|
206
|
+
def self.connection_fields
|
207
|
+
['searcher_username', 'searcher_password', 'filter_string', 'host', 'port', 'ssl', 'map']
|
208
|
+
end
|
209
|
+
|
166
210
|
end
|
167
|
-
end
|
211
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: socialcast_ldap_integration
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.11
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -11,20 +11,57 @@ authors:
|
|
11
11
|
autorequire:
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
|
-
date: 2012-
|
14
|
+
date: 2012-08-21 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: socialcast-net-ldap
|
18
|
-
requirement:
|
18
|
+
requirement: !ruby/object:Gem::Requirement
|
19
19
|
none: false
|
20
20
|
requirements:
|
21
|
-
- - =
|
21
|
+
- - '='
|
22
22
|
- !ruby/object:Gem::Version
|
23
23
|
version: 0.1.6
|
24
24
|
type: :runtime
|
25
25
|
prerelease: false
|
26
|
-
version_requirements:
|
27
|
-
|
26
|
+
version_requirements: !ruby/object:Gem::Requirement
|
27
|
+
none: false
|
28
|
+
requirements:
|
29
|
+
- - '='
|
30
|
+
- !ruby/object:Gem::Version
|
31
|
+
version: 0.1.6
|
32
|
+
- !ruby/object:Gem::Dependency
|
33
|
+
name: active_support
|
34
|
+
requirement: !ruby/object:Gem::Requirement
|
35
|
+
none: false
|
36
|
+
requirements:
|
37
|
+
- - ! '>='
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '3.0'
|
40
|
+
type: :runtime
|
41
|
+
prerelease: false
|
42
|
+
version_requirements: !ruby/object:Gem::Requirement
|
43
|
+
none: false
|
44
|
+
requirements:
|
45
|
+
- - ! '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
- !ruby/object:Gem::Dependency
|
49
|
+
name: rspec
|
50
|
+
requirement: !ruby/object:Gem::Requirement
|
51
|
+
none: false
|
52
|
+
requirements:
|
53
|
+
- - '='
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: 2.11.0
|
56
|
+
type: :development
|
57
|
+
prerelease: false
|
58
|
+
version_requirements: !ruby/object:Gem::Requirement
|
59
|
+
none: false
|
60
|
+
requirements:
|
61
|
+
- - '='
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: 2.11.0
|
64
|
+
description: ! 'The most bestest LDAP integration gem thine eyes hath ever beholded. '
|
28
65
|
email:
|
29
66
|
- mitch@socialcast.com
|
30
67
|
- sean@socialcast.com
|
@@ -55,7 +92,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
55
92
|
version: '0'
|
56
93
|
requirements: []
|
57
94
|
rubyforge_project: socialcast_ldap_integration
|
58
|
-
rubygems_version: 1.8.
|
95
|
+
rubygems_version: 1.8.24
|
59
96
|
signing_key:
|
60
97
|
specification_version: 3
|
61
98
|
summary: Provides support for connecting to and traversing LDAP trees.
|