devise_w3_authenticatable 0.3.1 → 0.3.2

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.1
1
+ 0.3.2
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{devise_w3_authenticatable}
8
- s.version = "0.3.1"
8
+ s.version = "0.3.2"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Rodrigo Navarro"]
12
- s.date = %q{2010-09-13}
12
+ s.date = %q{2010-09-14}
13
13
  s.description = %q{Devise strategy to authenticate against IBM w3 LDAP directory.}
14
14
  s.email = %q{reu@rnavarro.com.br}
15
15
  s.files = [
@@ -13,7 +13,7 @@ module Devise
13
13
  Devise::W3Adapter.valid_credentials? email, password
14
14
  end
15
15
 
16
- def after_w3_authentication(employee = nil)
16
+ def after_w3_authentication(bluepages_information = nil)
17
17
  end
18
18
 
19
19
  module ClassMethods
@@ -6,16 +6,18 @@ module Devise
6
6
  def authenticate!
7
7
  resource = mapping.to.find_for_w3_authentication(authentication_hash)
8
8
 
9
- employee = nil
10
-
11
- if validate(resource) { employee = resource.authenticate_with_w3!(password) }
12
- resource.after_w3_authentication employee
9
+ if validate(resource) { bluepages_information = resource.authenticate_with_w3!(password) }
10
+ resource.after_w3_authentication bluepages_information
13
11
  resource.save if DeviseW3Authenticatable.auto_create_user
14
12
  success! resource
15
13
  else
16
14
  fail :invalid
17
15
  end
18
16
  end
17
+
18
+ private
19
+
20
+ attr_accessor :bluepages_information
19
21
  end
20
22
  end
21
23
  end
@@ -5,7 +5,7 @@ require 'nokogiri'
5
5
  module Devise
6
6
  module W3Adapter
7
7
  def self.valid_credentials?(logon, password)
8
- return unless employee = get_information_from_bluepages(logon)
8
+ return unless employee = IBMEmployee.find_by_mail(logon)
9
9
 
10
10
  user = Net::LDAP.new :host => "bluepages.ibm.com"
11
11
  user.authenticate(employee.uid, password)
@@ -13,26 +13,28 @@ module Devise
13
13
  user.bind and employee
14
14
  end
15
15
 
16
- def self.get_information_from_bluepages(logon)
17
- IBMEmployee.parse_from_bluepages("http://bluepages.ibm.com/BpHttpApisv3/slaphapi?ibmperson/mail=#{logon}.list/byxml")
18
- end
19
-
20
16
  class IBMEmployee < Struct.new(:uid, :logon, :name, :serial, :department, :country, :workplace)
21
- def self.parse_from_bluepages(bluepages_url)
22
- begin
23
- entry = Nokogiri::XML(open(bluepages_url)).css("entry").first
17
+ class << self
18
+ def parse_from_bluepages(bluepages_url)
19
+ begin
20
+ entry = Nokogiri::XML(open(bluepages_url)).css("entry").first
24
21
 
25
- uid = entry.attributes["dn"].to_s
26
- logon = entry.css("attr[name='mail'] value").children.first.to_s
27
- name = entry.css("attr[name='cn'] value").children.first.to_s
28
- serial = entry.css("attr[name='serialnumber'] value").children.first.to_s
29
- department = entry.css("attr[name='dept'] value").children.first.to_s
30
- country = entry.css("attr[name='co'] value").children.first.to_s
31
- workplace = entry.css("attr[name='physicaldeliveryofficename'] value").children.first.to_s
22
+ uid = entry.attributes["dn"].to_s
23
+ logon = entry.css("attr[name='mail'] value").children.first.to_s
24
+ name = entry.css("attr[name='cn'] value").children.first.to_s
25
+ serial = entry.css("attr[name='serialnumber'] value").children.first.to_s
26
+ department = entry.css("attr[name='dept'] value").children.first.to_s
27
+ country = entry.css("attr[name='co'] value").children.first.to_s
28
+ workplace = entry.css("attr[name='physicaldeliveryofficename'] value").children.first.to_s
29
+
30
+ new(uid, logon, name, serial, department, country, workplace)
31
+ rescue
32
+ nil
33
+ end
34
+ end
32
35
 
33
- new(uid, logon, name, serial, department, country, workplace)
34
- rescue
35
- nil
36
+ def find_by_mail(mail)
37
+ parse_from_bluepages("http://bluepages.ibm.com/BpHttpApisv3/slaphapi?ibmperson/mail=#{mail}.list/byxml")
36
38
  end
37
39
  end
38
40
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 3
8
- - 1
9
- version: 0.3.1
8
+ - 2
9
+ version: 0.3.2
10
10
  platform: ruby
11
11
  authors:
12
12
  - Rodrigo Navarro
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-09-13 00:00:00 -03:00
17
+ date: 2010-09-14 00:00:00 -03:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency