예제 #1
0
  public void afterPropertiesSet() throws Exception {
    if (workingDir == null) {
      String apacheWorkDir = System.getProperty("apacheDSWorkDir");

      if (apacheWorkDir == null) {
        apacheWorkDir = "apacheds-spring-security";
      }

      setWorkingDirectory(new File(apacheWorkDir));
    }

    server = new LdapServer();
    server.setDirectoryService(service);
    server.setTransports(new TcpTransport(port));
    start();
  }
  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();
  }
 private void startServer() throws Exception {
   service.startup();
   server = new LdapServer();
   server.setTransports(new TcpTransport(10389));
   server.setDirectoryService(service);
 }