activeldap 1.2.4 → 3.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (45) hide show
  1. data/Gemfile +18 -0
  2. data/LICENSE +2 -1
  3. data/README.textile +137 -0
  4. data/doc/text/development.textile +50 -0
  5. data/{CHANGES → doc/text/news.textile} +256 -237
  6. data/doc/text/rails.textile +144 -0
  7. data/doc/text/tutorial.textile +1005 -0
  8. data/lib/active_ldap/adapter/base.rb +5 -3
  9. data/lib/active_ldap/adapter/net_ldap_ext.rb +1 -1
  10. data/lib/active_ldap/associations.rb +6 -2
  11. data/lib/active_ldap/base.rb +16 -71
  12. data/lib/active_ldap/callbacks.rb +52 -33
  13. data/lib/active_ldap/configuration.rb +2 -2
  14. data/lib/active_ldap/get_text/parser.rb +2 -2
  15. data/lib/active_ldap/human_readable.rb +5 -4
  16. data/lib/active_ldap/log_subscriber.rb +50 -0
  17. data/lib/active_ldap/persistence.rb +65 -0
  18. data/lib/active_ldap/railtie.rb +40 -0
  19. data/lib/active_ldap/railties/controller_runtime.rb +48 -0
  20. data/lib/active_ldap/user_password.rb +1 -0
  21. data/lib/active_ldap/validations.rb +34 -72
  22. data/lib/active_ldap.rb +13 -912
  23. data/{rails_generators/model_active_ldap → lib/rails/generators/active_ldap/model}/USAGE +2 -1
  24. data/lib/rails/generators/active_ldap/model/model_generator.rb +47 -0
  25. data/{rails_generators/model_active_ldap → lib/rails/generators/active_ldap/model}/templates/model_active_ldap.rb +0 -0
  26. data/lib/rails/generators/active_ldap/scaffold/scaffold_generator.rb +14 -0
  27. data/{rails_generators/scaffold_active_ldap → lib/rails/generators/active_ldap/scaffold}/templates/ldap.yml +1 -0
  28. data/test/test_base.rb +9 -0
  29. data/test/test_callback.rb +2 -6
  30. data/test/test_connection.rb +2 -2
  31. data/test/test_user.rb +2 -2
  32. data/test/test_validation.rb +11 -11
  33. metadata +165 -106
  34. data/README +0 -155
  35. data/Rakefile +0 -133
  36. data/rails/README +0 -54
  37. data/rails/init.rb +0 -33
  38. data/rails_generators/model_active_ldap/model_active_ldap_generator.rb +0 -69
  39. data/rails_generators/model_active_ldap/templates/unit_test.rb +0 -8
  40. data/rails_generators/scaffold_active_ldap/scaffold_active_ldap_generator.rb +0 -7
  41. data/test/al-test-utils.rb +0 -439
  42. data/test/command.rb +0 -112
  43. data/test/config.yaml.sample +0 -6
  44. data/test/fixtures/lower_case_object_class_schema.rb +0 -802
  45. data/test/run-test.rb +0 -44
