ruby-activeldap 0.7.4 → 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES +375 -0
- data/COPYING +340 -0
- data/LICENSE +58 -0
- data/Manifest.txt +33 -0
- data/README +63 -0
- data/Rakefile +37 -0
- data/TODO +31 -0
- data/benchmark/bench-al.rb +152 -0
- data/lib/{activeldap.rb → active_ldap.rb} +280 -263
- data/lib/active_ldap/adaptor/base.rb +29 -0
- data/lib/active_ldap/adaptor/ldap.rb +466 -0
- data/lib/active_ldap/association/belongs_to.rb +38 -0
- data/lib/active_ldap/association/belongs_to_many.rb +40 -0
- data/lib/active_ldap/association/collection.rb +80 -0
- data/lib/active_ldap/association/has_many.rb +48 -0
- data/lib/active_ldap/association/has_many_wrap.rb +56 -0
- data/lib/active_ldap/association/proxy.rb +89 -0
- data/lib/active_ldap/associations.rb +162 -0
- data/lib/active_ldap/attributes.rb +199 -0
- data/lib/active_ldap/base.rb +1343 -0
- data/lib/active_ldap/callbacks.rb +19 -0
- data/lib/active_ldap/command.rb +46 -0
- data/lib/active_ldap/configuration.rb +96 -0
- data/lib/active_ldap/connection.rb +137 -0
- data/lib/{activeldap → active_ldap}/ldap.rb +1 -1
- data/lib/active_ldap/object_class.rb +70 -0
- data/lib/active_ldap/schema.rb +258 -0
- data/lib/{activeldap → active_ldap}/timeout.rb +0 -0
- data/lib/{activeldap → active_ldap}/timeout_stub.rb +0 -0
- data/lib/active_ldap/user_password.rb +92 -0
- data/lib/active_ldap/validations.rb +78 -0
- data/rails/plugin/active_ldap/README +54 -0
- data/rails/plugin/active_ldap/init.rb +6 -0
- data/test/TODO +2 -0
- data/test/al-test-utils.rb +337 -0
- data/test/command.rb +62 -0
- data/test/config.yaml +8 -0
- data/test/config.yaml.sample +6 -0
- data/test/run-test.rb +17 -0
- data/test/test-unit-ext.rb +2 -0
- data/test/test_associations.rb +334 -0
- data/test/test_attributes.rb +71 -0
- data/test/test_base.rb +345 -0
- data/test/test_base_per_instance.rb +32 -0
- data/test/test_bind.rb +53 -0
- data/test/test_callback.rb +35 -0
- data/test/test_connection.rb +38 -0
- data/test/test_connection_per_class.rb +50 -0
- data/test/test_find.rb +36 -0
- data/test/test_groupadd.rb +50 -0
- data/test/test_groupdel.rb +46 -0
- data/test/test_groupls.rb +107 -0
- data/test/test_groupmod.rb +51 -0
- data/test/test_lpasswd.rb +75 -0
- data/test/test_object_class.rb +32 -0
- data/test/test_reflection.rb +173 -0
- data/test/test_schema.rb +166 -0
- data/test/test_user.rb +209 -0
- data/test/test_user_password.rb +93 -0
- data/test/test_useradd-binary.rb +59 -0
- data/test/test_useradd.rb +55 -0
- data/test/test_userdel.rb +48 -0
- data/test/test_userls.rb +86 -0
- data/test/test_usermod-binary-add-time.rb +62 -0
- data/test/test_usermod-binary-add.rb +61 -0
- data/test/test_usermod-binary-del.rb +64 -0
- data/test/test_usermod-lang-add.rb +57 -0
- data/test/test_usermod.rb +56 -0
- data/test/test_validation.rb +38 -0
- metadata +94 -21
- data/lib/activeldap/associations.rb +0 -170
- data/lib/activeldap/base.rb +0 -1456
- data/lib/activeldap/configuration.rb +0 -59
- data/lib/activeldap/schema2.rb +0 -217
@@ -0,0 +1,64 @@
|
|
1
|
+
require 'al-test-utils'
|
2
|
+
|
3
|
+
class TestUsermodBinaryDel < Test::Unit::TestCase
|
4
|
+
include AlTestUtils
|
5
|
+
|
6
|
+
def setup
|
7
|
+
super
|
8
|
+
@command = File.join(@examples_dir, "usermod-binary-del")
|
9
|
+
make_ou("People")
|
10
|
+
@user_class.instance_variable_set("@prefix", "ou=People")
|
11
|
+
end
|
12
|
+
|
13
|
+
priority :must
|
14
|
+
|
15
|
+
priority :normal
|
16
|
+
def test_non_exist_user
|
17
|
+
ensure_delete_user("test-user") do |uid,|
|
18
|
+
assert(!@user_class.exists?(uid))
|
19
|
+
assert_equal([false, "User #{uid} doesn't exist.\n"],
|
20
|
+
run_command(uid, "New CN", 11111))
|
21
|
+
assert(!@user_class.exists?(uid))
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_modify_user
|
26
|
+
make_temporary_user(:simple => true) do |user, password|
|
27
|
+
user.add_class("strongAuthenticationUser")
|
28
|
+
user.user_certificate = certificate
|
29
|
+
assert(user.save)
|
30
|
+
assert_usermod_binary_del_successfully(user.uid, "New #{user.cn}",
|
31
|
+
user.uid_number.to_i + 100)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
private
|
36
|
+
def assert_usermod_binary_del_successfully(name, cn, uid, *args, &block)
|
37
|
+
_wrap_assertion do
|
38
|
+
assert(@user_class.exists?(name))
|
39
|
+
previous_classes = @user_class.find(name).classes
|
40
|
+
assert_operator(previous_classes, :include?, "strongAuthenticationUser")
|
41
|
+
args.concat([name, cn, uid])
|
42
|
+
assert_equal([true, ""], run_command(*args, &block))
|
43
|
+
assert(@user_class.exists?(name))
|
44
|
+
|
45
|
+
user = @user_class.find(name)
|
46
|
+
assert_equal(name, user.uid)
|
47
|
+
assert_equal(cn, user.cn)
|
48
|
+
assert_equal(uid.to_s, user.uid_number)
|
49
|
+
assert_equal(uid.to_s, user.gid_number)
|
50
|
+
assert_equal((previous_classes - ['strongAuthenticationUser']).sort,
|
51
|
+
user.classes.sort)
|
52
|
+
assert(!user.respond_to?(:user_certificate))
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def assert_usermod_binary_del_failed(name, cn, uid, message, *args, &block)
|
57
|
+
_wrap_assertion do
|
58
|
+
assert(@user_class.exists?(name))
|
59
|
+
args.concat([name, cn, uid])
|
60
|
+
assert_equal([false, message], run_command(*args, &block))
|
61
|
+
assert(@user_class.exists?(name))
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
require 'al-test-utils'
|
2
|
+
|
3
|
+
class TestUsermodLangAdd < Test::Unit::TestCase
|
4
|
+
include AlTestUtils
|
5
|
+
|
6
|
+
def setup
|
7
|
+
super
|
8
|
+
@command = File.join(@examples_dir, "usermod-lang-add")
|
9
|
+
make_ou("People")
|
10
|
+
@user_class.instance_variable_set("@prefix", "ou=People")
|
11
|
+
end
|
12
|
+
|
13
|
+
priority :must
|
14
|
+
|
15
|
+
priority :normal
|
16
|
+
def test_non_exist_user
|
17
|
+
ensure_delete_user("test-user") do |uid,|
|
18
|
+
assert(!@user_class.exists?(uid))
|
19
|
+
assert_equal([false, "User #{uid} doesn't exist.\n"],
|
20
|
+
run_command(uid, "New CN", 11111))
|
21
|
+
assert(!@user_class.exists?(uid))
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_modify_user
|
26
|
+
make_temporary_user do |user, password|
|
27
|
+
assert_usermod_lang_add_successfully(user.uid, "New #{user.cn}",
|
28
|
+
user.uid_number.to_i + 100)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
def assert_usermod_lang_add_successfully(name, cn, uid, *args, &block)
|
34
|
+
_wrap_assertion do
|
35
|
+
assert(@user_class.exists?(name))
|
36
|
+
previous_classes = @user_class.find(name).classes
|
37
|
+
args.concat([name, cn, uid])
|
38
|
+
assert_equal([true, ""], run_command(*args, &block))
|
39
|
+
assert(@user_class.exists?(name))
|
40
|
+
|
41
|
+
user = @user_class.find(name)
|
42
|
+
assert_equal(name, user.uid)
|
43
|
+
assert_equal([cn, {'lang-en-us' => cn}], user.cn)
|
44
|
+
assert_equal(uid.to_s, user.uid_number)
|
45
|
+
assert_equal(uid.to_s, user.gid_number)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def assert_usermod_lang_add_failed(name, cn, uid, message, *args, &block)
|
50
|
+
_wrap_assertion do
|
51
|
+
assert(@user_class.exists?(name))
|
52
|
+
args.concat([name, cn, uid])
|
53
|
+
assert_equal([false, message], run_command(*args, &block))
|
54
|
+
assert(@user_class.exists?(name))
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
require 'al-test-utils'
|
2
|
+
|
3
|
+
class TestUsermod < Test::Unit::TestCase
|
4
|
+
include AlTestUtils
|
5
|
+
|
6
|
+
def setup
|
7
|
+
super
|
8
|
+
@command = File.join(@examples_dir, "usermod")
|
9
|
+
make_ou("People")
|
10
|
+
@user_class.instance_variable_set("@prefix", "ou=People")
|
11
|
+
end
|
12
|
+
|
13
|
+
priority :must
|
14
|
+
|
15
|
+
priority :normal
|
16
|
+
def test_non_exist_user
|
17
|
+
ensure_delete_user("test-user") do |uid,|
|
18
|
+
assert(!@user_class.exists?(uid))
|
19
|
+
assert_equal([false, "User #{uid} doesn't exist.\n"],
|
20
|
+
run_command(uid, "New CN", 11111))
|
21
|
+
assert(!@user_class.exists?(uid))
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_modify_user
|
26
|
+
make_temporary_user do |user, password|
|
27
|
+
assert_usermod_successfully(user.uid, "New #{user.cn}",
|
28
|
+
user.uid_number.to_i + 100)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
def assert_usermod_successfully(name, cn, uid, *args, &block)
|
34
|
+
_wrap_assertion do
|
35
|
+
assert(@user_class.exists?(name))
|
36
|
+
args.concat([name, cn, uid])
|
37
|
+
assert_equal([true, ""], run_command(*args, &block))
|
38
|
+
assert(@user_class.exists?(name))
|
39
|
+
|
40
|
+
user = @user_class.find(name)
|
41
|
+
assert_equal(name, user.uid)
|
42
|
+
assert_equal(cn, user.cn)
|
43
|
+
assert_equal(uid.to_s, user.uid_number)
|
44
|
+
assert_equal(uid.to_s, user.gid_number)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def assert_usermod_failed(name, cn, uid, message, *args, &block)
|
49
|
+
_wrap_assertion do
|
50
|
+
assert(@user_class.exists?(name))
|
51
|
+
args.concat([name, cn, uid])
|
52
|
+
assert_equal([false, message], run_command(*args, &block))
|
53
|
+
assert(@user_class.exists?(name))
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'al-test-utils'
|
2
|
+
|
3
|
+
class TestValidation < Test::Unit::TestCase
|
4
|
+
include AlTestUtils
|
5
|
+
|
6
|
+
priority :must
|
7
|
+
|
8
|
+
priority :normal
|
9
|
+
def test_save!
|
10
|
+
make_temporary_group do |group|
|
11
|
+
group.description = ""
|
12
|
+
|
13
|
+
assert_nothing_raised do
|
14
|
+
group.save!
|
15
|
+
end
|
16
|
+
|
17
|
+
@group_class.validates_presence_of(:description)
|
18
|
+
assert_raises(ActiveLdap::EntryInvalid) do
|
19
|
+
group.save!
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_validates_presence_of
|
25
|
+
make_temporary_group do |group|
|
26
|
+
assert_nothing_raised do
|
27
|
+
group.description = ""
|
28
|
+
end
|
29
|
+
assert(group.valid?)
|
30
|
+
assert_equal([], group.errors.to_a)
|
31
|
+
|
32
|
+
@group_class.validates_presence_of(:description)
|
33
|
+
assert(!group.valid?)
|
34
|
+
assert(group.errors.invalid?(:description))
|
35
|
+
assert_equal(1, group.errors.size)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
metadata
CHANGED
@@ -1,21 +1,23 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
|
-
rubygems_version: 0.
|
2
|
+
rubygems_version: 0.9.0
|
3
3
|
specification_version: 1
|
4
4
|
name: ruby-activeldap
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.
|
7
|
-
date: 2006-
|
8
|
-
summary: Ruby/
|
6
|
+
version: 0.8.0
|
7
|
+
date: 2006-11-20 00:00:00 +00:00
|
8
|
+
summary: Ruby/ActiveLdap is a object-oriented API to LDAP
|
9
9
|
require_paths:
|
10
10
|
- lib
|
11
|
-
email:
|
12
|
-
|
11
|
+
email:
|
12
|
+
- will@alum.bu.edu
|
13
|
+
- kou@cozmixng.org
|
14
|
+
homepage: http://rubyforge.org/projects/ruby-activeldap/
|
13
15
|
rubyforge_project: ruby-activeldap
|
14
|
-
description:
|
15
|
-
autorequire:
|
16
|
+
description: "'Ruby/ActiveLdap' is a ruby extension library which provides a clean objected oriented interface to the Ruby/LDAP library. It was inspired by ActiveRecord. This is not nearly as clean or as flexible as ActiveRecord, but it is still trivial to define new objects and manipulate them with minimal difficulty."
|
17
|
+
autorequire: active_ldap
|
16
18
|
default_executable:
|
17
19
|
bindir: bin
|
18
|
-
has_rdoc:
|
20
|
+
has_rdoc: true
|
19
21
|
required_ruby_version: !ruby/object:Gem::Version::Requirement
|
20
22
|
requirements:
|
21
23
|
- - ">"
|
@@ -25,20 +27,82 @@ required_ruby_version: !ruby/object:Gem::Version::Requirement
|
|
25
27
|
platform: ruby
|
26
28
|
signing_key:
|
27
29
|
cert_chain:
|
30
|
+
post_install_message:
|
28
31
|
authors:
|
29
32
|
- Will Drewry
|
33
|
+
- Kouhei Sutou
|
30
34
|
files:
|
31
|
-
-
|
32
|
-
-
|
33
|
-
-
|
34
|
-
-
|
35
|
-
-
|
36
|
-
-
|
37
|
-
-
|
38
|
-
- lib/
|
39
|
-
- lib/
|
40
|
-
|
41
|
-
|
35
|
+
- Rakefile
|
36
|
+
- LICENSE
|
37
|
+
- TODO
|
38
|
+
- COPYING
|
39
|
+
- CHANGES
|
40
|
+
- README
|
41
|
+
- Manifest.txt
|
42
|
+
- lib/active_ldap/adaptor/ldap.rb
|
43
|
+
- lib/active_ldap/adaptor/base.rb
|
44
|
+
- lib/active_ldap/association/has_many_wrap.rb
|
45
|
+
- lib/active_ldap/association/has_many.rb
|
46
|
+
- lib/active_ldap/association/proxy.rb
|
47
|
+
- lib/active_ldap/association/belongs_to_many.rb
|
48
|
+
- lib/active_ldap/association/collection.rb
|
49
|
+
- lib/active_ldap/association/belongs_to.rb
|
50
|
+
- lib/active_ldap/validations.rb
|
51
|
+
- lib/active_ldap/command.rb
|
52
|
+
- lib/active_ldap/callbacks.rb
|
53
|
+
- lib/active_ldap/ldap.rb
|
54
|
+
- lib/active_ldap/timeout_stub.rb
|
55
|
+
- lib/active_ldap/timeout.rb
|
56
|
+
- lib/active_ldap/attributes.rb
|
57
|
+
- lib/active_ldap/object_class.rb
|
58
|
+
- lib/active_ldap/connection.rb
|
59
|
+
- lib/active_ldap/associations.rb
|
60
|
+
- lib/active_ldap/user_password.rb
|
61
|
+
- lib/active_ldap/schema.rb
|
62
|
+
- lib/active_ldap/configuration.rb
|
63
|
+
- lib/active_ldap/base.rb
|
64
|
+
- lib/active_ldap.rb
|
65
|
+
- benchmark/bench-al.rb
|
66
|
+
- rails/plugin/active_ldap/init.rb
|
67
|
+
- rails/plugin/active_ldap/README
|
68
|
+
test_files:
|
69
|
+
- test/test-unit-ext
|
70
|
+
- test/test_useradd.rb
|
71
|
+
- test/test_user.rb
|
72
|
+
- test/command.rb
|
73
|
+
- test/test_usermod.rb
|
74
|
+
- test/test_bind.rb
|
75
|
+
- test/test_usermod-binary-add-time.rb
|
76
|
+
- test/test_usermod-lang-add.rb
|
77
|
+
- test/test_attributes.rb
|
78
|
+
- test/test_usermod-binary-add.rb
|
79
|
+
- test/test_validation.rb
|
80
|
+
- test/test-unit-ext.rb
|
81
|
+
- test/test_object_class.rb
|
82
|
+
- test/test_groupmod.rb
|
83
|
+
- test/test_associations.rb
|
84
|
+
- test/test_user_password.rb
|
85
|
+
- test/test_base_per_instance.rb
|
86
|
+
- test/al-test-utils.rb
|
87
|
+
- test/test_useradd-binary.rb
|
88
|
+
- test/test_groupdel.rb
|
89
|
+
- test/test_find.rb
|
90
|
+
- test/test_groupls.rb
|
91
|
+
- test/run-test.rb
|
92
|
+
- test/TODO
|
93
|
+
- test/config.yaml.sample
|
94
|
+
- test/test_reflection.rb
|
95
|
+
- test/test_connection_per_class.rb
|
96
|
+
- test/test_callback.rb
|
97
|
+
- test/test_connection.rb
|
98
|
+
- test/test_schema.rb
|
99
|
+
- test/test_userdel.rb
|
100
|
+
- test/test_usermod-binary-del.rb
|
101
|
+
- test/test_groupadd.rb
|
102
|
+
- test/test_base.rb
|
103
|
+
- test/test_userls.rb
|
104
|
+
- test/test_lpasswd.rb
|
105
|
+
- test/config.yaml
|
42
106
|
rdoc_options: []
|
43
107
|
|
44
108
|
extra_rdoc_files: []
|
@@ -48,8 +112,8 @@ executables: []
|
|
48
112
|
extensions: []
|
49
113
|
|
50
114
|
requirements:
|
115
|
+
- ruby-ldap >= 0.8.2
|
51
116
|
- (Open)LDAP server
|
52
|
-
- ruby-ldap = 0.8.2
|
53
117
|
dependencies:
|
54
118
|
- !ruby/object:Gem::Dependency
|
55
119
|
name: log4r
|
@@ -60,3 +124,12 @@ dependencies:
|
|
60
124
|
- !ruby/object:Gem::Version
|
61
125
|
version: 1.0.4
|
62
126
|
version:
|
127
|
+
- !ruby/object:Gem::Dependency
|
128
|
+
name: activerecord
|
129
|
+
version_requirement:
|
130
|
+
version_requirements: !ruby/object:Gem::Version::Requirement
|
131
|
+
requirements:
|
132
|
+
- - ">"
|
133
|
+
- !ruby/object:Gem::Version
|
134
|
+
version: 0.0.0
|
135
|
+
version:
|
@@ -1,170 +0,0 @@
|
|
1
|
-
|
2
|
-
module ActiveLDAP
|
3
|
-
# Associations
|
4
|
-
#
|
5
|
-
# Associations provides the class methods needed for
|
6
|
-
# the extension classes to create methods using
|
7
|
-
# belongs_to and has_many
|
8
|
-
module Associations
|
9
|
-
def self.append_features(base)
|
10
|
-
super
|
11
|
-
base.extend(ClassMethods)
|
12
|
-
end
|
13
|
-
module ClassMethods
|
14
|
-
|
15
|
-
# This class function is used to setup all mappings between the subclass
|
16
|
-
# and ldap for use in activeldap
|
17
|
-
#
|
18
|
-
# Example:
|
19
|
-
# ldap_mapping :dnattr => 'uid', :prefix => 'ou=People',
|
20
|
-
# :classes => ['top', 'posixAccount'], scope => LDAP::LDAP_SCOPE_SUBTREE,
|
21
|
-
# :parent => String
|
22
|
-
def ldap_mapping(options = {})
|
23
|
-
# The immediate ancestor should be the caller....
|
24
|
-
klass = self.ancestors[0]
|
25
|
-
|
26
|
-
dnattr = options[:dnattr] || 'cn'
|
27
|
-
prefix = options[:prefix] || "ou=#{klass.to_s.split(':').last}"
|
28
|
-
classes_array = options[:classes] || nil
|
29
|
-
scope = options[:scope] || 'super'
|
30
|
-
# When used, instantiates parent objects from the "parent dn". This
|
31
|
-
# can be a String or a real ActiveLDAP class. This just adds the helper
|
32
|
-
# Base#parent.
|
33
|
-
parent = options[:parent_class] || nil
|
34
|
-
|
35
|
-
classes = 'super'
|
36
|
-
unless classes_array.nil?
|
37
|
-
raise TypeError, ":classes must be an array" \
|
38
|
-
unless classes_array.respond_to? :size
|
39
|
-
# Build classes array
|
40
|
-
classes = '['
|
41
|
-
classes_array.map! {|x| x = "'#{x}'"}
|
42
|
-
classes << classes_array.join(', ')
|
43
|
-
classes << ']'
|
44
|
-
end
|
45
|
-
|
46
|
-
# This adds the methods to the local
|
47
|
-
# class which can then be inherited, etc
|
48
|
-
# which describe the mapping to LDAP.
|
49
|
-
klass.class_eval(<<-"end_eval")
|
50
|
-
class << self
|
51
|
-
# Return the list of required object classes
|
52
|
-
def required_classes
|
53
|
-
#{classes}
|
54
|
-
end
|
55
|
-
|
56
|
-
# Return the full base of the class
|
57
|
-
def base
|
58
|
-
if "#{prefix}".empty?
|
59
|
-
return "\#{super}"
|
60
|
-
else
|
61
|
-
return "#{prefix},\#{super}"
|
62
|
-
end
|
63
|
-
end
|
64
|
-
|
65
|
-
# Return the expected DN attribute of an object
|
66
|
-
def dnattr
|
67
|
-
'#{dnattr}'
|
68
|
-
end
|
69
|
-
|
70
|
-
# Return the expected DN attribute of an object
|
71
|
-
def ldap_scope
|
72
|
-
#{scope}
|
73
|
-
end
|
74
|
-
end
|
75
|
-
|
76
|
-
# Hide connect
|
77
|
-
private_class_method :connect
|
78
|
-
|
79
|
-
# Unhide class methods
|
80
|
-
public_class_method :find_all
|
81
|
-
public_class_method :find
|
82
|
-
public_class_method :new
|
83
|
-
public_class_method :dnattr
|
84
|
-
end_eval
|
85
|
-
|
86
|
-
# Add the parent helper if desired
|
87
|
-
if parent
|
88
|
-
klass.class_eval(<<-"end_eval")
|
89
|
-
def parent()
|
90
|
-
return #{parent}.new(@dn.split(',')[1..-1].join(','))
|
91
|
-
end
|
92
|
-
end_eval
|
93
|
-
end
|
94
|
-
end
|
95
|
-
|
96
|
-
# belongs_to
|
97
|
-
#
|
98
|
-
# This defines a method for an extension class map its DN key
|
99
|
-
# attribute value on to multiple items which reference it by
|
100
|
-
# |:foreign_key| in the other LDAP entry covered by class |:class_name|.
|
101
|
-
#
|
102
|
-
# Example:
|
103
|
-
# belongs_to :groups, :class_name => Group, :foreign_key => memberUid, :local_key => 'uid'
|
104
|
-
#
|
105
|
-
def belongs_to(association_id, options = {})
|
106
|
-
klass = options[:class_name] || association_id.to_s
|
107
|
-
key = options[:foreign_key] || association_id.to_s + "_id"
|
108
|
-
local_key = options[:local_key] || ''
|
109
|
-
class_eval <<-"end_eval"
|
110
|
-
def #{association_id}(objects = nil)
|
111
|
-
objects = @@config[:return_objects] if objects.nil?
|
112
|
-
local_key = "#{local_key}"
|
113
|
-
local_key = dnattr() if local_key.empty?
|
114
|
-
results = []
|
115
|
-
#{klass}.find_all(:attribute => "#{key}", :value => send(local_key.to_sym), :objects => objects).each do |o|
|
116
|
-
results << o
|
117
|
-
end
|
118
|
-
return results
|
119
|
-
end
|
120
|
-
end_eval
|
121
|
-
end
|
122
|
-
|
123
|
-
|
124
|
-
# has_many
|
125
|
-
#
|
126
|
-
# This defines a method for an extension class expand an
|
127
|
-
# existing multi-element attribute into ActiveLDAP objects.
|
128
|
-
# This discards any calls which result in entries that
|
129
|
-
# don't exist in LDAP!
|
130
|
-
#
|
131
|
-
# Example:
|
132
|
-
# has_many :members, :class_name => User, :local_key => memberUid, :foreign_key => 'uid'
|
133
|
-
#
|
134
|
-
# TODO[ENH]: def #{...}=(val) to redefine group membership
|
135
|
-
def has_many(association_id, options = {})
|
136
|
-
klass = options[:class_name] || association_id.to_s
|
137
|
-
key = options[:local_key] || association_id.to_s + "_id"
|
138
|
-
foreign_key = options[:foreign_key] || ''
|
139
|
-
class_eval <<-"end_eval"
|
140
|
-
def #{association_id}(objects = nil)
|
141
|
-
objects = @@config[:return_objects] if objects.nil?
|
142
|
-
foreign_key = "#{foreign_key}"
|
143
|
-
if foreign_key.empty?
|
144
|
-
foreign_key = dnattr()
|
145
|
-
end
|
146
|
-
results = []
|
147
|
-
unless @data["#{key}"].nil?
|
148
|
-
@data["#{key}"].each do |item|
|
149
|
-
fkey = ""
|
150
|
-
if foreign_key == "dn" and not item.empty?
|
151
|
-
fkey = item.split(',')[0].split('=')[0]
|
152
|
-
item = item.split(',')[0].split('=')[1]
|
153
|
-
end
|
154
|
-
# This will even yield entries that don't necessarily exist
|
155
|
-
if foreign_key != "dn"
|
156
|
-
fkey = foreign_key
|
157
|
-
end
|
158
|
-
#{klass}.find_all(:attribute => fkey, :value => item, :objects => objects).each do |match|
|
159
|
-
results << match
|
160
|
-
end
|
161
|
-
end
|
162
|
-
end
|
163
|
-
return results
|
164
|
-
end
|
165
|
-
end_eval
|
166
|
-
end
|
167
|
-
|
168
|
-
end
|
169
|
-
end
|
170
|
-
end
|