oa-enterprise 0.1.6 → 0.2.0.beta1

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -12,10 +12,9 @@ For the full auth suite:
12
12
 
13
13
  gem install omniauth
14
14
 
15
- CAS strategy
16
- == Stand-Alone Example
15
+ == CAS
17
16
 
18
- Use the strategy as a middleware in your application:
17
+ Use the CAS strategy as a middleware in your application:
19
18
 
20
19
  require 'omniauth/enterprise'
21
20
 
@@ -23,13 +22,47 @@ Use the strategy as a middleware in your application:
23
22
 
24
23
  Then simply direct users to '/auth/cas' to have them sign in via your company's CAS server.
25
24
  See OmniAuth::Strategies::CAS::Configuration for more configuration options.
26
-
27
- Then simply direct users to '/auth/cas' to have them sign in via your company's CAS server.
28
- See OmniAuth::Strategies::CAS::Configuration for more configuration options.
29
25
 
30
- == OmniAuth Builder
26
+ == LDAP
31
27
 
32
- If CAS is one of several authentication strategies, use the OmniAuth Builder:
28
+ Use the LDAP strategy as a middleware in your applicaiton:
29
+
30
+ require 'omniauth/enterprise'
31
+ use OmniAuth::Strategies::LDAP,
32
+ :title => "My LDAP",
33
+ :host => '10.101.10.1',
34
+ :port => 389,
35
+ :method => :plain,
36
+ :base => 'dc=intridea, dc=com',
37
+ :uid => 'sAMAccountName',
38
+ :name_proc => Proc.new {|name| name.gsub(/@.*$/,''}}
39
+
40
+ All of the listed options are required, with the exception of :name_proc.
41
+ Allowed values of :method are: :plain, :ssl, :tls.
42
+
43
+ :uid is the LDAP attribute name for the user name in the login form. typically
44
+ AD would be 'sAMAccountName' or 'UserPrincipalName', while OpenLDAP is 'uid'.
45
+ You can also use 'dn', if your user choose the put in the dn in the login form
46
+ (but usually is too long for user to remember or know).
47
+
48
+ :name_proc allows you to match the user name entered with the format of the
49
+ :uid attributes. For example, value of 'sAMAccountName' in AD contains only the
50
+ windows user name. If your user prefers use email to login, a name_proc as
51
+ above will trim the email string down to just the windows name. In summary,
52
+ :name_proc helps you to fill the gap between the authentication and user lookup
53
+ process.
54
+
55
+ :try_sasl and :sasl_mechanisms are optional. Use them to initialize a SASL
56
+ connection to server. Allowed values are 'DIGEST-MD5' and 'GSS-SPNEGO'. If you
57
+ are not familiar with these authentication methods, please just avoid them.
58
+
59
+ Direct users to '/auth/ldap' to have them authenticated via your
60
+ company's LDAP server.
61
+
62
+ == Multiple Strategies
63
+
64
+ If you're using multiple strategies together, use OmniAuth's Builder. That's
65
+ what it's there for:
33
66
 
34
67
  require 'omniauth/enterprise'
35
68
  require 'omniauth/oauth' # for Campfire
@@ -39,20 +72,3 @@ If CAS is one of several authentication strategies, use the OmniAuth Builder:
39
72
  provider :cas, :server => 'http://cas.mycompany.com/cas'
40
73
  provider :campfire
41
74
  end