@@ -0,0 +1,144 @@
1
+ h1. Rails
2
+
3
+ ActiveLdap supports Rails 3.1.
4
+
5
+ h2. Install
6
+
7
+ To install, simply add the following code to your Gemfile:
8
+
9
+ <pre>
10
+ gem 'activeldap'
11
+ </pre>
12
+
13
+ You should also depend on an LDAP adapter such as Net::LDAP
14
+ or Ruby/LDAP. The following example uses Ruby/LDAP:
15
+
16
+ <pre>
17
+ gem 'ruby-ldap'
18
+ </pre>
19
+
20
+ Bundler will install the gems automatically when you run
21
+ 'bundle install'.
22
+
23
+ You also need to include the ActiveLdap railtie in
24
+ config/application.rb, after the other railties:
25
+
26
+ <pre>
27
+ require "active_ldap/railtie"
28
+ </pre>
29
+
30
+ h2. Configuration
31
+
32
+ You can use a LDAP configuration per environment. They are in
33
+ a file named 'ldap.yml' in the config directory of your
34
+ rails app. This file has a similar function to the
35
+ 'database.yml' file that allows you to set your database
36
+ connection configurations per environment. Similarly, the
37
+ ldap.yml file allows configurations to be set for
38
+ development, test, and production environments.
39
+
40
+ You can generate 'config/ldap.yml' by the follwoing command:
41
+
42
+ <pre class="command">
43
+ % script/rails generate active_ldap:scaffold
44
+ </pre>
45
+
46
+ You need to modify 'config/ldap.yml' generated by
47
+ active_ldap:scaffold. For instance, the development entry
48
+ would look something like the following:
49
+
50
+ <pre>
51
+ !!!plain
52
+ development:
53
+ host: 127.0.0.1
54
+ port: 389
55
+ base: dc=localhost
56
+ bind_dn: cn=admin,dc=localhost
57
+ password: secret
58
+ </pre>
59
+
60
+ When your application starts up,
61
+ ActiveLdap::Base.setup_connection will be called with the
62
+ parameters specified for your current environment.
63
+
64
+ h2. Model
65
+
66
+ You can generate a User model that represents entries under
67
+ ou=Users by the following command:
68
+
69
+ <pre class="command">
70
+ % script/rails generate model User --dn-attribute uid --classes person PosixAccount
71
+ </pre>
72
+
73
+ It generates the following app/model/user.rb:
74
+
75
+ <pre>
76
+ class User < ActiveLdap::Base
77
+ ldap_mapping :dn_attribute => "uid",
78
+ :prefix => "ou=Users",
79
+ :classes => ["person", "PosixAccount"]
80
+ end
81
+ </pre>
82
+
83
+ You can add relationships by modifying app/model/user.rb:
84
+
85
+ <pre>
86
+ class User < ActiveLdap::Base
87
+ ldap_mapping :dn_attribute => 'uid',
88
+ :prefix => "ou=Users",
89
+ :classes => ['person', 'posixAccount']
90
+ belongs_to :primary_group,
91
+ :class_name => "Group",
92
+ :foreign_key => "gidNumber",
93
+ :primary_key => "gidNumber"
94
+ belongs_to :groups,
95
+ :many => 'memberUid'
96
+ end
97
+ </pre>
98
+
99
+ You can also generate a Group model by the following command:
100
+
101
+ <pre class="command">
102
+ % script/rails generate model Group --classes PosixGroup
103
+ </pre>
104
+
105
+ app/model/group.rb:
106
+
107
+ <pre>
108
+ class Group < ActiveLdap::Base
109
+ ldap_mapping :dn_attribute => "cn",
110
+ :prefix => "ou=Groups",
111
+ :classes => ["PosixGroup"]
112
+ end
113
+ </pre>
114
+
115
+ You can add relationships by modifying app/model/group.rb:
116
+
117
+ <pre>
118
+ class Group < ActiveLdap::Base
119
+ ldap_mapping :dn_attribute => "cn",
120
+ :prefix => "ou=Groups",
121
+ :classes => ["PosixGroup"]
122
+ has_many :members,
123
+ :class_name => "User",
124
+ :wrap => "memberUid"
125
+ has_many :primary_members,
126
+ :class_name => "Group",
127
+ :foreign_key => "gidNumber",
128
+ :primary_key => "gidNumber"
129
+ end
130
+ </pre>
131
+
132
+ You can also generate a Ou model by the following command:
133
+
134
+ <pre class="command">
135
+ % script/rails generate model Ou --prefix '' --classes organizationalUnit
136
+ </pre>
137
+
138
+ <pre>
139
+ class Ou < ActiveLdap::Base
140
+ ldap_mapping :dn_attribute => "cn",
141
+ :prefix => "",
142
+ :classes => ["organizationalUnit"]
143
+ end
144
+ </pre>