soar_ldap 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: def8660c3a9aab179dcb6135d71ef1bc7b44d498
4
+ data.tar.gz: 203eae89e13f58d405fc0d99fb60ba15a84f9ae7
5
+ SHA512:
6
+ metadata.gz: dddbeba8a02711054d8a89324db8109dc9aa4c8be371969a00317a036c1ee6c7bf3ed0d0bad1bd18ff69d02bbed209192b36aed9afdee0310744bbe12d943a5b
7
+ data.tar.gz: c329706fef6bd445f5f42fa45210bb3e5a10245f336a1baf05a59eb416d70bd68ec76b0894e54d5375bca658d2a76917bed70769ffcb9776b59d149d7d0b8c47
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ .byebug_history
2
+ /.bundle/
3
+ /.yardoc
4
+ /Gemfile.lock
5
+ /_yardoc/
6
+ /coverage/
7
+ /doc/
8
+ /pkg/
9
+ /spec/reports/
10
+ /tmp/
11
+ *.gem
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.ruby-gemset ADDED
@@ -0,0 +1 @@
1
+ soar_ldap
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ ruby-2.0.0-p643
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in soar_ldap.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Ernst van Graan
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,49 @@
1
+ # SoarLdap
2
+
3
+ SoarLdap is a simplified LDAP client library allowing easy access to entries on LDAP servers, using LDAP protocol version 3, for use in the SOAR architecture. SoarLdap has an optional built-in cache, which reduces the requirement for connections to the LDAP server. Freshness of 0 disables the cache. Freshness is in seconds.
4
+
5
+ SoarLdap adheres to the SoarIdm::DirectoryProvider specification for diretory providers.
6
+
7
+ The finder find_entity can be over-ridden to model specific search behaviour. By default, get_entity establishes a connection and calls find_entity, which searches the subtree for UUIDs matching the identifier specified, or for dn entries which include the identifier specifier. By default the finder includes the following fields: 'objectClass', 'cn', 'dn', 'entryuuid', 'description' and returns only the first entry found. You might want to override find_entity to return an array if you expect multiple results.
8
+
9
+ SoarLdap will raise a SoarLdapError if it encounters unexpected or invalid configuration or state. get_entity returns an LDAP::Entry. connect returns LDAP::Conn.
10
+
11
+ ## Installation
12
+
13
+ Add this line to your application's Gemfile:
14
+
15
+ gem 'soar_ldap'
16
+
17
+ And then execute:
18
+
19
+ bundle
20
+
21
+ Or install it yourself as:
22
+
23
+ gem install soar_ldap
24
+
25
+ ## Usage
26
+ spec.add_development_dependency 'soar_ldap'
27
+ bundle exec irb
28
+
29
+ require 'soar_ldap'
30
+ configuration = { 'server' => 'my.server.com', 'port' => 389, 'node' => 'dc=directory,dc=my,dc=server,dc=com', freshness => 0 }
31
+ credentials = { 'username' => 'ldap-user', 'password' => 'ldap-password' }
32
+ @soar_ldap = SoarLdap::LdapProvider.new(configuration)
33
+ @soar_ldap.authenticate(credentials)
34
+ puts "This LDAP Provider operated on #{@soar_ldap.uri}"
35
+ @soar_ldap.connect if @soar_ldap.bootstrapped?
36
+ # returns LDAP::Conn
37
+ puts "Connected? #{@soar_ldap.connected?}"
38
+ ldap_entry = @soar_ldap.get_entity('findme') if @soar_ldap.ready?
39
+ # LDAP::Entry
40
+
41
+ ## Contributing
42
+
43
+ Bug reports and feature requests are welcome by email to ernst dot van dot graan at hetzner dot co dot za. This gem is sponsored by Hetzner (Pty) Ltd (http://hetzner.co.za)
44
+
45
+
46
+ ## License
47
+
48
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
49
+
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,3 @@
1
+ module SoarLdap
2
+ VERSION = "0.0.1"
3
+ end
data/lib/soar_ldap.rb ADDED
@@ -0,0 +1,116 @@
1
+ require "soar_ldap/version"
2
+ require 'ldap'
3
+ require 'ldap/control'
4
+ require 'soar_idm/directory_provider'
5
+ #require 'byebug'
6
+
7
+ module SoarLdap
8
+ class SoarLdapError < StandardError
9
+ end
10
+
11
+ class LdapProvider < SoarIdm::DirectoryProvider
12
+ attr_reader :configuration
13
+ attr_reader :path
14
+ attr_reader :server
15
+ attr_reader :port
16
+ attr_reader :credentials
17
+ attr_reader :username
18
+ attr_reader :password
19
+ attr_reader :connection
20
+
21
+ def initialize(configuration)
22
+ bootstrap(configuration)
23
+ end
24
+
25
+ def bootstrap(configuration)
26
+ @configuration = nil
27
+ validate_configuration(configuration)
28
+ remember_configuration(configuration)
29
+ end
30
+
31
+ def bootstrapped?
32
+ not @configuration.nil?
33
+ end
34
+
35
+ def authenticate(credentials)
36
+ @credentials = nil
37
+ validate_credentials(credentials)
38
+ remember_credentials(credentials)
39
+ end
40
+
41
+ def connect
42
+ @connection = ::LDAP::Conn.new(@server, @port)
43
+ @connection.set_option(::LDAP::LDAP_OPT_PROTOCOL_VERSION, 3)
44
+ @connection.bind(@username, @password)
45
+ @connection
46
+
47
+ rescue => ex
48
+ raise SoarLdapError.new("Connection error + #{ex}")
49
+ end
50
+
51
+ def connected?
52
+ not @connection.nil?
53
+ end
54
+
55
+ def ready?
56
+ bootstrapped? and connected?
57
+ end
58
+
59
+ def uri
60
+ raise SoarLdapError.new('Not bootstrapped') if not bootstrapped?
61
+ "ldap://#{server}:#{port}/#{@path}"
62
+ end
63
+
64
+ def get_entity(identifier)
65
+ connect if not connected?
66
+ find_entity(@connection, identifier)
67
+
68
+ rescue => ex
69
+ raise SoarLdapError.new("Lookup error, #{ex}")
70
+ end
71
+
72
+ protected
73
+
74
+ def find_entity(connection, identifier)
75
+ connection.search(@path, ::LDAP::LDAP_SCOPE_SUBTREE, 'objectClass=*', ['objectClass', 'cn', 'dn', 'entryuuid', 'description']) do |entry|
76
+ uuid = entry['entryUUID'].first
77
+ dn = entry.dn
78
+ return entry if uuid == identifier
79
+ return entry if dn and dn.include?(identifier)
80
+ end
81
+ nil
82
+ end
83
+
84
+ private
85
+
86
+ def validate_configuration(configuration)
87
+ raise SoarLdapError.new('No configuration') if configuration.nil?
88
+ raise SoarLdapError.new('Empty configuration') if configuration == {}
89
+ raise SoarLdapError.new('Invalid configuration') if not configuration.is_a?(Hash)
90
+ raise SoarLdapError.new('Missing server') if configuration['server'].nil?
91
+ raise SoarLdapError.new('Missing port') if configuration['port'].nil?
92
+ raise SoarLdapError.new('Missing path') if configuration['path'].nil?
93
+ end
94
+
95
+ def validate_credentials(credentials)
96
+ raise SoarLdapError.new('Missing credentials') if credentials.nil?
97
+ raise SoarLdapError.new('Empty credentials') if credentials == {}
98
+ raise SoarLdapError.new('Invalid credentials') if not credentials.is_a?(Hash)
99
+ raise SoarLdapError.new('Missing username') if credentials['username'].nil?
100
+ raise SoarLdapError.new('Missing password') if credentials['password'].nil?
101
+ end
102
+
103
+ def remember_configuration(configuration)
104
+ @configuration = configuration
105
+ @server = @configuration['server']
106
+ @port = @configuration['port'].to_i
107
+ @path = @configuration['path']
108
+ end
109
+
110
+ def remember_credentials(credentials)
111
+ @credentials = credentials
112
+ @username = @credentials['username']
113
+ @password = @credentials['password']
114
+ end
115
+ end
116
+ end
data/soar_ldap.gemspec ADDED
@@ -0,0 +1,34 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'soar_ldap/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "soar_ldap"
8
+ spec.version = SoarLdap::VERSION
9
+ spec.authors = ["Ernst van Graan"]
10
+ spec.email = ["ernst.van.graan@hetzner.co.za"]
11
+
12
+ spec.summary = %q{LDAP client library allowing easy acces to entries on LDAP servers}
13
+ spec.description = %q{LDAP client library allowing easy acces to entries on LDAP servers}
14
+ # spec.homepage = "TODO: Put your gem's website or public repo URL here."
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = "exe"
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+ # spec.required_ruby_version = ['>=2.0.0']
22
+
23
+ spec.add_development_dependency "persistent-cache-ram"
24
+ spec.add_development_dependency "bundler", "~> 1.10"
25
+ spec.add_development_dependency "rake", "~> 10.0"
26
+ spec.add_development_dependency "rspec"
27
+ spec.add_development_dependency "soar_idm"
28
+ if RUBY_PLATFORM =~ /java/
29
+ spec.add_development_dependency "jruby-ldap"
30
+ else
31
+ spec.add_development_dependency "ruby-ldap"
32
+ #spec.add_development_dependency "byebug"
33
+ end
34
+ end
metadata ADDED
@@ -0,0 +1,139 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: soar_ldap
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Ernst van Graan
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-03-12 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: persistent-cache-ram
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
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.10'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '1.10'
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: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: soar_idm
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: ruby-ldap
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description: LDAP client library allowing easy acces to entries on LDAP servers
98
+ email:
99
+ - ernst.van.graan@hetzner.co.za
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - .gitignore
105
+ - .rspec
106
+ - .ruby-gemset
107
+ - .ruby-version
108
+ - Gemfile
109
+ - LICENSE.txt
110
+ - README.md
111
+ - Rakefile
112
+ - lib/soar_ldap.rb
113
+ - lib/soar_ldap/version.rb
114
+ - soar_ldap.gemspec
115
+ homepage:
116
+ licenses:
117
+ - MIT
118
+ metadata: {}
119
+ post_install_message:
120
+ rdoc_options: []
121
+ require_paths:
122
+ - lib
123
+ required_ruby_version: !ruby/object:Gem::Requirement
124
+ requirements:
125
+ - - '>='
126
+ - !ruby/object:Gem::Version
127
+ version: '0'
128
+ required_rubygems_version: !ruby/object:Gem::Requirement
129
+ requirements:
130
+ - - '>='
131
+ - !ruby/object:Gem::Version
132
+ version: '0'
133
+ requirements: []
134
+ rubyforge_project:
135
+ rubygems_version: 2.4.8
136
+ signing_key:
137
+ specification_version: 4
138
+ summary: LDAP client library allowing easy acces to entries on LDAP servers
139
+ test_files: []