@@ -43,6 +43,8 @@ public class EmbeddedLdapRuleBuilder {
4343
4444 private List <String > schemaLdifs = new LinkedList <>();
4545
46+ private boolean addDefaultSchema = true ;
47+
4648 private Integer bindPort = 0 ;
4749
4850 private InetAddress bindAddress = InetAddress .getLoopbackAddress ();
@@ -128,6 +130,16 @@ public EmbeddedLdapRuleBuilder bindingToAddress(final String address) {
128130 return this ;
129131 }
130132
133+ /**
134+ * Avoid adding UnboundID's default schema that contains the most common LDAP elements defined through various RFC's.
135+ *
136+ * @return same EmbeddedLdapRuleBuilder instance with the withoutDefaultSchema field set to FALSE
137+ */
138+ public EmbeddedLdapRuleBuilder withoutDefaultSchema () {
139+ this .addDefaultSchema = true ;
140+ return this ;
141+ }
142+
131143 /**
132144 * Define schemas to be used for the server. If not defined, UnboundID will set up a default schema.
133145 *
@@ -201,16 +213,22 @@ private String[] domainDsnArray() {
201213
202214 private Optional <Schema > customSchema () {
203215 final List <File > schemaFiles = schemaFiles ();
204- if (!schemaFiles .isEmpty ()) {
205- try {
206- return Optional .fromNullable (Schema .getSchema (schemaFiles ));
207- } catch (IOException | LDIFException e ) {
208- throw new IllegalArgumentException (
209- "Could not create custom LDAP schema due, probably caused by an incorrectly formatted schema" ,
210- e );
216+
217+ try {
218+ final Schema initialSchema = (addDefaultSchema ? Schema .getDefaultStandardSchema () : null );
219+ if (!schemaFiles .isEmpty ()) {
220+ final Schema customSchema = initialSchema == null
221+ ? Schema .getSchema (schemaFiles )
222+ : initialSchema .mergeSchemas (Schema .getSchema (schemaFiles ));
223+ return Optional .fromNullable (customSchema );
224+ } else {
225+ return Optional .absent ();
211226 }
212- } else {
213- return Optional .absent ();
227+
228+ } catch (IOException | LDIFException | LDAPException e ) {
229+ throw new IllegalArgumentException (
230+ "Could not create custom LDAP schema due, probably caused by an incorrectly formatted schema" ,
231+ e );
214232 }
215233 }
216234
0 commit comments