jruby-ldap-fixes 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: a867ffe29ace51c3cc6910eb3d6e1ec61915111f
4
+ data.tar.gz: 6a1e57c6d5d5b66aba8cddf48d3d1fbf0820f793
5
+ SHA512:
6
+ metadata.gz: 3eb2f6ed083b26807346baa524d0ef38f19771f5e163803131a0a9a3b3a5dd484da9aa7f09bc434053faf0c9024a2765b8068e32366ad22a772cec64501e3acc
7
+ data.tar.gz: 4f112bb512000bf41b5fda9c04a139efd49c42b27428d78327267075d2be9c87020b5d175b66bbf0522e661b713939c2e456d292633ed1c37479277d256d270f
@@ -0,0 +1 @@
1
+ Gemfile.lock
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in jruby-ldap-fixes.gemspec
4
+ gemspec
@@ -0,0 +1,11 @@
1
+ == 0.0.3 (16/03/16)
2
+
3
+ - Use default naming factory for tomcat support
4
+
5
+ == 0.0.2 (03/12/12)
6
+
7
+ - 1.9 compatibility (thanks Arkadiy Kraportov)
8
+
9
+ == 0.0.1 (10/09/07)
10
+
11
+ - Initial release.
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2007 Ola Bini <ola.bini@gmail.com>
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README ADDED
@@ -0,0 +1,14 @@
1
+ JRuby/LDAP
2
+ -----------
3
+
4
+ This is an interface compatible port of Ruby/LDAP - to allow binary LDAP usage through JRuby. This implementation is pure Ruby, but uses the Java Integration features of JRuby to access the JNDI libraries and through these implement the correct functionality.
5
+
6
+ Many classes are missing right now, but the base functionality should be there.
7
+
8
+
9
+ Usage
10
+ -----
11
+ require 'rubygems'
12
+ require 'ldap'
13
+
14
+ And then use it like all tutorials of Ruby/LDAP show you.
@@ -0,0 +1,14 @@
1
+ require 'rake/testtask'
2
+ require 'bundler/gem_tasks'
3
+
4
+ task :default => [:test, :build]
5
+
6
+ desc "Run all tests"
7
+ task :test => [:test_all]
8
+
9
+ Rake::TestTask.new(:test_all) do |t|
10
+ t.test_files = FileList['test/**/test_*.rb']
11
+ t.libs << 'test'
12
+ t.libs.delete("lib") unless defined?(JRUBY_VERSION)
13
+ end
14
+
@@ -0,0 +1,18 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "jruby-ldap-fixes/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "jruby-ldap-fixes"
7
+ s.version = JRuby::LDAP::VERSION
8
+ s.authors = ["Ernst van Graan"]
9
+ s.email = ["ernst.vangraan@gmail.com"]
10
+ s.homepage = "http://jruby-extras.rubyforge.org/jruby-ldap"
11
+ s.summary = "Port of Ruby/LDAP to JRuby with fixes"
12
+ s.description = "Fixes applied to jruby-ldap which has been stale for years"
13
+
14
+ s.files = `git ls-files`.split("\n")
15
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
16
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
17
+ s.require_paths = ["lib"]
18
+ end
@@ -0,0 +1,6 @@
1
+ require "jruby-ldap-fixes/version"
2
+
3
+ module JRuby
4
+ module LDAP
5
+ end
6
+ end
@@ -0,0 +1,5 @@
1
+ module JRuby
2
+ module LDAP
3
+ VERSION = "0.0.3"
4
+ end
5
+ end
@@ -0,0 +1,84 @@
1
+ require 'java'
2
+
3
+ module LDAP
4
+ def self.err2string(err)
5
+ case err||0
6
+ when -1 then "Can't contact LDAP server"
7
+ when 0 then "Success"
8
+ when 1 then "Operations error"
9
+ when 2 then "Protocol error"
10
+ when 3 then "Time limit exceeded"
11
+ when 4 then "Size limit exceeded"
12
+ when 5 then "Compare False"
13
+ when 6 then "Compare True"
14
+ when 7 then "Authentication method not supported"
15
+ when 8 then "Strong(er) authentication required"
16
+ when 9 then "Partial results and referral received"
17
+ when 10 then "Referral"
18
+ when 11 then "Administrative limit exceeded"
19
+ when 12 then "Critical extension is unavailable"
20
+ when 13 then "Confidentiality required"
21
+ when 14 then "SASL bind in progress"
22
+ when 15 then "Unknown error"
23
+ when 16 then "No such attribute"
24
+ when 17 then "Undefined attribute type"
25
+ when 18 then "Inappropriate matching"
26
+ when 19 then "Constraint violation"
27
+ when 20 then "Type or value exists"
28
+ when 21 then "Invalid syntax"
29
+ when 32 then "No such object"
30
+ when 33 then "Alias problem"
31
+ when 34 then "Invalid DN syntax"
32
+ when 35 then "Entry is a leaf"
33
+ when 36 then "Alias dereferencing problem"
34
+ when 47 then "Proxy Authorization Failure"
35
+ when 48 then "Inappropriate authentication"
36
+ when 49 then "Invalid credentials"
37
+ when 50 then "Insufficient access"
38
+ when 51 then "Server is busy"
39
+ when 52 then "Server is unavailable"
40
+ when 53 then "Server is unwilling to perform"
41
+ when 54 then "Loop detected"
42
+ when 64 then "Naming violation"
43
+ when 65 then "Object class violation"
44
+ when 66 then "Operation not allowed on non-leaf"
45
+ when 67 then "Operation not allowed on RDN"
46
+ when 68 then "Already exists"
47
+ when 69 then "Cannot modify object class"
48
+ when 70 then "Results too large"
49
+ when 71 then "Operation affects multiple DSAs"
50
+ when 80 then "Internal (implementation specific) error"
51
+ else "Unknown error"
52
+ end
53
+ end
54
+
55
+ def self.load_configuration(attrs={})
56
+ env = nil
57
+ env = javax.naming.directory.InitialDirContext.new.environment rescue nil
58
+ default = {'java.naming.factory.initial' => 'com.sun.jndi.ldap.LdapCtxFactory'}
59
+ if env
60
+ env2 = default.dup
61
+ env.each do |k,v|
62
+ env2[k.to_s] = v.to_s
63
+ end
64
+ env = env2
65
+ else
66
+ env = default.dup
67
+ end
68
+ env = default.dup
69
+ env.merge! attrs
70
+ @environment = env
71
+ end
72
+
73
+ def self.configuration(attrs = { })
74
+ @environment.merge attrs
75
+ end
76
+ end
77
+
78
+ require 'ldap/constants'
79
+ require 'ldap/conn'
80
+ require 'ldap/entry'
81
+ require 'ldap/error'
82
+ require 'ldap/mod'
83
+
84
+ LDAP.load_configuration
@@ -0,0 +1,273 @@
1
+ module LDAP
2
+ module ConnImplementation
3
+ def controls(*args)
4
+ raise "NOT IMPLEMENTED"
5
+ end
6
+
7
+ def get_option(*args)
8
+ raise "NOT IMPLEMENTED"
9
+ end
10
+
11
+ # Modify the RDN of the entry with DN, +dn+, giving it the new RDN,
12
+ # +new_rdn+. If +delete_old_rdn+ is *true*, the old RDN value will be deleted
13
+ # from the entry.
14
+ def modrdn(dn, new_rdn, delete_old_rdn)
15
+ begin
16
+ if delete_old_rdn
17
+ @context.rename(dn, new_rdn)
18
+ else
19
+ obj = @context.lookup(dn)
20
+ @context.bind(new_rdn, obj)
21
+ end
22
+ @err = 0
23
+ rescue javax.naming.NameAlreadyBoundException => e
24
+ @err = 68
25
+ rescue javax.naming.InvalidNameException => e
26
+ @err = 34
27
+ rescue javax.naming.NoPermissionException => e
28
+ @err = 50
29
+ rescue javax.naming.directory.SchemaViolationException => e
30
+ @err = 65
31
+ rescue javax.naming.NamingException => e
32
+ @err = 21
33
+ rescue javax.naming.NoPermissionException => e
34
+ @err = 50
35
+ rescue javax.naming.NamingException => e
36
+ @err = -1
37
+ end
38
+ raise LDAP::ResultError.wrap(LDAP::err2string(@err), e) if @err != 0
39
+ self
40
+ end
41
+
42
+ def perror(*args)
43
+ raise "NOT IMPLEMENTED"
44
+ end
45
+
46
+ def referrals(*args)
47
+ raise "NOT IMPLEMENTED"
48
+ end
49
+
50
+ def result2error(*args)
51
+ raise "NOT IMPLEMENTED"
52
+ end
53
+
54
+ def __jndi_context
55
+ @context
56
+ end
57
+
58
+ def initialize(host='localhost', port=LDAP_PORT)
59
+ @host = host
60
+ @port = port
61
+ end
62
+
63
+ def err
64
+ @err || 0
65
+ end
66
+
67
+ def err2string(err)
68
+ LDAP.err2string(err)
69
+ end
70
+
71
+ def simple_bind(dn=nil, password=nil, &block)
72
+ bind(dn, password, LDAP_AUTH_SIMPLE, &block)
73
+ end
74
+
75
+ def bind(dn=nil, password=nil, method=LDAP_AUTH_SIMPLE)
76
+ raise LDAP::Error, "already bound" if bound?
77
+
78
+ url = @use_ssl ? "ldaps://#@host:#@port/" : "ldap://#@host:#@port/"
79
+ base_env = {javax.naming.Context::PROVIDER_URL => url}
80
+ base_env[javax.naming.Context::SECURITY_PRINCIPAL] = dn if dn
81
+ base_env[javax.naming.Context::SECURITY_CREDENTIALS] = password if password
82
+
83
+ @current_env = java.util.Hashtable.new(LDAP::configuration(base_env))
84
+
85
+ begin
86
+ @context = javax.naming.directory.InitialDirContext.new(@current_env)
87
+ @err = 0
88
+ rescue javax.naming.NoPermissionException => e
89
+ @err = 50
90
+ raise LDAP::ResultError.wrap(LDAP::err2string(@err), e)
91
+ rescue javax.naming.NamingException => e
92
+ @err = -1
93
+ raise LDAP::ResultError.wrap(LDAP::err2string(@err), e)
94
+ end
95
+
96
+ if !block_given?
97
+ return self
98
+ end
99
+
100
+ begin
101
+ yield self
102
+
103
+ return nil
104
+ ensure
105
+ unbind
106
+ end
107
+ end
108
+
109
+ def set_option(opt, value)
110
+ @err = 0
111
+ end
112
+
113
+ def add(dn, attrs)
114
+ raise LDAP::InvalidDataError, "The LDAP handler has already unbound." unless bound?
115
+
116
+ attrs = LDAP::hash2mods(LDAP::LDAP_MOD_ADD, attrs) if attrs.is_a?(Hash)
117
+
118
+ begin
119
+ @context.create_subcontext(dn, LDAP::Mod.to_java_attributes(*attrs))
120
+ @err = 0
121
+ rescue javax.naming.NameNotFoundException => e
122
+ @err = 32
123
+ raise LDAP::ResultError.wrap(LDAP::err2string(@err), e)
124
+ rescue javax.naming.InvalidNameException => e
125
+ @err = 34
126
+ raise LDAP::ResultError.wrap(LDAP::err2string(@err), e)
127
+ rescue javax.naming.NoPermissionException => e
128
+ @err = 50
129
+ raise LDAP::ResultError.wrap(LDAP::err2string(@err), e)
130
+ rescue javax.naming.directory.SchemaViolationException => e
131
+ @err = 65
132
+ raise LDAP::ResultError.wrap(LDAP::err2string(@err), e)
133
+ rescue javax.naming.NamingException => e
134
+ @err = 21
135
+ raise LDAP::ResultError.wrap(LDAP::err2string(@err), e)
136
+ end
137
+ self
138
+ end
139
+
140
+ def modify(dn, attrs)
141
+ raise LDAP::InvalidDataError, "The LDAP handler has already unbound." unless bound?
142
+
143
+ attrs = LDAP::hash2mods(LDAP::LDAP_MOD_REPLACE, attrs) if attrs.is_a?(Hash)
144
+
145
+ begin
146
+ @context.modify_attributes(dn, LDAP::Mod.to_java_modification_items(*attrs))
147
+ @err = 0
148
+ rescue javax.naming.NameNotFoundException => e
149
+ @err = 32
150
+ raise LDAP::ResultError.wrap(LDAP::err2string(@err), e)
151
+ rescue javax.naming.InvalidNameException => e
152
+ @err = 34
153
+ raise LDAP::ResultError.wrap(LDAP::err2string(@err), e)
154
+ rescue javax.naming.NoPermissionException => e
155
+ @err = 50
156
+ raise LDAP::ResultError.wrap(LDAP::err2string(@err), e)
157
+ rescue javax.naming.directory.SchemaViolationException => e
158
+ @err = 65
159
+ raise LDAP::ResultError.wrap(LDAP::err2string(@err), e)
160
+ rescue javax.naming.NamingException => e
161
+ @err = 21
162
+ raise LDAP::ResultError.wrap(LDAP::err2string(@err), e)
163
+ end
164
+
165
+ self
166
+ end
167
+
168
+ def delete(dn)
169
+ raise LDAP::InvalidDataError, "The LDAP handler has already unbound." unless bound?
170
+
171
+ begin
172
+ @context.destroy_subcontext(dn)
173
+ @err = 0
174
+ rescue javax.naming.NameNotFoundException => e
175
+ @err = 32
176
+ raise LDAP::ResultError.wrap(LDAP::err2string(@err), e)
177
+ rescue javax.naming.InvalidNameException => e
178
+ @err = 34
179
+ raise LDAP::ResultError.wrap(LDAP::err2string(@err), e)
180
+ rescue javax.naming.NoPermissionException => e
181
+ @err = 50
182
+ raise LDAP::ResultError.wrap(LDAP::err2string(@err), e)
183
+ rescue javax.naming.NamingException => e
184
+ @err = 21
185
+ raise LDAP::ResultError.wrap(LDAP::err2string(@err), e)
186
+ end
187
+ self
188
+ end
189
+
190
+ def search(base_dn, scope, filter, attrs=nil, attrsonly=nil, sec=0, usec=0, s_attr=nil, s_proc=nil)
191
+ raise LDAP::InvalidDataError, "The LDAP handler has already unbound." unless bound?
192
+
193
+ controls = javax.naming.directory.SearchControls.new
194
+ controls.search_scope = scope
195
+
196
+ if attrs && !attrs.empty?
197
+ controls.returning_attributes = attrs.to_java(:string)
198
+ end
199
+ if attrsonly
200
+ controls.returning_obj_flag = true
201
+ end
202
+
203
+ if sec != 0 || usec != 0
204
+ controls.time_limit = usec/1000 + sec*1000
205
+ end
206
+
207
+ begin
208
+ @context.search(base_dn, filter, controls).each do |val|
209
+ yield LDAP::Entry.create_from_search_result(val)
210
+ end
211
+
212
+ @err = 0
213
+ rescue javax.naming.NameNotFoundException => e
214
+ @err = 32
215
+ raise LDAP::ResultError.wrap(LDAP::err2string(@err), e)
216
+ rescue javax.naming.InvalidNameException => e
217
+ @err = 34
218
+ raise LDAP::ResultError.wrap(LDAP::err2string(@err), e)
219
+ rescue javax.naming.NoPermissionException => e
220
+ @err = 50
221
+ raise LDAP::ResultError.wrap(LDAP::err2string(@err), e)
222
+ end
223
+
224
+ self
225
+ end
226
+
227
+ def search2(base_dn, scope, filter, attrs=nil, attrsonly=nil, sec=0, usec=0, s_attr=nil, s_proc=nil)
228
+ arr = []
229
+ search(base_dn, scope, filter, attrs, attrsonly, sec, usec, s_attr, s_proc) do |val|
230
+ arr << LDAP::entry2hash(val)
231
+ end
232
+ arr
233
+ end
234
+
235
+ def unbind
236
+ raise LDAP::InvalidDataError, "The LDAP handler has already unbound." unless bound?
237
+ @context.close
238
+ @err = 0
239
+ @context = nil
240
+ end
241
+
242
+ def bound?
243
+ !@context.nil?
244
+ end
245
+ end
246
+
247
+
248
+ class Conn
249
+ class << self
250
+ alias open new
251
+ end
252
+
253
+ def initialize(host='localhost', port=LDAP_PORT)
254
+ super
255
+ @use_ssl = false
256
+ end
257
+
258
+ include ConnImplementation
259
+ end
260
+
261
+ class SSLConn
262
+ class << self
263
+ alias open new
264
+ end
265
+
266
+ def initialize(host='localhost', port=LDAPS_PORT)
267
+ super
268
+ @use_ssl = true
269
+ end
270
+
271
+ include ConnImplementation
272
+ end
273
+ end