42
-
43
- LDAP strategy
44
-
45
- use OmniAuth::Strategies::LDAP, :host => '10.101.10.1', :port => 389, :method => :plain, :base => 'dc=intridea, dc=com', :uid => 'sAMAccountName', :try_sasl => true, :sasl_mechanisms => "GSS-SPNEGO"
46
- or
47
- use OmniAuth::Builder do
48
- provider :LDAP, :host => '10.101.10.1', :port => 389, :method => :plain, :base => 'dc=intridea, dc=com', :uid => 'sAMAccountName', :try_sasl => true, :sasl_mechanisms => "GSS-SPNEGO"
49
- end
50
-
51
- LDAP server's :host and :port are required, :method is also a required field, and allowed values are :plain, :ssl, and :tls.
52
- :base is required, it is the distinguish name (DN) for your organization, all users should be searchable under this base.
53
- :uid is required, it is the LDAP attribute name for the user name in the login form. typically AD would be 'sAMAccountName' or 'UniquePersonalIdentifier', while
54
- OpenLDAP is 'uid'. You can also use 'dn', if your user choose the put in the dn in the login form (but usually is too long for user to remember or know).
55
- :try_sasl and :sasl_mechanisms are optional, use it to initial SASL connection to server. mechanism supported are DIGEST-MD5 and GSS-SPNEGO.
56
-
57
- Then simply direct users to '/auth/ldap' to have them authenticated via your company's LDAP server.
58
-
@@ -8,8 +8,8 @@ module OmniAuth
8
8
  autoload :Configuration, 'omniauth/strategies/cas/configuration'
9
9
  autoload :ServiceTicketValidator, 'omniauth/strategies/cas/service_ticket_validator'
10
10
 
11
- def initialize(app, options = {})
12
- super(app, options.delete(:name) || :cas)
11
+ def initialize(app, options = {}, &block)
12
+ super(app, options.delete(:name) || :cas, options, &block)
13
13
  @configuration = OmniAuth::Strategies::CAS::Configuration.new(options)
14
14
  end
15
15
 
@@ -1,57 +1,66 @@
1
1
  #this code boughts pieces from activeldap and net-ldap
2
+
2
3
  require 'rack'
3
4
  require 'net/ldap'
4
5
  require 'net/ntlm'
5
6
  require 'uri'
7
+
6
8
  module OmniAuth
7
9
  module Strategies
8
10
  class LDAP
9
11
  class Adaptor
10
- class LdapError < StandardError; end
11
- class ConfigurationError < StandardError; end
12
- class AuthenticationError < StandardError; end
13
- class ConnectionError < StandardError; end
14
- VALID_ADAPTER_CONFIGURATION_KEYS = [:host, :port, :method, :bind_dn, :password,
15
- :try_sasl, :sasl_mechanisms, :uid, :base]
16
- MUST_HAVE_KEYS = [:host, :port, :method, :uid, :base]
17
- METHOD = {
18
- :ssl => :simple_tls,
19
- :tls => :start_tls,
20
- :plain => nil
21
- }
22
- attr_accessor :bind_dn, :password
23
- attr_reader :connection, :uid, :base
24
- def initialize(configuration={})
25
- @connection = nil
26
- @disconnected = false
27
- @bound = false
28
- @configuration = configuration.dup
29
- @logger = @configuration.delete(:logger)
30
- message = []
31
- MUST_HAVE_KEYS.each do |name|
32
- message << name if configuration[name].nil?
33
- end
34
- raise ArgumentError.new(message.join(",") +" MUST be provided") unless message.empty?
35
- VALID_ADAPTER_CONFIGURATION_KEYS.each do |name|
36
- instance_variable_set("@#{name}", configuration[name])
37
- end
38
- end
12
+ class LdapError < StandardError; end
13
+ class ConfigurationError < StandardError; end
14
+ class AuthenticationError < StandardError; end
15
+ class ConnectionError < StandardError; end
16
+
17
+ VALID_ADAPTER_CONFIGURATION_KEYS = [:host, :port, :method, :bind_dn, :password,
18
+ :try_sasl, :sasl_mechanisms, :uid, :base]
19
+
20
+ MUST_HAVE_KEYS = [:host, :port, :method, :uid, :base]
21
+
22
+ METHOD = {
23
+ :ssl => :simple_tls,
24
+ :tls => :start_tls,
25
+ :plain => nil
26
+ }
27
+
28
+ attr_accessor :bind_dn, :password
29
+ attr_reader :connection, :uid, :base
30
+
31
+ def initialize(configuration={})
32
+ @connection = nil
33
+ @disconnected = false
34
+ @bound = false
35
+ @configuration = configuration.dup
36
+ @logger = @configuration.delete(:logger)
37
+ message = []
38
+ MUST_HAVE_KEYS.each do |name|
39
+ message << name if configuration[name].nil?
40
+ end
41
+ raise ArgumentError.new(message.join(",") +" MUST be provided") unless message.empty?
42
+ VALID_ADAPTER_CONFIGURATION_KEYS.each do |name|
43
+ instance_variable_set("@#{name}", configuration[name])
44
+ end
45
+ end
39
46
 
