/** * Add a default partition to the server * * @param partitionId The partition Id * @param partitionDn The partition DN * @return The newly added partition * @throws Exception If the partition can't be added */ private void createDefaultPartition() throws Exception { Partition partition = new JdbmPartition(); partition.setId("jboss"); partition.setSuffix("dc=jboss,dc=org"); service.addPartition(partition); }
private Partition addPartition(String partitionId, String partitionDn) throws Exception { // Create a new partition named 'ippon'. Partition partition = new JdbmPartition(); partition.setId(partitionId); partition.setSuffix(partitionDn); service.addPartition(partition); return partition; }
public void start() throws Exception { // Initialize the LDAP service service = new DefaultDirectoryService(); service.setWorkingDirectory(workingDir); // Disable the ChangeLog system service.getChangeLog().setEnabled(false); service.setDenormalizeOpAttrsEnabled(true); Partition ipponPartition = addPartition("ippon", "dc=ippon,dc=fr"); // And start the service service.startup(); // Inject the ippon root entry if it does not already exist try { service.getAdminSession().lookup(ipponPartition.getSuffixDn()); System.out.printf("Root %s found ! %n", ipponPartition.getSuffixDn()); } catch (LdapNameNotFoundException lnnfe) { System.out.printf("Root %s not found ! creating it ... %n", ipponPartition.getSuffixDn()); LdapDN dnippon = new LdapDN("dc=ippon,dc=fr"); ServerEntry entryippon = service.newEntry(dnippon); entryippon.add("objectClass", "top", "domain", "extensibleObject"); entryippon.add("dc", "ippon"); service.getAdminSession().add(entryippon); System.out.printf("Importing some data ... %n", ipponPartition.getSuffixDn()); InputStream is = this.getClass().getResource("ipponTestLdapExport.ldif").openStream(); LdifReader ldifReader = new LdifReader(is); for (LdifEntry entry : ldifReader) { injectEntry(entry, service); } is.close(); } // service LDAP : server = new LdapServer(); // int serverPort = 10389; int serverPort = 389; server.setTransports(new TcpTransport(serverPort)); server.setDirectoryService(service); server.start(); }