ladle 0.1.1 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/CHANGELOG.md CHANGED
@@ -1,3 +1,8 @@
1
+ 0.2.0
2
+ =====
3
+
4
+ - Support custom schemas.
5
+
1
6
  0.1.1
2
7
  =====
3
8
 
data/CUSTOM-SCHEMA.md ADDED
@@ -0,0 +1,61 @@
1
+ Custom Schemas in Ladle
2
+ =======================
3
+
4
+ If you need to use LDAP classes other the standard ones, you'll need
5
+ to define and include a custom schema. There are three steps in this
6
+ process:
7
+
8
+ Create or obtain the schema in openldap format
9
+ ----------------------------------------------
10
+
11
+ All the details are there in the step name.
12
+
13
+ Generate the java representation of the schema
14
+ ----------------------------------------------
15
+
16
+ The embedded LDAP server in ladle is ApacheDS 1.0.2. That project
17
+ provides [documentation][ds-custom] of how to build custom schemas;
18
+ look at the section titled "Creating a Maven module for your custom
19
+ schema." As you might guess from the title, you'll need [maven
20
+ 2][mvn] to do this.
21
+
22
+ The process has one snag -- after you generate the schema using
23
+ `apacheds-schema-archetype.sh`, you'll need to modify the generated
24
+ `pom.xml`. Under the this code:
25
+
26
+ <plugins>
27
+ <plugin>
28
+ <groupId>org.apache.directory.server</groupId>
29
+ <artifactId>apacheds-core-plugin</artifactId>
30
+
31
+ Add the line:
32
+
33
+ <version>1.0.2</version>
34
+
35
+ Then continue with the directions.
36
+
37
+ [ds-custom]: http://directory.apache.org/apacheds/1.0/custom-schema.html.
38
+ [mvn]: http://maven.apache.org/
39
+
40
+ Configure ladle to use the custom schema
41
+ ----------------------------------------
42
+
43
+ At the end of the java schema generation step, you'll have a jar file
44
+ under `target` containing several classes representing the the schema.
45
+ Put that jar somewhere in your project, then configure the
46
+ {Ladle::Server} instance to point to it:
47
+
48
+ Ladle::Server.new(
49
+ :additional_classpath => %w(path/to/sample-schema-1.0-SNAPSHOT.jar),
50
+ :custom_schemas => %w(com.example.schema.TestSchema),
51
+ :ldif => "path/to/schema-using.ldif",
52
+ :domain => "dc=example,dc=com"
53
+ )
54
+
55
+ The custom schema classname is derived from the first argument you
56
+ passed to `apacheds-schema-archtype.sh` and the name of your schema
57
+ file. In the example above, it's as if you ran
58
+
59
+ apacheds-schema-archetype.sh com.example.schema sample-schema
60
+
61
+ And then named the schema file `test.schema`.
data/README.md CHANGED
@@ -111,6 +111,13 @@ restriction of the data to a single domain.)
111
111
 
112
112
  [rfc2849]: http://tools.ietf.org/rfc/rfc2849.txt
113
113
 
114
+ Additional classes
115
+ ------------------
116
+
117
+ If you need to use LDAP classes that are not among the standard set
118
+ provided by ApacheDS, you'll need to specify a custom schema. See
119
+ {file:CUSTOM-SCHEMA.md} for details.
120
+
114
121
  Project links
115
122
  -------------
116
123
 
@@ -16,6 +16,9 @@ import java.io.File;
16
16
  import java.io.IOException;
17
17
  import java.io.InputStreamReader;
18
18
  import java.io.PrintWriter;
19
+ import java.util.ArrayList;
20
+ import java.util.Arrays;
21
+ import java.util.List;
19
22
 