40
- def connect(options={})
41
- host = options[:host] || @host
42
- method = options[:method] || @method || :plain
43
- port = options[:port] || @port || ensure_port(method)
44
- method = ensure_method(method)
45
- @disconnected = false
46
- @bound = false
47
- @bind_tried = false
47
+ def connect(options={})
48
+ host = options[:host] || @host
49
+ method = options[:method] || @method || :plain
50
+ port = options[:port] || @port || ensure_port(method)
51
+ method = ensure_method(method)
52
+ @disconnected = false
53
+ @bound = false
54
+ @bind_tried = false
55
+
48
56
  config = {
49
57
  :host => host,
50
58
  :port => port,
51
59
  }
60
+
52
61
  config[:encryption] = {:method => method} if method
53
- @connection, @uri, @with_start_tls =
54
- begin
62
+
63
+ @connection, @uri, @with_start_tls = begin
55
64
  uri = construct_uri(host, port, method == :simple_tls)
56
65
  with_start_tls = method == :start_tls
57
66
  puts ({:uri => uri, :with_start_tls => with_start_tls}).inspect
@@ -59,189 +68,201 @@ module OmniAuth
59
68
  rescue Net::LDAP::LdapError
60
69
  raise ConnectionError, $!.message
61
70
  end
62
- end
71
+
72
+ end
63
73
 
64
- def unbind(options={})
65
- @connection.close # Net::LDAP doesn't implement unbind.
66
- end
74
+ def unbind(options={})
75
+ @connection.close # Net::LDAP doesn't implement unbind.
76
+ end
67
77
 
68
- def bind(options={})
69
- connect(options) unless connecting?
70
- begin
71
- @bind_tried = true
72
-
73
- bind_dn = (options[:bind_dn] || @bind_dn).to_s
74
- try_sasl = options.has_key?(:try_sasl) ? options[:try_sasl] : @try_sasl
75
-
76
- # Rough bind loop:
77
- # Attempt 1: SASL if available
78
- # Attempt 2: SIMPLE with credentials if password block
79
- if try_sasl and sasl_bind(bind_dn, options)
80
- puts "bind with sasl"
81
- elsif simple_bind(bind_dn, options)
82
- puts "bind with simple"
83
- else
84
- message = yield if block_given?
85
- message ||= ('All authentication methods for %s exhausted.') % target
86
- raise AuthenticationError, message
87
- end
78
+ def bind(options={})
79
+ connect(options) unless connecting?
80
+ begin
81
+ @bind_tried = true
82
+
83
+ bind_dn = (options[:bind_dn] || @bind_dn).to_s
84
+ try_sasl = options.has_key?(:try_sasl) ? options[:try_sasl] : @try_sasl
88
85
 
89
- @bound = true
90
- rescue Net::LDAP::LdapError
91
- raise AuthenticationError, $!.message
92
- end
86
+ # Rough bind loop:
87
+ # Attempt 1: SASL if available
88
+ # Attempt 2: SIMPLE with credentials if password block
89
+ if try_sasl and sasl_bind(bind_dn, options)
90
+ puts "bind with sasl"
91
+ elsif simple_bind(bind_dn, options)
92
+ puts "bind with simple"
93
+ else
94
+ message = yield if block_given?
95
+ message ||= ('All authentication methods for %s exhausted.') % target
96
+ raise AuthenticationError, message
97
+ end
98
+
99
+ @bound = true
100
+ rescue Net::LDAP::LdapError
101
+ raise AuthenticationError, $!.message
93
102
  end
