/** start the LDAP server */
  private void startLdap(LdapServerBean ldapServerBean, DirectoryService directoryService)
      throws Exception {
    LOG.info("Starting the LDAP server");
    long startTime = System.currentTimeMillis();

    ldapServer = ServiceBuilder.createLdapServer(ldapServerBean, directoryService);

    if (ldapServer == null) {
      LOG.info(
          "Cannot find any reference to the LDAP Server in the configuration : the server won't be started");
      return;
    }

    // printBanner( BANNER_LDAP );

    ldapServer.setDirectoryService(directoryService);

    // And start the server now
    try {
      ldapServer.start();
    } catch (Exception e) {
      LOG.error("Cannot start the server : " + e.getMessage());
    }

    LOG.info(
        "LDAP server: started in {} milliseconds", (System.currentTimeMillis() - startTime) + "");
  }
 /**
  * Creates directory services and starts LDAP server
  *
  * @param managementClient
  * @param containerId
  * @throws Exception
  * @see
  *     org.jboss.as.arquillian.api.ServerSetupTask#setup(org.jboss.as.arquillian.container.ManagementClient,
  *     java.lang.String)
  */
 public void setup(ManagementClient managementClient, String containerId) throws Exception {
   try {
     if (Security.getProvider(BouncyCastleProvider.PROVIDER_NAME) == null) {
       Security.addProvider(new BouncyCastleProvider());
       removeBouncyCastle = true;
     }
   } catch (SecurityException ex) {
     LOGGER.warn("Cannot register BouncyCastleProvider", ex);
   }
   directoryService = DSAnnotationProcessor.getDirectoryService();
   DSAnnotationProcessor.injectEntries(
       directoryService,
       "dn: uid=jduke,dc=jboss,dc=org\n" //
           + "objectclass: top\n" //
           + "objectclass: uidObject\n" //
           + "objectclass: person\n" //
           + "uid: jduke\n" //
           + "cn: Java Duke\n" //
           + "sn: Duke\n" //
           + "userPassword: theduke\n");
   final ManagedCreateLdapServer createLdapServer =
       new ManagedCreateLdapServer(
           (CreateLdapServer) AnnotationUtils.getInstance(CreateLdapServer.class));
   Utils.fixApacheDSTransportAddress(
       createLdapServer, Utils.getSecondaryTestAddress(managementClient, false));
   ldapServer =
       ServerAnnotationProcessor.instantiateLdapServer(createLdapServer, directoryService);
   ldapServer.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();
  }
Exemplo n.º 4
0
  public void start() {
    if (isRunning()) {
      return;
    }

    if (service.isStarted()) {
      throw new IllegalStateException("DirectoryService is already running.");
    }

    logger.info("Starting directory server...");
    try {
      service.startup();
      server.start();
    } catch (Exception e) {
      logger.error("Server startup failed ", e);
      return;
    }

    try {
      service.getAdminSession().lookup(partition.getSuffixDn());
    } catch (LdapNameNotFoundException e) {
      try {
        LdapDN dn = new LdapDN(root);
        Assert.isTrue(root.startsWith("dc="));
        String dc = root.substring(3, root.indexOf(','));
        ServerEntry entry = service.newEntry(dn);
        entry.add("objectClass", "top", "domain", "extensibleObject");
        entry.add("dc", dc);
        service.getAdminSession().add(entry);
      } catch (Exception e1) {
        logger.error("Failed to create dc entry", e1);
      }
    } catch (Exception e) {
      logger.error("Lookup failed", e);
    }

    running = true;

    try {
      importLdifs();
    } catch (Exception e) {
      logger.error("Failed to import LDIF file(s)", e);
    }
  }
Exemplo n.º 5
0
 /**
  * Creates directory services, starts LDAP server and KDCServer
  *
  * @param managementClient
  * @param containerId
  * @throws Exception
  * @see
  *     org.jboss.as.arquillian.api.ServerSetupTask#setup(org.jboss.as.arquillian.container.ManagementClient,
  *     java.lang.String)
  */
 public void setup(ManagementClient managementClient, String containerId) throws Exception {
   try {
     if (Security.getProvider(BouncyCastleProvider.PROVIDER_NAME) == null) {
       Security.addProvider(new BouncyCastleProvider());
       removeBouncyCastle = true;
     }
   } catch (SecurityException ex) {
     LOGGER.warn("Cannot register BouncyCastleProvider", ex);
   }
   directoryService = DSAnnotationProcessor.getDirectoryService();
   final SchemaManager schemaManager = directoryService.getSchemaManager();
   try {
     for (LdifEntry ldifEntry :
         new LdifReader(
             LdapLoginModuleTestCase.class.getResourceAsStream(
                 LdapLoginModuleTestCase.class.getSimpleName() + ".ldif"))) {
       directoryService
           .getAdminSession()
           .add(new DefaultEntry(schemaManager, ldifEntry.getEntry()));
     }
   } catch (Exception e) {
     e.printStackTrace();
     throw e;
   }
   final ManagedCreateLdapServer createLdapServer =
       new ManagedCreateLdapServer(
           (CreateLdapServer) AnnotationUtils.getInstance(CreateLdapServer.class));
   FileOutputStream fos = new FileOutputStream(KEYSTORE_FILE);
   IOUtils.copy(getClass().getResourceAsStream(KEYSTORE_FILENAME), fos);
   fos.close();
   createLdapServer.setKeyStore(KEYSTORE_FILE.getAbsolutePath());
   Utils.fixApacheDSTransportAddress(
       createLdapServer, Utils.getSecondaryTestAddress(managementClient, false));
   ldapServer =
       ServerAnnotationProcessor.instantiateLdapServer(createLdapServer, directoryService);
   ldapServer.start();
 }
 public void start() throws Exception {
   server.start();
 }
  // @formatter:off
  @CreateDS(
      name = "JBossDS",
      factory = org.jboss.as.test.integration.ldap.InMemoryDirectoryServiceFactory.class,
      partitions = {
        @CreatePartition(
            name = "jboss",
            suffix = "dc=jboss,dc=org",
            contextEntry =
                @ContextEntry(
                    entryLdif =
                        "dn: dc=jboss,dc=org\n"
                            + "dc: jboss\n"
                            + "objectClass: top\n"
                            + "objectClass: domain\n\n"),
            indexes = {
              @CreateIndex(attribute = "objectClass"),
              @CreateIndex(attribute = "dc"),
              @CreateIndex(attribute = "ou")
            })
      },
      additionalInterceptors = {KeyDerivationInterceptor.class})
  @CreateLdapServer(
      transports = {
        @CreateTransport(protocol = "LDAP", port = LDAP_PORT),
        @CreateTransport(protocol = "LDAPS", port = LDAPS_PORT)
      },
      certificatePassword = "******")
  @CreateKdcServer(
      primaryRealm = KERBEROS_PRIMARY_REALM,
      kdcPrincipal = "krbtgt/" + KERBEROS_PRIMARY_REALM + "@" + KERBEROS_PRIMARY_REALM,
      searchBaseDn = "dc=jboss,dc=org",
      transports = {
        @CreateTransport(protocol = "UDP", port = KERBEROS_PORT),
        @CreateTransport(protocol = "TCP", port = KERBEROS_PORT)
      })
  // @formatter:on
  public void createLdap1(ManagementClient managementClient, final String hostname)
      throws Exception, IOException, ClassNotFoundException, FileNotFoundException {
    final Map<String, String> map = new HashMap<String, String>();
    final String cannonicalHost =
        NetworkUtils.formatPossibleIpv6Address(Utils.getCannonicalHost(managementClient));
    map.put("hostname", cannonicalHost);
    map.put("realm", KERBEROS_PRIMARY_REALM);
    directoryService1 = DSAnnotationProcessor.getDirectoryService();
    final String ldifContent =
        StrSubstitutor.replace(
            IOUtils.toString(
                KerberosServerSetupTask.class.getResourceAsStream(
                    KerberosServerSetupTask.class.getSimpleName() + ".ldif"),
                "UTF-8"),
            map);
    LOGGER.info(ldifContent);

    final SchemaManager schemaManager = directoryService1.getSchemaManager();
    try {
      for (LdifEntry ldifEntry : new LdifReader(IOUtils.toInputStream(ldifContent))) {
        directoryService1
            .getAdminSession()
            .add(new DefaultEntry(schemaManager, ldifEntry.getEntry()));
      }
    } catch (Exception e) {
      e.printStackTrace();
      throw e;
    }
    final ManagedCreateLdapServer createLdapServer =
        new ManagedCreateLdapServer(
            (CreateLdapServer) AnnotationUtils.getInstance(CreateLdapServer.class));
    FileOutputStream fos = new FileOutputStream(KEYSTORE_FILE);
    IOUtils.copy(getClass().getResourceAsStream(KEYSTORE_FILENAME), fos);
    fos.close();

    createLdapServer.setKeyStore(KEYSTORE_FILE.getAbsolutePath());
    fixTransportAddress(createLdapServer, cannonicalHost);

    ldapServer1 =
        ServerAnnotationProcessor.instantiateLdapServer(createLdapServer, directoryService1);
    krbServer1 =
        KDCServerAnnotationProcessor.getKdcServer(directoryService1, KERBEROS_PORT, cannonicalHost);
    ldapServer1.start();
  }