jackad 0.2.0
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.
- data/.gitignore +19 -0
- data/Gemfile +6 -0
- data/LICENSE +22 -0
- data/README.md +47 -0
- data/Rakefile +2 -0
- data/jackad.gemspec +23 -0
- data/lib/jackad.rb +7 -0
- data/lib/jackad/ad_connect.rb +46 -0
- data/lib/jackad/config.rb +7 -0
- data/lib/jackad/jackad.rb +32 -0
- data/lib/jackad/net/ldap.rb +20 -0
- data/lib/jackad/version.rb +3 -0
- metadata +73 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 — 2013 Nick Kugaevsky
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
# Jackad
|
2
|
+
|
3
|
+
Active Directory connector gem
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'jackad'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle install
|
14
|
+
|
15
|
+
Or install it alone with:
|
16
|
+
|
17
|
+
$ gem install jackad
|
18
|
+
|
19
|
+
Configure your AD connection with YAML file `/usr/local/jackad/ldap.yml`
|
20
|
+
|
21
|
+
:host: 'example.com'
|
22
|
+
:port: 389
|
23
|
+
:base: 'dc=example,dc=com'
|
24
|
+
:attribute: 'sAMAccountName'
|
25
|
+
:method: 'simple'
|
26
|
+
:ssl: false
|
27
|
+
:admin: false
|
28
|
+
:admin_user: 'admin_username' # Only if admin:true needed
|
29
|
+
:admin_password: 'admin_password' # Only if admin:true needed
|
30
|
+
|
31
|
+
## Usage
|
32
|
+
|
33
|
+
Jackad gives you simple API to access your LDAP directory. All self methods return true or false
|
34
|
+
|
35
|
+
Jackad.credentials_valid?('username@example.com', 'user_ldap_password') # Check validity of username and password
|
36
|
+
|
37
|
+
Jackad.entry_exists?('username') # Check user existance by configured attribute
|
38
|
+
|
39
|
+
Jackad.entry_valid?(username) # Check user validity by configured attribute, useraccountcontrol flags and pwdlastset attribute
|
40
|
+
|
41
|
+
## Contributing
|
42
|
+
|
43
|
+
1. Fork it
|
44
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
45
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
46
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
47
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
data/jackad.gemspec
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/jackad/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["Nick Kugaevsky"]
|
6
|
+
gem.email = ["nick@kugaevsky.ru"]
|
7
|
+
gem.description = %q{ Simple LDAP (Active Directory) connector }
|
8
|
+
gem.summary = gem.description
|
9
|
+
gem.homepage = "https://github.com/pantsu/jackad"
|
10
|
+
|
11
|
+
gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
12
|
+
gem.files = `git ls-files`.split("\n")
|
13
|
+
gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
14
|
+
gem.name = "jackad"
|
15
|
+
gem.require_paths = ["lib"]
|
16
|
+
gem.version = Jackad::VERSION
|
17
|
+
|
18
|
+
gem.add_dependency 'net-ldap', '~>0.2.0'
|
19
|
+
# gem.add_dependency 'yaml'
|
20
|
+
|
21
|
+
#gem.add_development_dependency('rspec')
|
22
|
+
|
23
|
+
end
|
data/lib/jackad.rb
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
module Jackad
|
2
|
+
class AdConnect
|
3
|
+
|
4
|
+
attr_reader :ldap, :attribute
|
5
|
+
|
6
|
+
def initialize(params = {})
|
7
|
+
options = Jackad::Config.setup
|
8
|
+
|
9
|
+
@ldap = Net::LDAP.new(params)
|
10
|
+
@ldap.host = options[:host]
|
11
|
+
@ldap.port = options[:port]
|
12
|
+
@ldap.base = options[:base]
|
13
|
+
@attribute = params[:attribute] || options[:attribute]
|
14
|
+
@login = params[:login] || options[:admin_user]
|
15
|
+
@password = params[:password] || options[:admin_password]
|
16
|
+
|
17
|
+
@ldap.auth @login, @password
|
18
|
+
|
19
|
+
@new_password = params[:new_password]
|
20
|
+
end
|
21
|
+
|
22
|
+
# Gets entry attributes from LDAP
|
23
|
+
def get_entry_data(username, attrs = [] )
|
24
|
+
filter = Net::LDAP::Filter.eq(@attribute.to_s, username)
|
25
|
+
search_params = { filter: filter, size: 1 }
|
26
|
+
search_params[:attributes] = attrs unless attrs.empty?
|
27
|
+
@ldap.search(search_params)[0]
|
28
|
+
end
|
29
|
+
|
30
|
+
# Gets user guid from LDAP.
|
31
|
+
# Returns binary Net::BER::BerIdentifiedString
|
32
|
+
def get_entry_guid(username)
|
33
|
+
filter = Net::LDAP::Filter.eq(@attribute.to_s, username)
|
34
|
+
result = @ldap.search(filter: filter, attributes: ['objectguid'], size: 1)
|
35
|
+
result.size > 0 ? result[0]['objectguid'][0] : nil
|
36
|
+
end
|
37
|
+
|
38
|
+
# Gets user guid from LDAP.
|
39
|
+
# Returns string.
|
40
|
+
def get_entry_guid_as_string(username)
|
41
|
+
username = get_entry_guid(username)
|
42
|
+
username.unpack('H*')[0].upcase unless username.nil?
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module Jackad
|
2
|
+
class ConnectionRefused < StandardError; end
|
3
|
+
class RecordNotFound < StandardError; end
|
4
|
+
|
5
|
+
# Check validity of username and password
|
6
|
+
# Returns true or false
|
7
|
+
def self.credentials_valid?(username, password)
|
8
|
+
ad = AdConnect.new
|
9
|
+
ad.ldap.auth(username, password)
|
10
|
+
ad.ldap.bind
|
11
|
+
end
|
12
|
+
|
13
|
+
# Check user existance by configured attribute
|
14
|
+
# Returns true or false
|
15
|
+
def self.entry_exists?(username)
|
16
|
+
ad = AdConnect.new
|
17
|
+
filter = Net::LDAP::Filter.eq(ad.attribute.to_s, username)
|
18
|
+
ad.ldap.search(filter: filter, size: 1).size > 0 ? true : false
|
19
|
+
end
|
20
|
+
|
21
|
+
# Check user validity by configured attribute, useraccountcontrol flags and pwdlastset attribute
|
22
|
+
# Returns true or false
|
23
|
+
def self.entry_valid?(username)
|
24
|
+
ad = AdConnect.new
|
25
|
+
filter_by_attr = Net::LDAP::Filter.eq(ad.attribute.to_s, username)
|
26
|
+
filter_by_uac = ~Net::LDAP::Filter.construct('useraccountcontrol:1.2.840.113556.1.4.803:=2')
|
27
|
+
filter_by_pass = ~Net::LDAP::Filter.eq('pwdlastset', '0')
|
28
|
+
filter = filter_by_attr & filter_by_uac & filter_by_pass
|
29
|
+
ad.ldap.search(filter: filter, size: 1).size > 0 ? true : false
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require "net/ldap"
|
2
|
+
|
3
|
+
module Jackad
|
4
|
+
module Net
|
5
|
+
class LDAP < ::Net::LDAP
|
6
|
+
|
7
|
+
def search(args = {})
|
8
|
+
super(args) || []
|
9
|
+
rescue => e
|
10
|
+
case e.message
|
11
|
+
when /refused connection/
|
12
|
+
raise Jackad::ConnectionRefused, e.message
|
13
|
+
else
|
14
|
+
raise
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
metadata
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: jackad
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease:
|
5
|
+
version: 0.2.0
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Nick Kugaevsky
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-01-15 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: net-ldap
|
16
|
+
type: :runtime
|
17
|
+
requirement: !ruby/object:Gem::Requirement
|
18
|
+
none: false
|
19
|
+
requirements:
|
20
|
+
- - ~>
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 0.2.0
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 0.2.0
|
30
|
+
description: ! ' Simple LDAP (Active Directory) connector '
|
31
|
+
email:
|
32
|
+
- nick@kugaevsky.ru
|
33
|
+
executables: []
|
34
|
+
extensions: []
|
35
|
+
extra_rdoc_files: []
|
36
|
+
files:
|
37
|
+
- .gitignore
|
38
|
+
- Gemfile
|
39
|
+
- LICENSE
|
40
|
+
- README.md
|
41
|
+
- Rakefile
|
42
|
+
- jackad.gemspec
|
43
|
+
- lib/jackad.rb
|
44
|
+
- lib/jackad/ad_connect.rb
|
45
|
+
- lib/jackad/config.rb
|
46
|
+
- lib/jackad/jackad.rb
|
47
|
+
- lib/jackad/net/ldap.rb
|
48
|
+
- lib/jackad/version.rb
|
49
|
+
homepage: https://github.com/pantsu/jackad
|
50
|
+
licenses: []
|
51
|
+
post_install_message:
|
52
|
+
rdoc_options: []
|
53
|
+
require_paths:
|
54
|
+
- lib
|
55
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
56
|
+
none: false
|
57
|
+
requirements:
|
58
|
+
- - ! '>='
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '0'
|
61
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
62
|
+
none: false
|
63
|
+
requirements:
|
64
|
+
- - ! '>='
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: '0'
|
67
|
+
requirements: []
|
68
|
+
rubyforge_project:
|
69
|
+
rubygems_version: 1.8.24
|
70
|
+
signing_key:
|
71
|
+
specification_version: 3
|
72
|
+
summary: Simple LDAP (Active Directory) connector
|
73
|
+
test_files: []
|