103
+ end
94
104
 
95
- def disconnect!(options={})
96
- unbind(options)
97
- @connection = @uri = @with_start_tls = nil
98
- @disconnected = true
99
- end
105
+ def disconnect!(options={})
106
+ unbind(options)
107
+ @connection = @uri = @with_start_tls = nil
108
+ @disconnected = true
109
+ end
100
110
 
101
- def rebind(options={})
102
- unbind(options) if bound?
103
- connect(options)
104
- end
111
+ def rebind(options={})
112
+ unbind(options) if bound?
113
+ connect(options)
114
+ end
105
115
 
106
- def connecting?
107
- !@connection.nil? and !@disconnected
108
- end
116
+ def connecting?
117
+ !@connection.nil? and !@disconnected
118
+ end
109
119
 
110
- def bound?
111
- connecting? and @bound
112
- end
120
+ def bound?
121
+ connecting? and @bound
122
+ end
113
123
 
114
- def search(options={}, &block)
115
- base = options[:base]
116
- filter = options[:filter]
117
- limit = options[:limit]
124
+ def search(options={}, &block)
125
+ base = options[:base]
126
+ filter = options[:filter]
127
+ limit = options[:limit]
118
128
 
119
- args = {
120
- :base => @base,
121
- :filter => filter,
122
- :size => limit
123
- }
124
- puts args.inspect
129
+ args = {
130
+ :base => @base,
131
+ :filter => filter,
132
+ :size => limit
133
+ }
134
+
135
+ puts args.inspect
136
+
125
137
  attributes = {}
126
138
  execute(:search, args) do |entry|
127
139
  entry.attribute_names.each do |name|
128
140
  attributes[name] = entry[name]
129
141
  end
130
- end
131
- attributes
132
- end
133
- private
134
- def execute(method, *args, &block)
135
- result = @connection.send(method, *args, &block)
136
- message = nil
137
- if result.is_a?(Hash)
138
- message = result[:errorMessage]
139
- result = result[:resultCode]
140
- end
141
- unless result.zero?
142
- message = [Net::LDAP.result2string(result), message].compact.join(": ")
143
- raise LdapError, message
144
- end
145
- end
142
+ end
143
+ attributes
144
+ end
145
+
146
+ private
147
+
148
+ def execute(method, *args, &block)
149
+ result = @connection.send(method, *args, &block)
150
+ message = nil
151
+
152
+ if result.is_a?(Hash)
153
+ message = result[:errorMessage]
154
+ result = result[:resultCode]
155
+ end
156
+
157
+ unless result.zero?
158
+ message = [Net::LDAP.result2string(result), message].compact.join(": ")
159
+ raise LdapError, message
160
+ end
161
+ end
146
162
 
147
- def ensure_port(method)
148
- if method == :ssl
149
- URI::LDAPS::DEFAULT_PORT
150
- else
151
- URI::LDAP::DEFAULT_PORT
152
- end
153
- end
154
-
155
- def prepare_connection(options)
163
+ def ensure_port(method)
164
+ if method == :ssl
165
+ URI::LDAPS::DEFAULT_PORT
166
+ else
167
+ URI::LDAP::DEFAULT_PORT
156
168
  end
169
+ end
157
170
 
158
- def ensure_method(method)
159
- method ||= "plain"
160
- normalized_method = method.to_s.downcase.to_sym
161
- return METHOD[normalized_method] if METHOD.has_key?(normalized_method)
171
+ def prepare_connection(options)
172
+ end
162
173
 