20
23
  /**
21
24
  * The executable front-end to {@link Server}. Uses stdin/stdout as a control channel, with
@@ -42,6 +45,14 @@ public class Main {
42
45
  new File(commandLine.getOptionValue("l")),
43
46
  new File(commandLine.getOptionValue('t')),
44
47
  !commandLine.hasOption('A'));
48
+ if (commandLine.hasOption('S')) {
49
+ List<String> schemaClassNames = Arrays.asList(commandLine.getOptionValue('S').split(","));
50
+ List<Class<?>> schemaClasses = new ArrayList<Class<?>>(schemaClassNames.size());
51
+ for (String schemaClassName : schemaClassNames) {
52
+ schemaClasses.add(Class.forName(schemaClassName));
53
+ }
54
+ s.setCustomSchemas(schemaClasses);
55
+ }
45
56
 
46
57
  Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
47
58
  public void run() {
@@ -115,6 +126,10 @@ public class Main {
115
126
  withLongOpt("no-anonymous").
116
127
  withDescription("Disable anonymous access").
117
128
  create('A'))
129
+ .addOption(OptionBuilder.
130
+ withLongOpt("custom-schemas").hasArg().
131
+ withDescription("Specify one or more custom schemas (comma-separated)").
132
+ create('S'))
118
133
  ;
119
134
  CommandLineParser parser = new GnuParser();
120
135
 
@@ -5,6 +5,7 @@ import org.apache.directory.server.configuration.MutableServerStartupConfigurati
5
5
  import org.apache.directory.server.core.configuration.Configuration;
6
6
  import org.apache.directory.server.core.configuration.MutablePartitionConfiguration;
7
7
  import org.apache.directory.server.core.configuration.ShutdownConfiguration;
8
+ import org.apache.directory.server.core.schema.bootstrap.BootstrapSchema;
8
9
  import org.apache.log4j.Logger;
9
10
 
10
11
  import javax.naming.Context;
@@ -16,6 +17,7 @@ import javax.naming.directory.BasicAttributes;
16
17
  import javax.naming.directory.InitialDirContext;
17
18
  import java.io.File;
18
19
  import java.io.IOException;
20
+ import java.util.Collection;
19
21
  import java.util.Collections;
20
22
  import java.util.HashSet;
21
23
  import java.util.Hashtable;
@@ -39,6 +41,7 @@ public class Server {
39
41
  private final File tempDir;
40
42
  private final File ldifDir;
41
43
  private boolean running = false;
44
+ private Collection<Class<?>> customSchemas = Collections.emptyList();
42
45
 
43
46
  public Server(
44
47
  int port, String domainComponent, File ldifFile, File tempDirBase, boolean allowAnonymous
@@ -93,6 +96,7 @@ public class Server {
93
96
 
94
97
  ////// RUNNING
95
98
 
99
+ @SuppressWarnings({"unchecked"})
96
100
  public void start() {
97
101
  if (running) return;
98
102
 
@@ -107,10 +111,21 @@ public class Server {
107
111
  cfg.setShutdownHookEnabled(false);
108
112
  cfg.setContextPartitionConfigurations(
109
113
  Collections.singleton(createPartitionConfiguration()));
114
+ if (!customSchemas.isEmpty()) {
115
+ Set<BootstrapSchema> schemas = cfg.getBootstrapSchemas();
116
+ for (Class<?> customSchemaClass : customSchemas) {
117
+ schemas.add((BootstrapSchema) customSchemaClass.newInstance());
118
+ }
119
+ cfg.setBootstrapSchemas(schemas);
120
+ }
110
121
 
111
122
  new InitialDirContext(createJndiEnvironment(cfg));
112
123
  } catch (NamingException e) {
113
124
  throw new LadleFatalException("Startup failed", e);
125
+ } catch (InstantiationException e) {
126
+ throw new LadleFatalException("Custom schema not initializable", e);
127
+ } catch (IllegalAccessException e) {
128
+ throw new LadleFatalException("Custom schema not initializable", e);
114
129
  }
115
130
 
116
131
  running = true;
@@ -171,4 +186,8 @@ public class Server {
171
186
  }
172
187
  }
173
188
  }
189
+
190
+ public void setCustomSchemas(Collection<Class<?>> customSchemas) {
191
+ this.customSchemas = customSchemas;
192
+ }
174
193
  }
data/lib/ladle/server.rb CHANGED
@@ -38,6 +38,17 @@ module Ladle
38
38
  # @return [String]
39
39
  attr_reader :java_bin
40
40
 
41
+ ##
42
+ # Any custom schemas to use with the server.
43
+ # @return [Array<String>]
44
+ attr_reader :custom_schemas
45
+
46
+ ##
47
+ # Any additional entries to add to the classpath for the server,
48
+ # e.g., jars containing custom schemas.
49
+ # @return [Array<String>]
50
+ attr_reader :additional_classpath
51
+
41
52
  ##
42
53
  # @param [Hash] opts the options for the server
43
54
  # @option opts [Fixnum] :port (3897) The port to serve from.
@@ -75,6 +86,9 @@ module Ladle
75
86
  @tmpdir = opts[:tmpdir] || ENV['TMPDIR'] || ENV['TEMPDIR']
76
87
  @java_bin = opts[:java_bin] ||
77
88
  (ENV['JAVA_HOME'] ? File.join(ENV['JAVA_HOME'], "bin", "java") : "java")
89
+ @custom_schemas = opts[:custom_schemas] ? [*opts[:custom_schemas]] : []
90
+ @additional_classpath =
91
+ opts[:additional_classpath] ? [*opts[:additional_classpath]] : []
78
92
 
79
93
  # Additional arguments that can be passed to the java server
80
94
  # process. Used for testing only, so not documented.
@@ -229,8 +243,12 @@ module Ladle
229
243
  "--domain", domain,
230
244
  "--ldif", ldif,
231
245
  "--tmpdir", tmpdir,
232
- ("--no-anonymous" unless allow_anonymous?)
233
- ].compact + @additional_args
246
+ ("--no-anonymous" unless allow_anonymous?),
247
+ ([
248
+ "--custom-schemas",
249
+ custom_schemas.join(',')
250
+ ] unless custom_schemas.empty?)
251
+ ].flatten.compact + @additional_args
234
252
  end
235
253
 
236
254
  def classpath
@@ -238,7 +256,9 @@ module Ladle
238
256
  # ApacheDS
239
257
  Dir[File.expand_path("../apacheds/*.jar", __FILE__)] +
240
258
  # Wrapper code
241
- [File.expand_path("../java", __FILE__)]
259
+ [File.expand_path("../java", __FILE__)] +
260
+ # User-specified classpath
261
+ additional_classpath
242
262
  ).join(':')
243
263
  end
244
264
 
data/lib/ladle/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  module Ladle
2
2
  ##
3
3
  # The current version number for Ladle.
4
- VERSION = "0.1.1"
4
+ VERSION = "0.2.0"
5
5
  end
Binary file
@@ -0,0 +1,22 @@
1
+ version: 1
2
+
3
+ dn: ou=animals,dc=example,dc=net
4
+ objectClass: top
5
+ objectClass: organizationalUnit
6
+ ou: animals
7
+
8
+ dn: cn=Ada Aardvark,ou=animals,dc=example,dc=net
9
+ objectClass: top
10
+ objectClass: person
11
+ objectClass: animal
12
+ cn: Ada Aardvark
13
+ sn: Aardvark
14
+ species: Orycteropus afer
15
+
16
+ dn: cn=Bob Badger,ou=animals,dc=example,dc=net
17
+ objectClass: top
18
+ objectClass: person
19
+ objectClass: animal
20
+ cn: Bob Badger
21
+ sn: Badger
22
+ species: Meles meles
@@ -193,6 +193,38 @@ describe Ladle, "::Server" do
193
193
  Ladle::Server.new(:allow_anonymous => false).allow_anonymous?.should be_false
194
194
  end
195
195
  end
196
+
197
+ describe ":custom_schemas" do
198
+ it "defaults to an empty list" do
199
+ Ladle::Server.new.custom_schemas.should == []
200
+ end
201
+
202
+ it "can be set from one class name" do
203
+ Ladle::Server.new(:custom_schemas => "net.example.HappySchema").
204
+ custom_schemas.should == %w(net.example.HappySchema)
205
+ end
206
+
207
+ it "can be set from a list" do
208
+ Ladle::Server.new(:custom_schemas => ["net.example.HappySchema", "net.example.SadSchema"]).
209
+ custom_schemas.should == %w(net.example.HappySchema net.example.SadSchema)
210
+ end
211
+ end
212
+
213
+ describe ":additional_classpath" do
214
+ it "defaults to an empty list" do
215
+ Ladle::Server.new.additional_classpath.should == []
216
+ end
217
+
218
+ it "can be set from one entry" do
219
+ Ladle::Server.new(:additional_classpath => "foo").
220
+ additional_classpath.should == %w(foo)
221
+ end
222
+
223
+ it "can be set from a list" do
224
+ Ladle::Server.new(:additional_classpath => ["bar", "baz"]).
225
+ additional_classpath.should == %w(bar baz)
226
+ end
227
+ end
196
228
  end
197
229
 
198
230
  describe "running" do
@@ -323,6 +355,22 @@ describe Ladle, "::Server" do
323
355
  collect { |result| result[:givenname].first }.sort.should == %w(Ada Bob)
324
356
  end
325
357
  end
358
+
359
+ describe "with a custom schema" do
360
+ before do
361
+ @server = create_server(
362
+ :ldif => File.expand_path("../animals-custom.ldif", __FILE__),
363
+ :domain => "dc=example,dc=net",
364
+ :custom_schemas => %w(net.detailedbalance.ladle.test.AnimalSchema),
365
+ :additional_classpath => File.expand_path("../animal-schema.jar", __FILE__)
366
+ )
367
+ end
368
+
369
+ it "has the data defined in the schema" do
370
+ ldap_search(Net::LDAP::Filter.pres('species'), 'dc=example,dc=net').
371
+ collect { |r| r[:species].first }.sort.should == ["Meles meles", "Orycteropus afer"]
372
+ end
373
+ end
326
374
  end
327
375
 
328
376
  describe "binding" do
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ladle
3
3
  version: !ruby/object:Gem::Version
4
- hash: 25
4
+ hash: 23
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
- - 1
9
- - 1
10
- version: 0.1.1
8
+ - 2
9
+ - 0
10
+ version: 0.2.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Rhett Sutphin
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-10-27 00:00:00 -05:00
18
+ date: 2010-10-29 00:00:00 -05:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -166,11 +166,14 @@ files:
166
166
  - lib/ladle/server.rb
167
167
  - lib/ladle/version.rb
168
168
  - lib/ladle.rb
169
+ - spec/ladle/animal-schema.jar
170
+ - spec/ladle/animals-custom.ldif
169
171
  - spec/ladle/animals.ldif
170
172
  - spec/ladle/server_spec.rb
171
173
  - spec/ladle/version_spec.rb
172
174
  - spec/spec_helper.rb
173
175
  - CHANGELOG.md
176
+ - CUSTOM-SCHEMA.md
174
177
  - README.md
175
178
  - ASL20-LICENSE
176
179
  - LICENSE
@@ -210,6 +213,8 @@ signing_key:
210
213
  specification_version: 3
211
214
  summary: Dishes out steaming helpings of LDAP for fluid testing
212
215
  test_files:
216
+ - spec/ladle/animal-schema.jar
217
+ - spec/ladle/animals-custom.ldif
213
218
  - spec/ladle/animals.ldif
214
219
  - spec/ladle/server_spec.rb
215
220
  - spec/ladle/version_spec.rb