el_dap 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/CHANGELOG +5 -0
- data/README.rdoc +10 -0
- data/el_dap.gemspec +19 -4
- data/lib/el_dap.rb +3 -1
- data/lib/el_dap/base.rb +10 -12
- data/lib/el_dap/time_cop.rb +29 -0
- data/lib/el_dap/version.rb +1 -1
- data/spec/el_dap/base_spec.rb +7 -0
- data/spec/el_dap/time_cop_spec.rb +19 -0
- metadata +21 -9
- data/lib/el_dap/.rvmrc +0 -10
data/.gitignore
CHANGED
data/CHANGELOG
CHANGED
data/README.rdoc
CHANGED
@@ -16,11 +16,21 @@ Additionally, users are also able to search the Active Directory.
|
|
16
16
|
Just add this to your gem file:
|
17
17
|
|
18
18
|
gem 'el_dap'
|
19
|
+
|
20
|
+
=== Ruby Version Dependencies
|
21
|
+
|
22
|
+
ElDap will work out of the box with Ruby 1.9.
|
23
|
+
|
24
|
+
If you are using Ruby 1.8, you will need to manually install the *SystemTimer* gem so that timeout exceptions are handled
|
25
|
+
correctly. You will not be able to install ElDap on Ruby 1.8 unless you have this gem.
|
26
|
+
|
27
|
+
gem install SystemTimer
|
19
28
|
|
20
29
|
== Features
|
21
30
|
|
22
31
|
* Easily perform authentication against an Active Directory / LDAP server
|
23
32
|
* Search an Active Directory based on wildcard search criteria
|
33
|
+
* Use multiple servers to protect against timeouts
|
24
34
|
|
25
35
|
== Usage
|
26
36
|
|
data/el_dap.gemspec
CHANGED
@@ -1,4 +1,8 @@
|
|
1
|
-
|
1
|
+
#!/usr/bin/env gem build
|
2
|
+
# encoding: utf-8
|
3
|
+
|
4
|
+
require 'base64'
|
5
|
+
|
2
6
|
$:.push File.expand_path("../lib", __FILE__)
|
3
7
|
require "el_dap/version"
|
4
8
|
|
@@ -7,10 +11,10 @@ Gem::Specification.new do |s|
|
|
7
11
|
s.version = ElDap::VERSION
|
8
12
|
s.platform = Gem::Platform::RUBY
|
9
13
|
s.authors = ["Ed James"]
|
10
|
-
s.email =
|
14
|
+
s.email = Base64.decode64("ZWQuamFtZXMuZW1haWxAZ21haWwuY29t\n")
|
11
15
|
s.homepage = "https://github.com/edjames/el_dap"
|
12
|
-
s.summary =
|
13
|
-
s.description =
|
16
|
+
s.summary = "Simple search and authentication tool for Active Directory"
|
17
|
+
s.description = "#{s.summary}. This included support for both Ruby 1.9 and ruby 1.8 (using the SystemTimer gem)."
|
14
18
|
|
15
19
|
s.rubyforge_project = "el_dap"
|
16
20
|
|
@@ -20,4 +24,15 @@ Gem::Specification.new do |s|
|
|
20
24
|
s.require_paths = ["lib"]
|
21
25
|
|
22
26
|
s.add_dependency("net-ldap", "~> 0.2.2")
|
27
|
+
s.add_development_dependency "bundler"
|
28
|
+
|
29
|
+
# If Ruby version is 1.8 then check for SystemTimer gem
|
30
|
+
if RUBY_VERSION < "1.9"
|
31
|
+
begin
|
32
|
+
require 'system_timer'
|
33
|
+
rescue LoadError => ex
|
34
|
+
warn "WARNING: To use ElDap in Ruby 1.8 you must have the SystemTimer gem installed. Please run: gem install SystemTimer"
|
35
|
+
raise ex.message
|
36
|
+
end
|
37
|
+
end
|
23
38
|
end
|
data/lib/el_dap.rb
CHANGED
@@ -1,11 +1,13 @@
|
|
1
1
|
require 'net/ldap'
|
2
|
-
require 'timeout'
|
3
2
|
|
3
|
+
|
4
|
+
$: << File.dirname(__FILE__)
|
4
5
|
require 'el_dap/api_methods'
|
5
6
|
require 'el_dap/constants'
|
6
7
|
require 'el_dap/exceptions'
|
7
8
|
require 'el_dap/validator'
|
8
9
|
require 'el_dap/worker'
|
10
|
+
require 'el_dap/time_cop'
|
9
11
|
require 'el_dap/base'
|
10
12
|
|
11
13
|
module ElDap
|
data/lib/el_dap/base.rb
CHANGED
@@ -1,19 +1,19 @@
|
|
1
1
|
module ElDap
|
2
2
|
class Base
|
3
3
|
attr_accessor :server_ips, :username, :password, :timeout, :treebase
|
4
|
-
|
4
|
+
|
5
5
|
def initialize
|
6
6
|
@server_ips = []
|
7
7
|
@timeout = 15
|
8
8
|
yield(self) if block_given?
|
9
9
|
end
|
10
|
-
|
10
|
+
|
11
11
|
def validate(username, password)
|
12
12
|
return false if Validator.blank?(username, password)
|
13
|
-
|
13
|
+
|
14
14
|
@server_ips.each do |ip_address|
|
15
15
|
begin
|
16
|
-
|
16
|
+
TimeCop.timer.timeout(self.timeout) do
|
17
17
|
worker = Worker.new(:username => username, :password => password, :ip_address => ip_address)
|
18
18
|
return worker.bind
|
19
19
|
end
|
@@ -22,26 +22,24 @@ module ElDap
|
|
22
22
|
end
|
23
23
|
end
|
24
24
|
end
|
25
|
-
|
25
|
+
|
26
26
|
def search(search_string)
|
27
27
|
return nil if Validator.blank?(search_string)
|
28
|
-
|
29
|
-
search_result = []
|
30
|
-
|
28
|
+
|
31
29
|
@server_ips.each do |ip_address|
|
32
30
|
begin
|
33
|
-
|
31
|
+
TimeCop.timer.timeout(self.timeout) do
|
34
32
|
worker = Worker.new(:username => self.username, :password => self.password, :ip_address => ip_address)
|
35
|
-
|
36
33
|
raise(InvalidCredentialsError, 'The user credentials provided are invalid') unless worker.bind
|
37
|
-
|
38
34
|
return worker.search_directory(search_string, self.treebase)
|
39
35
|
end
|
40
36
|
rescue Timeout::Error
|
41
37
|
next
|
42
38
|
end
|
43
39
|
end
|
40
|
+
|
41
|
+
false
|
44
42
|
end
|
45
|
-
|
43
|
+
|
46
44
|
end
|
47
45
|
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module ElDap
|
2
|
+
class TimeCop
|
3
|
+
|
4
|
+
def self.timer
|
5
|
+
if ruby_version < "1.9"
|
6
|
+
use_system_timer
|
7
|
+
else
|
8
|
+
use_timeout
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
private
|
13
|
+
|
14
|
+
def self.ruby_version
|
15
|
+
RUBY_VERSION
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.use_system_timer
|
19
|
+
require 'system_timer'
|
20
|
+
SystemTimer
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.use_timeout
|
24
|
+
require 'timeout'
|
25
|
+
Timeout
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
end
|
data/lib/el_dap/version.rb
CHANGED
data/spec/el_dap/base_spec.rb
CHANGED
@@ -3,6 +3,7 @@ require 'spec_helper'
|
|
3
3
|
module ElDap
|
4
4
|
describe Base do
|
5
5
|
before(:each) do
|
6
|
+
allow_message_expectations_on_nil
|
6
7
|
@instance = Base.new do |i|
|
7
8
|
i.username = 'name'
|
8
9
|
i.password = 'password'
|
@@ -74,6 +75,12 @@ module ElDap
|
|
74
75
|
@instance.search('name').should == ['result']
|
75
76
|
end
|
76
77
|
|
78
|
+
it "should return false when all servers timeout" do
|
79
|
+
@worker.stub(:bind).and_return(true)
|
80
|
+
@worker.stub(:search_directory).and_raise(Timeout::Error)
|
81
|
+
@instance.search('name').should be_false
|
82
|
+
end
|
83
|
+
|
77
84
|
it "should throw an exception if the search user credentials are invalid" do
|
78
85
|
@worker.should_receive(:bind).and_return(false)
|
79
86
|
lambda{ @instance.search('name') }.should raise_error(InvalidCredentialsError, 'The user credentials provided are invalid')
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module ElDap
|
4
|
+
describe TimeCop do
|
5
|
+
|
6
|
+
it "should use the SystemTimer gem when Ruby version is 1.8" do
|
7
|
+
TimeCop.should_receive(:ruby_version).and_return('1.8')
|
8
|
+
TimeCop.should_receive(:use_system_timer)
|
9
|
+
TimeCop.timer
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should use the SystemTimer gem when Ruby version is 1.9" do
|
13
|
+
TimeCop.should_receive(:ruby_version).and_return('1.9')
|
14
|
+
TimeCop.should_receive(:use_timeout)
|
15
|
+
TimeCop.timer
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: el_dap
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2011-04-
|
12
|
+
date: 2011-04-21 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: net-ldap
|
16
|
-
requirement: &
|
16
|
+
requirement: &79902310 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
@@ -21,10 +21,21 @@ dependencies:
|
|
21
21
|
version: 0.2.2
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
25
|
-
|
26
|
-
|
27
|
-
|
24
|
+
version_requirements: *79902310
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: bundler
|
27
|
+
requirement: &79902100 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
type: :development
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *79902100
|
36
|
+
description: Simple search and authentication tool for Active Directory. This included
|
37
|
+
support for both Ruby 1.9 and ruby 1.8 (using the SystemTimer gem).
|
38
|
+
email: ed.james.email@gmail.com
|
28
39
|
executables: []
|
29
40
|
extensions: []
|
30
41
|
extra_rdoc_files: []
|
@@ -40,17 +51,18 @@ files:
|
|
40
51
|
- TODO.rdoc
|
41
52
|
- el_dap.gemspec
|
42
53
|
- lib/el_dap.rb
|
43
|
-
- lib/el_dap/.rvmrc
|
44
54
|
- lib/el_dap/api_methods.rb
|
45
55
|
- lib/el_dap/base.rb
|
46
56
|
- lib/el_dap/constants.rb
|
47
57
|
- lib/el_dap/exceptions.rb
|
58
|
+
- lib/el_dap/time_cop.rb
|
48
59
|
- lib/el_dap/validator.rb
|
49
60
|
- lib/el_dap/version.rb
|
50
61
|
- lib/el_dap/worker.rb
|
51
62
|
- spec/el_dap/api_methods_spec.rb
|
52
63
|
- spec/el_dap/base_spec.rb
|
53
64
|
- spec/el_dap/constants_spec.rb
|
65
|
+
- spec/el_dap/time_cop_spec.rb
|
54
66
|
- spec/el_dap/validator_spec.rb
|
55
67
|
- spec/el_dap/worker_spec.rb
|
56
68
|
- spec/spec_helper.rb
|
@@ -77,5 +89,5 @@ rubyforge_project: el_dap
|
|
77
89
|
rubygems_version: 1.7.2
|
78
90
|
signing_key:
|
79
91
|
specification_version: 3
|
80
|
-
summary:
|
92
|
+
summary: Simple search and authentication tool for Active Directory
|
81
93
|
test_files: []
|
data/lib/el_dap/.rvmrc
DELETED
@@ -1,10 +0,0 @@
|
|
1
|
-
#!/usr/bin/env bash
|
2
|
-
environment_id="ruby-1.9.2-head@el_dap"
|
3
|
-
|
4
|
-
if [[ -d "${rvm_path:-$HOME/.rvm}/environments" \
|
5
|
-
&& -s "${rvm_path:-$HOME/.rvm}/environments/$environment_id" ]] ; then
|
6
|
-
\. "${rvm_path:-$HOME/.rvm}/environments/$environment_id"
|
7
|
-
else
|
8
|
-
rvm --create "$environment_id"
|
9
|
-
fi
|
10
|
-
|