163
- available_methods = METHOD.keys.collect {|m| m.inspect}.join(", ")
164
- format = "%s is not one of the available connect methods: %s"
165
- raise ConfigurationError, format % [method.inspect, available_methods]
166
- end
174
+ def ensure_method(method)
175
+ method ||= "plain"
176
+ normalized_method = method.to_s.downcase.to_sym
177
+ return METHOD[normalized_method] if METHOD.has_key?(normalized_method)
178
+
179
+ available_methods = METHOD.keys.collect {|m| m.inspect}.join(", ")
180
+ format = "%s is not one of the available connect methods: %s"
181
+ raise ConfigurationError, format % [method.inspect, available_methods]
182
+ end
167
183
 
168
- def sasl_bind(bind_dn, options={})
169
- sasl_mechanisms = options[:sasl_mechanisms] || @sasl_mechanisms
170
- sasl_mechanisms.each do |mechanism|
171
- begin
172
- normalized_mechanism = mechanism.downcase.gsub(/-/, '_')
173
- sasl_bind_setup = "sasl_bind_setup_#{normalized_mechanism}"
174
- next unless respond_to?(sasl_bind_setup, true)
175
- initial_credential, challenge_response =
176
- send(sasl_bind_setup, bind_dn, options)
177
- args = {
178
- :method => :sasl,
179
- :initial_credential => initial_credential,
180
- :mechanism => mechanism,
181
- :challenge_response => challenge_response,
182
- }
183
- info = {
184
- :name => "bind: SASL", :dn => bind_dn, :mechanism => mechanism,
185
- }
186
- puts info.inspect
187
- execute(:bind, args)
188
- return true
189
- rescue Exception => e
190
- puts e.message
191
- end
192
- end
193
- false
194
- end
195
-
196
- def sasl_bind_setup_digest_md5(bind_dn, options)
197
- initial_credential = ""
198
- challenge_response = Proc.new do |cred|
199
- pref = SASL::Preferences.new :digest_uri => "ldap/#{@host}", :username => bind_dn, :has_password? => true, :password => options[:password]||@password
200
- sasl = SASL.new("DIGEST-MD5", pref)
201
- response = sasl.receive("challenge", cred)
202
- response[1]
184
+ def sasl_bind(bind_dn, options={})
185
+ sasl_mechanisms = options[:sasl_mechanisms] || @sasl_mechanisms
186
+ sasl_mechanisms.each do |mechanism|
187
+ begin
188
+ normalized_mechanism = mechanism.downcase.gsub(/-/, '_')
189
+ sasl_bind_setup = "sasl_bind_setup_#{normalized_mechanism}"
190
+ next unless respond_to?(sasl_bind_setup, true)
191
+ initial_credential, challenge_response = send(sasl_bind_setup, bind_dn, options)
192
+
193
+ args = {
194
+ :method => :sasl,
195
+ :initial_credential => initial_credential,
196
+ :mechanism => mechanism,
197
+ :challenge_response => challenge_response,
198
+ }
199
+
200
+ info = {
201
+ :name => "bind: SASL", :dn => bind_dn, :mechanism => mechanism,
202
+ }
203
+ puts info.inspect
204
+
205
+ execute(:bind, args)
206
+ return true
207
+
208
+ rescue Exception => e
209
+ puts e.message
210
+ end
211
+ end
212
+
213
+ false
214
+ end
215
+
216
+ def sasl_bind_setup_digest_md5(bind_dn, options)
217
+ initial_credential = ""
218
+ challenge_response = Proc.new do |cred|
219
+ pref = SASL::Preferences.new :digest_uri => "ldap/#{@host}", :username => bind_dn, :has_password? => true, :password => options[:password]||@password
220
+ sasl = SASL.new("DIGEST-MD5", pref)
221
+ response = sasl.receive("challenge", cred)
222
+ response[1]
223
+ end
224
+ [initial_credential, challenge_response]
225
+ end
226
+
227
+ def sasl_bind_setup_gss_spnego(bind_dn, options)
228
+ puts options.inspect
229
+ user,psw = [bind_dn, options[:password]||@password]
230
+ raise LdapError.new( "invalid binding information" ) unless (user && psw)
231
+
232
+ nego = proc {|challenge|
233
+ t2_msg = Net::NTLM::Message.parse( challenge )
234
+ user, domain = user.split('\\').reverse
235
+ t2_msg.target_name = Net::NTLM::encode_utf16le(domain) if domain
236
+ t3_msg = t2_msg.response( {:user => user, :password => psw}, {:ntlmv2 => true} )
237
+ t3_msg.serialize
238
+ }
239
+ [Net::NTLM::Message::Type1.new.serialize, nego]
203
240
  end
