blueauth 0.0.5
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.
- checksums.yaml +7 -0
- data/.gitignore +10 -0
- data/.rspec +2 -0
- data/.travis.yml +4 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +55 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/blueauth.gemspec +37 -0
- data/lib/blueauth.rb +96 -0
- data/lib/blueauth/error.rb +19 -0
- data/lib/blueauth/version.rb +3 -0
- metadata +115 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 59aac8d5b398a5a4eca4c258b8cea6c4ea55522b
|
4
|
+
data.tar.gz: 5bf67c57e5e13373f728b2d7b2eb10b4709e1fbe
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: df93080542f4398640c7de6fe6bb7a4902a8b78fe7d99adcf75b3e4476dd4e7952a75bb119fb51075cbaad82aab81b978e4ce970ec0ef9d58f2220c1018edd6f
|
7
|
+
data.tar.gz: 2519db022a4d4f7aa80b16f811663ff5617e34981f38f77f0724ff8d0c5e7438d3288fc93cb50cb47d40a25c0718482101ee79e2e23d6201d031ec281262e807
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 mawwerik
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
# Blueauth
|
2
|
+
|
3
|
+
The purpose of this gem is to allow IBMers to search and authenticate user that are registered in IBM's Enterprise Directory. This gem can only be used in IBM's Intranet network. Every IBM employee can be searched based on his/her Intraned ID, or Notes ID, or Common name.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'blueauth'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle install
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install blueauth
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
#### Search for a user if she/he exists in IBM's Enterprise Directory
|
24
|
+
|
25
|
+
The userid can be Intranet ID or Notes ID or Common name
|
26
|
+
|
27
|
+
Blueauth::search 'istvan.kovacs@hu.ibm.com'
|
28
|
+
Blueauth::search 'Istvan Kovacs/Hungary/IBM'
|
29
|
+
Blueauth::search 'Istvan Kovacs'
|
30
|
+
|
31
|
+
If the user is found, then the returned object will be a hash: {:name, :country, :intranetid, :dn}. If the user is not found, then nil
|
32
|
+
|
33
|
+
|
34
|
+
#### Search for a user's Bluegroups
|
35
|
+
|
36
|
+
First, the user must exist in Enterprise Directory, and the Bluegroup can be queried based on the DN of the user
|
37
|
+
|
38
|
+
user = Blueauth::search 'istvan.kovacs@hu.ibm.com'
|
39
|
+
Blueauth::bluegroups user[:dn]
|
40
|
+
|
41
|
+
Returned object will be an Array of strings containing the names of Bluegroups where the user is assigned to.
|
42
|
+
|
43
|
+
#### Authenticate a user with his/her password
|
44
|
+
|
45
|
+
The userid can be Intranet ID or Notes ID or Common name
|
46
|
+
|
47
|
+
Blueauth::authenticate 'istvan.kovacs@hu.ibm.com', 'password'
|
48
|
+
Blueauth::authenticate 'Istvan Kovacs/Hungary/IBM', 'password'
|
49
|
+
Blueauth::authenticate 'Istvan Kovacs', 'password'
|
50
|
+
|
51
|
+
If the user is found, then the returned object will be a hash: {:name, :country, :intranetid, :dn, :groups}. Groups is an array containing all Bluegroups. If the user is not found, then nil
|
52
|
+
|
53
|
+
#### In case of any problem with LDAP server will throw an Exception
|
54
|
+
|
55
|
+
Blueauth::BlueError
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "blueauth"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
data/blueauth.gemspec
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
original_verbose, $VERBOSE = $VERBOSE, nil
|
4
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
|
+
$VERBOSE = original_verbose
|
6
|
+
require 'blueauth/version'
|
7
|
+
|
8
|
+
Gem::Specification.new do |spec|
|
9
|
+
spec.name = "blueauth"
|
10
|
+
spec.version = Blueauth::VERSION
|
11
|
+
spec.authors = ["zoltan-izso"]
|
12
|
+
spec.email = ["zoltan.izso@hu.ibm.com"]
|
13
|
+
|
14
|
+
spec.summary = %q{Bluepages Authentication for IBMers within IBM's Intranet}
|
15
|
+
spec.description = %q{Bluepages Authentication for IBMers within IBM's Intranet}
|
16
|
+
#spec.homepage = "Currently there is no homepage specified"
|
17
|
+
spec.license = "MIT"
|
18
|
+
|
19
|
+
# Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
|
20
|
+
# delete this section to allow pushing this gem to any host.
|
21
|
+
if spec.respond_to?(:metadata)
|
22
|
+
spec.metadata['allowed_push_host'] = 'https://rubygems.org'
|
23
|
+
else
|
24
|
+
raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
|
25
|
+
end
|
26
|
+
|
27
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
28
|
+
spec.bindir = "exe"
|
29
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
30
|
+
spec.require_paths = ["lib"]
|
31
|
+
|
32
|
+
spec.add_dependency 'net-ldap', '~>0.11'
|
33
|
+
|
34
|
+
spec.add_development_dependency "bundler", "~> 1.11"
|
35
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
36
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
37
|
+
end
|
data/lib/blueauth.rb
ADDED
@@ -0,0 +1,96 @@
|
|
1
|
+
require "blueauth/version"
|
2
|
+
require "blueauth/error"
|
3
|
+
require 'net-ldap'
|
4
|
+
|
5
|
+
module Blueauth
|
6
|
+
|
7
|
+
Net::LDAP::LDAPControls::PAGED_RESULTS = FALSE
|
8
|
+
|
9
|
+
BPHOST = "bluepages.ibm.com"
|
10
|
+
BGHOST = "bluegroups.ibm.com"
|
11
|
+
BPBASE = "ou=bluepages,o=ibm.com"
|
12
|
+
BGBASE = "ou=memberlist,ou=ibmgroups,o=ibm.com"
|
13
|
+
|
14
|
+
# using this method a user can be authenticated
|
15
|
+
# Intraned ID, password are mandatory
|
16
|
+
def self.authenticate id, password
|
17
|
+
ldap = Net::LDAP.new host: BPHOST, port: 636, base: BPBASE, :encryption => :simple_tls
|
18
|
+
user = search id.strip
|
19
|
+
unless user.nil?
|
20
|
+
ldap.auth user[:dn], password.strip
|
21
|
+
begin
|
22
|
+
auth = ldap.bind
|
23
|
+
rescue => e
|
24
|
+
raise Blueauth::BlueError, "BluePages Bind issue -> #{e.message}"
|
25
|
+
end
|
26
|
+
if auth
|
27
|
+
groups = bluegroups user[:dn]
|
28
|
+
return user.merge({groups: groups})
|
29
|
+
else
|
30
|
+
return nil
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
# Tries to find the given user id in Enterprise Directory and the result will be an LDAP object
|
36
|
+
# user id can be
|
37
|
+
# - Intranet ID (must contain '@' sign)
|
38
|
+
# - Notes ID (must contain '/' sign)
|
39
|
+
# - Common name (none of the previous two)
|
40
|
+
# return object contains
|
41
|
+
# :name, :country, :intranetid, :dn
|
42
|
+
def self.search id
|
43
|
+
ldap = Net::LDAP.new host: BPHOST, port: 636, base: BPBASE, :encryption => :simple_tls
|
44
|
+
if id.include? '@'
|
45
|
+
searchfield = 'mail'
|
46
|
+
elsif id.include? '/'
|
47
|
+
searchfield = 'notesid'
|
48
|
+
email_parts = id.split('/')
|
49
|
+
id = ''
|
50
|
+
c = 1
|
51
|
+
email_parts.each do |part|
|
52
|
+
case c
|
53
|
+
when 1
|
54
|
+
id = 'CN='+part
|
55
|
+
when email_parts.count
|
56
|
+
id = id + '/O='+part
|
57
|
+
else
|
58
|
+
id = id + '/OU='+part
|
59
|
+
end
|
60
|
+
c += 1
|
61
|
+
end
|
62
|
+
else
|
63
|
+
searchfield = 'cn'
|
64
|
+
end
|
65
|
+
filter = Net::LDAP::Filter.eq(searchfield, id) & Net::LDAP::Filter.eq('objectclass', "ibmPerson")
|
66
|
+
begin
|
67
|
+
user_array = ldap.search(base: BPBASE, filter: filter, size: 1)
|
68
|
+
rescue => e
|
69
|
+
raise Blueauth::BlueError, "BluePages Search issue -> #{e.message}"
|
70
|
+
end
|
71
|
+
|
72
|
+
if user_array.count == 0
|
73
|
+
result = nil
|
74
|
+
else
|
75
|
+
user = user_array.first
|
76
|
+
result = {name: user.cn.first, country: user.co.first, intranetid: user.preferredidentity.first, dn: user.dn}
|
77
|
+
end
|
78
|
+
|
79
|
+
return result
|
80
|
+
end
|
81
|
+
|
82
|
+
def self.bluegroups dn
|
83
|
+
result = []
|
84
|
+
bg = Net::LDAP.new host: BGHOST, port: 389, base: BGBASE
|
85
|
+
bgf = Net::LDAP::Filter.eq('uniquemember', dn)
|
86
|
+
begin
|
87
|
+
bgres = bg.search(base: BGBASE, filter: bgf, attributes: ['cn'])
|
88
|
+
rescue => e
|
89
|
+
raise Blueauth::BlueError, "BlueGroup Search issue -> #{e.message}"
|
90
|
+
end
|
91
|
+
bgres.each {|g| result << g.cn.first}
|
92
|
+
|
93
|
+
return result
|
94
|
+
end
|
95
|
+
|
96
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Blueauth
|
2
|
+
class Error < StandardError
|
3
|
+
|
4
|
+
def initialize(options = {})
|
5
|
+
options.is_a?(String) ? @options = {:message => options} : @options = options
|
6
|
+
end
|
7
|
+
|
8
|
+
def message
|
9
|
+
@options[:message]
|
10
|
+
end
|
11
|
+
|
12
|
+
def options
|
13
|
+
@options
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
class BlueError < Error
|
18
|
+
end
|
19
|
+
end
|
metadata
ADDED
@@ -0,0 +1,115 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: blueauth
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.5
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- zoltan-izso
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-04-15 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.11'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0.11'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.11'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.11'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '10.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '10.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '3.0'
|
69
|
+
description: Bluepages Authentication for IBMers within IBM's Intranet
|
70
|
+
email:
|
71
|
+
- zoltan.izso@hu.ibm.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- ".gitignore"
|
77
|
+
- ".idea/vcs.xml"
|
78
|
+
- ".rspec"
|
79
|
+
- ".travis.yml"
|
80
|
+
- Gemfile
|
81
|
+
- LICENSE.txt
|
82
|
+
- README.md
|
83
|
+
- Rakefile
|
84
|
+
- bin/console
|
85
|
+
- bin/setup
|
86
|
+
- blueauth.gemspec
|
87
|
+
- lib/blueauth.rb
|
88
|
+
- lib/blueauth/error.rb
|
89
|
+
- lib/blueauth/version.rb
|
90
|
+
homepage:
|
91
|
+
licenses:
|
92
|
+
- MIT
|
93
|
+
metadata:
|
94
|
+
allowed_push_host: https://rubygems.org
|
95
|
+
post_install_message:
|
96
|
+
rdoc_options: []
|
97
|
+
require_paths:
|
98
|
+
- lib
|
99
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
105
|
+
requirements:
|
106
|
+
- - ">="
|
107
|
+
- !ruby/object:Gem::Version
|
108
|
+
version: '0'
|
109
|
+
requirements: []
|
110
|
+
rubyforge_project:
|
111
|
+
rubygems_version: 2.4.5.1
|
112
|
+
signing_key:
|
113
|
+
specification_version: 4
|
114
|
+
summary: Bluepages Authentication for IBMers within IBM's Intranet
|
115
|
+
test_files: []
|