blueauth 0.0.14 → 0.0.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/lib/blueauth.rb +113 -113
  3. data/lib/blueauth/version.rb +1 -1
  4. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3971e904a5cc8af2fe7a1ba19a9ce85c01e3c107
4
- data.tar.gz: f532e68bc14d53f08ed7114c48c9f6804b058f81
3
+ metadata.gz: aa847bd4eb47464ef189475cd27720cbec05be48
4
+ data.tar.gz: 2a514b995a0821fca8c8c1d2915c3d0830141d58
5
5
  SHA512:
6
- metadata.gz: 8fd050c0c12b2596f321c82e5ff4ec92bc636272513f4a882373bd3429084c106e232daa45be706da37f9b6fe2b81d61e22ed7a7e4fa464a1ffd31d47dd3f02d
7
- data.tar.gz: bccf67b6c695497ab5d4b47535f3dea3e028c43301c68c06cf04edeff4d27673edb1d281a850ca54edb51ab510658f51bfb118951f8fbeb22ffbe9d42d3e3419
6
+ metadata.gz: 5cc52b96fe76d27ef0d9800b6ea84d655d3ef6750eb01e216be905af2a320347ae17083f0000c164218990a9cb64c38ef206af8818ad800cdbbc81667e5bfce7
7
+ data.tar.gz: 5258f5e0a3df69da899a3943527f9fbf69adb42f6122919aff9a9e1844304acf4837ebae8169ea333fe698bcb4f744b8b4b06ffaef3f4168acc7ac954e35173d
data/lib/blueauth.rb CHANGED
@@ -1,113 +1,113 @@
1
- require 'blueauth/version'
2
- require 'blueauth/error'
3
- require 'blueauth/certificates'
4
- require 'net-ldap'
5
-
6
- module Blueauth
7
-
8
- BPBASE = 'ou=bluepages,o=ibm.com'
9
- BGBASE = 'ou=memberlist,ou=ibmgroups,o=ibm.com'
10
-
11
- BPHOSTS = [['9.57.182.78',636], ['9.17.186.253',636], ['bluepages.ibm.com',636]]
12
-
13
- old_verbose, $VERBOSE = $VERBOSE, nil
14
- Net::LDAP::LDAPControls::PAGED_RESULTS = FALSE
15
- $VERBOSE = old_verbose
16
-
17
- @cert_store = OpenSSL::X509::Store.new
18
- @cert_store.add_cert OpenSSL::X509::Certificate.new(NEW_CERT)
19
- @cert_store.add_cert OpenSSL::X509::Certificate.new(OLD_CERT)
20
-
21
- def self.open_ldap
22
- Net::LDAP.new hosts: BPHOSTS, encryption: {
23
- method: :simple_tls,
24
- tls_options: {
25
- ssl_version: :TLSv1_2,
26
- verify_mode: OpenSSL::SSL::VERIFY_PEER,
27
- cert_store: @cert_store
28
- }
29
- }
30
- end
31
-
32
- # using this method a user can be authenticated
33
- # Intraned ID, password are mandatory
34
- def self.authenticate(id, password)
35
- user = search id.strip
36
- unless user.nil?
37
- ldap = open_ldap
38
- ldap.auth user[:dn], password.strip
39
- begin
40
- auth = ldap.bind
41
- rescue => e
42
- raise Blueauth::BlueError, "BluePages Bind issue -> #{e.message}"
43
- end
44
- if auth
45
- groups = bluegroups user[:dn]
46
- return user.merge({groups: groups})
47
- else
48
- return nil
49
- end
50
- end
51
- end
52
-
53
- # Tries to find the given user id in Enterprise Directory and the result will be an LDAP object
54
- # user id can be
55
- # - Intranet ID (must contain '@' sign)
56
- # - Notes ID (must contain '/' sign)
57
- # - Common name (none of the previous two)
58
- # return object contains
59
- # :name, :country, :intranetid, :dn
60
- def self.search(id)
61
- if id.include? '@'
62
- searchfield = 'mail'
63
- elsif id.include? '/'
64
- searchfield = 'notesid'
65
- email_parts = id.split('/')
66
- id = ''
67
- c = 1
68
- email_parts.each do |part|
69
- id =
70
- case c
71
- when 1
72
- 'CN='+part
73
- when email_parts.count
74
- id + '/O='+part
75
- else
76
- id + '/OU='+part
77
- end
78
- c += 1
79
- end
80
- else
81
- searchfield = 'cn'
82
- end
83
- filter = Net::LDAP::Filter.eq(searchfield, id) & Net::LDAP::Filter.eq('objectclass', "ibmPerson")
84
- begin
85
- ldap = open_ldap
86
- user_array = ldap.search(base: BPBASE, filter: filter, size: 1)
87
- rescue => e
88
- raise Blueauth::BlueError, "BluePages Search issue -> #{e.message}"
89
- end
90
-
91
- if user_array.count == 0
92
- result = nil
93
- else
94
- user = user_array.first
95
- result = {name: user.cn.first, country: user.co.first, intranetid: user.preferredidentity.first, dn: user.dn}
96
- end
97
- return result
98
- end
99
-
100
- def self.bluegroups(dn)
101
- result = []
102
- filter = Net::LDAP::Filter.eq('uniquemember', dn)
103
- begin
104
- ldap = open_ldap
105
- bgres = ldap.search(base: BGBASE, filter: filter, attributes: ['cn'])
106
- bgres.each {|g| result << g.cn.first}
107
- rescue => e
108
- raise Blueauth::BlueError, "BlueGroup Search issue -> #{e.message}"
109
- end
110
- return result
111
- end
112
-
113
- end
1
+ require 'blueauth/version'
2
+ require 'blueauth/error'
3
+ require 'blueauth/certificates'
4
+ require 'net-ldap'
5
+
6
+ module Blueauth
7
+
8
+ BPBASE = 'ou=bluepages,o=ibm.com'
9
+ BGBASE = 'ou=memberlist,ou=ibmgroups,o=ibm.com'
10
+
11
+ BPHOSTS = [['bluepages.ibm.com',636], ['9.57.182.78',636], ['9.17.186.253',636]]
12
+
13
+ old_verbose, $VERBOSE = $VERBOSE, nil
14
+ Net::LDAP::LDAPControls::PAGED_RESULTS = FALSE
15
+ $VERBOSE = old_verbose
16
+
17
+ @cert_store = OpenSSL::X509::Store.new
18
+ @cert_store.add_cert OpenSSL::X509::Certificate.new(NEW_CERT)
19
+ @cert_store.add_cert OpenSSL::X509::Certificate.new(OLD_CERT)
20
+
21
+ def self.open_ldap
22
+ Net::LDAP.new hosts: BPHOSTS, encryption: {
23
+ method: :simple_tls,
24
+ tls_options: {
25
+ ssl_version: :TLSv1_2,
26
+ verify_mode: OpenSSL::SSL::VERIFY_PEER,
27
+ cert_store: @cert_store
28
+ }
29
+ }
30
+ end
31
+
32
+ # using this method a user can be authenticated
33
+ # Intraned ID, password are mandatory
34
+ def self.authenticate(id, password)
35
+ user = search id.strip
36
+ unless user.nil?
37
+ ldap = open_ldap
38
+ ldap.auth user[:dn], password.strip
39
+ begin
40
+ auth = ldap.bind
41
+ rescue => e
42
+ raise Blueauth::BlueError, "BluePages Bind issue -> #{e.message}"
43
+ end
44
+ if auth
45
+ groups = bluegroups user[:dn]
46
+ return user.merge({groups: groups})
47
+ else
48
+ return nil
49
+ end
50
+ end
51
+ end
52
+
53
+ # Tries to find the given user id in Enterprise Directory and the result will be an LDAP object
54
+ # user id can be
55
+ # - Intranet ID (must contain '@' sign)
56
+ # - Notes ID (must contain '/' sign)
57
+ # - Common name (none of the previous two)
58
+ # return object contains
59
+ # :name, :country, :intranetid, :dn
60
+ def self.search(id)
61
+ if id.include? '@'
62
+ searchfield = 'mail'
63
+ elsif id.include? '/'
64
+ searchfield = 'notesid'
65
+ email_parts = id.split('/')
66
+ id = ''
67
+ c = 1
68
+ email_parts.each do |part|
69
+ id =
70
+ case c
71
+ when 1
72
+ 'CN='+part
73
+ when email_parts.count
74
+ id + '/O='+part
75
+ else
76
+ id + '/OU='+part
77
+ end
78
+ c += 1
79
+ end
80
+ else
81
+ searchfield = 'cn'
82
+ end
83
+ filter = Net::LDAP::Filter.eq(searchfield, id) & Net::LDAP::Filter.eq('objectclass', "ibmPerson")
84
+ begin
85
+ ldap = open_ldap
86
+ user_array = ldap.search(base: BPBASE, filter: filter, size: 1)
87
+ rescue => e
88
+ raise Blueauth::BlueError, "BluePages Search issue -> #{e.message}"
89
+ end
90
+
91
+ if user_array.count == 0
92
+ result = nil
93
+ else
94
+ user = user_array.first
95
+ result = {name: user.cn.first, country: user.co.first, intranetid: user.preferredidentity.first, dn: user.dn}
96
+ end
97
+ return result
98
+ end
99
+
100
+ def self.bluegroups(dn)
101
+ result = []
102
+ filter = Net::LDAP::Filter.eq('uniquemember', dn)
103
+ begin
104
+ ldap = open_ldap
105
+ bgres = ldap.search(base: BGBASE, filter: filter, attributes: ['cn'])
106
+ bgres.each {|g| result << g.cn.first}
107
+ rescue => e
108
+ raise Blueauth::BlueError, "BlueGroup Search issue -> #{e.message}"
109
+ end
110
+ return result
111
+ end
112
+
113
+ end
@@ -1,3 +1,3 @@
1
1
  module Blueauth
2
- VERSION = "0.0.14"
2
+ VERSION = "0.0.15"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: blueauth
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.14
4
+ version: 0.0.15
5
5
  platform: ruby
6
6
  authors:
7
7
  - zoltan-izso
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-01-04 00:00:00.000000000 Z
11
+ date: 2018-01-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: net-ldap