204
- [initial_credential, challenge_response]
205
- end
206
- def sasl_bind_setup_gss_spnego(bind_dn, options)
207
- puts options.inspect
208
- user,psw = [bind_dn, options[:password]||@password]
209
- raise LdapError.new( "invalid binding information" ) unless (user && psw)
210
-
211
- nego = proc {|challenge|
212
- t2_msg = Net::NTLM::Message.parse( challenge )
213
- user, domain = user.split('\\').reverse
214
- t2_msg.target_name = Net::NTLM::encode_utf16le(domain) if domain
215
- t3_msg = t2_msg.response( {:user => user, :password => psw}, {:ntlmv2 => true} )
216
- t3_msg.serialize
217
- }
218
- [Net::NTLM::Message::Type1.new.serialize, nego]
219
- end
220
241
 
221
- def simple_bind(bind_dn, options={})
222
- args = {
223
- :method => :simple,
224
- :username => bind_dn,
225
- :password => options[:password]||@password,
226
- }
227
- execute(:bind, args)
228
- true
229
- end
242
+ def simple_bind(bind_dn, options={})
243
+ args = {
244
+ :method => :simple,
245
+ :username => bind_dn,
246
+ :password => options[:password]||@password,
247
+ }
248
+ execute(:bind, args)
249
+ true
250
+ end
230
251
 
231
- def construct_uri(host, port, ssl)
232
- protocol = ssl ? "ldaps" : "ldap"
233
- URI.parse("#{protocol}://#{host}:#{port}").to_s
234
- end
235
-
236
- def target
237
- return nil if @uri.nil?
238
- if @with_start_tls
239
- "#{@uri}(StartTLS)"
240
- else
241
- @uri
242
- end
243
- end
252
+ def construct_uri(host, port, ssl)
253
+ protocol = ssl ? "ldaps" : "ldap"
254
+ URI.parse("#{protocol}://#{host}:#{port}").to_s
255
+ end
256
+
257
+ def target
258
+ return nil if @uri.nil?
259
+ if @with_start_tls
260
+ "#{@uri}(StartTLS)"
261
+ else
262
+ @uri
263
+ end
264
+ end
244
265
  end
245
266
  end
246
267
  end
247
- end
268
+ end
@@ -2,25 +2,34 @@ require 'omniauth/enterprise'
2
2
  require 'net/ldap'
3
3
  require 'sasl/base'
4
4
  require 'sasl'
5
+
5
6
  module OmniAuth
6
7
  module Strategies
7
8
  class LDAP
8
9
  include OmniAuth::Strategy
9
10
 
10
11
  autoload :Adaptor, 'omniauth/strategies/ldap/adaptor'
11
- @@config = {'name' => 'cn', 'first_name' => 'givenName', 'last_name' => 'sn', 'email' => ['mail', "email", 'userPrincipalName'],
12
- 'phone' => ['telephoneNumber', 'homePhone', 'facsimileTelephoneNumber'],
13
- 'mobile_number' => ['mobile', 'mobileTelephoneNumber'],
14
- 'nickname' => ['uid', 'userid', 'sAMAccountName'],
15
- 'title' => 'title',
16
- 'location' => {"%0, %1, %2, %3 %4" => [['address', 'postalAddress', 'homePostalAddress', 'street', 'streetAddress'], ['l'], ['st'],['co'],['postOfficeBox']]},
17
- 'uid' => 'dn',
18
- 'url' => ['wwwhomepage'],
19
- 'image' => 'jpegPhoto',
20
- 'description' => 'description'}
21
- def initialize(app, title, options = {})
22
- super(app, options.delete(:name) || :ldap)
23
- @title = title
12
+ @@config = {'name' => 'cn',
13
+ 'first_name' => 'givenName',
14
+ 'last_name' => 'sn',
15
+ 'email' => ['mail', "email", 'userPrincipalName'],
16
+ 'phone' => ['telephoneNumber', 'homePhone', 'facsimileTelephoneNumber'],
17
+ 'mobile_number' => ['mobile', 'mobileTelephoneNumber'],
18
+ 'nickname' => ['uid', 'userid', 'sAMAccountName'],
19
+ 'title' => 'title',
20
+ 'location' => {"%0, %1, %2, %3 %4" => [['address', 'postalAddress', 'homePostalAddress', 'street', 'streetAddress'], ['l'], ['st'],['co'],['postOfficeBox']]},
21
+ 'uid' => 'dn',
22
+ 'url' => ['wwwhomepage'],
23
+ 'image' => 'jpegPhoto',
24
+ 'description' => 'description'}
25
+
26
+ # Initialize the LDAP Middleware
27
+ #
28
+ # @param [Rack Application] app Standard Rack middleware argument.
29
+ # @option options [String, 'LDAP Authentication'] :title A title for the authentication form.
30
+ def initialize(app, options = {}, &block)
31
+ super(app, options[:name] || :ldap, options.dup, &block)
32
+ @name_proc = (@options.delete(:name_proc) || Proc.new {|name| name})
24
33
  @adaptor = OmniAuth::Strategies::LDAP::Adaptor.new(options)
25
34
  end
26
35
 
@@ -34,23 +43,29 @@ module OmniAuth
34
43
  end
35
44
  end
36
45
 
37
- def get_credentials
38
- OmniAuth::Form.build(@title) do
46
+ def get_credentials
47
+ OmniAuth::Form.build(options[:title] || "LDAP Authentication") do
39
48
  text_field 'Login', 'username'
40
49
  password_field 'Password', 'password'
41
50
  end.to_response
42
51
  end
52
+
43
53
  def perform
44
54
  begin
45
- @adaptor.bind(:bind_dn => request.POST['username'], :password => request.POST['password'])
46
- @ldap_user_info = @adaptor.search(:filter => Net::LDAP::Filter.eq(@adaptor.uid, request.POST['username']),:limit => 1)
47
- @user_info = self.class.map_user(@@config, @ldap_user_info)
48
- @env['REQUEST_METHOD'] = 'GET'
49
- @env['PATH_INFO'] = "#{OmniAuth.config.path_prefix}/#{name}/callback"
55
+ bind_dn = "#{@adaptor.uid}=#{request.POST['username']}"
56
+ bind_dn << ",#{@adaptor.base}" unless @adaptor.base == ''
57
+
58
+ @adaptor.bind(:bind_dn => bind_dn, :password => request.POST['password'])
59
+ @ldap_user_info = @adaptor.search(:filter => Net::LDAP::Filter.eq(@adaptor.uid, @name_proc.call(request.POST['username'])),:limit => 1)
60
+ @user_info = self.class.map_user(@@config, @ldap_user_info)
61
+
62
+ @env['omniauth.auth'] = auth_hash
63
+ @env['REQUEST_METHOD'] = 'GET'
64
+ @env['PATH_INFO'] = "#{OmniAuth.config.path_prefix}/#{name}/callback"
50
65
 
51
- call_app!
66
+ call_app!
52
67
  rescue Exception => e
53
- fail!(:invalid_credentials, e)
68
+ fail!(:invalid_credentials, e)
54
69
  end
55
70
  end
56
71
 
@@ -66,28 +81,28 @@ module OmniAuth
66
81
  })
67
82
  end
68
83
 
69
- def self.map_user mapper, object
70
- user = {}
71
- mapper.each do |key, value|
72
- case value
73
- when String
74
- user[key] = object[value.downcase.to_sym].to_s if object[value.downcase.to_sym]
75
- when Array
76
- value.each {|v| (user[key] = object[v.downcase.to_sym].to_s; break;) if object[v.downcase.to_sym]}
77
- when Hash
78
- value.map do |key1, value1|
79
- pattern = key1.dup
80
- value1.each_with_index do |v,i|
81
- part = '';
82
- v.each {|v1| (part = object[v1.downcase.to_sym].to_s; break;) if object[v1.downcase.to_sym]}
83
- pattern.gsub!("%#{i}",part||'')
84
- end
85
- user[key] = pattern
86
- end
87
- end
88
- end
89
- user
90
- end
84
+ def self.map_user(mapper, object)
85
+ user = {}
86
+ mapper.each do |key, value|
87
+ case value
88
+ when String
89
+ user[key] = object[value.downcase.to_sym].to_s if object[value.downcase.to_sym]
90
+ when Array
91
+ value.each {|v| (user[key] = object[v.downcase.to_sym].to_s; break;) if object[v.downcase.to_sym]}
92
+ when Hash
93
+ value.map do |key1, value1|
94
+ pattern = key1.dup
95
+ value1.each_with_index do |v,i|
96
+ part = '';
97
+ v.each {|v1| (part = object[v1.downcase.to_sym].to_s; break;) if object[v1.downcase.to_sym]}
98
+ pattern.gsub!("%#{i}",part||'')
99
+ end
100
+ user[key] = pattern
101
+ end
102
+ end
103
+ end
104
+ user
105
+ end
91
106
  end
92
107
  end
93
108
  end
metadata CHANGED
@@ -1,13 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: oa-enterprise
3
3
  version: !ruby/object:Gem::Version
4
- hash: 23
5
- prerelease: false
4
+ hash: -1848230051
5
+ prerelease: true
6
6
  segments:
7
7
  - 0
8
- - 1
9
- - 6
10
- version: 0.1.6
8
+ - 2
9
+ - 0
10
+ - beta1
11
+ version: 0.2.0.beta1
11
12
  platform: ruby
12
13
  authors:
13
14
  - James A. Rosen
@@ -16,7 +17,7 @@ autorequire:
16
17
  bindir: bin
17
18
  cert_chain: []
18
19
 
19
- date: 2010-10-25 00:00:00 -05:00
20
+ date: 2010-11-29 00:00:00 -06:00
20
21
  default_executable:
21
22
  dependencies:
22
23
  - !ruby/object:Gem::Dependency
@@ -25,12 +26,13 @@ dependencies:
25
26
  requirements:
26
27
  - - "="
27
28
  - !ruby/object:Gem::Version
28
- hash: 23
29
+ hash: -1848230051
29
30
  segments:
30
31
  - 0
31
- - 1
32
- - 6
33
- version: 0.1.6
32
+ - 2
33
+ - 0
34
+ - beta1
35
+ version: 0.2.0.beta1
34
36
  requirement: *id001
35
37
  name: oa-core
36
38
  prerelease: false
@@ -233,12 +235,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
233
235
  required_rubygems_version: !ruby/object:Gem::Requirement
234
236
  none: false
235
237
  requirements:
236
- - - ">="
238
+ - - ">"
237
239
  - !ruby/object:Gem::Version
238
- hash: 3
240
+ hash: 25
239
241
  segments:
240
- - 0
241
- version: "0"
242
+ - 1
243
+ - 3
244
+ - 1
245
+ version: 1.3.1
242
246
  requirements: []
243
247
 
244
248
  rubyforge_project: