public void stop() throws Exception { // Stops the server if (ldapServer != null) { ldapServer.stop(); } if (kdcServer != null) { kdcServer.stop(); } /*if ( changePwdServer != null ) { changePwdServer.stop(); }*/ if (ntpServer != null) { ntpServer.stop(); } if (httpServer != null) { httpServer.stop(); } // We now have to stop the underlaying DirectoryService ldapServer.getDirectoryService().shutdown(); }
/** 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) + ""); }
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(); }
/** * 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(); }
/** * Stops LDAP server and shuts down the directory service. * * @param managementClient * @param containerId * @throws Exception * @see * org.jboss.as.arquillian.api.ServerSetupTask#tearDown(org.jboss.as.arquillian.container.ManagementClient, * java.lang.String) */ public void tearDown(ManagementClient managementClient, String containerId) throws Exception { ldapServer.stop(); directoryService.shutdown(); FileUtils.deleteDirectory(directoryService.getInstanceLayout().getInstanceDirectory()); if (removeBouncyCastle) { try { Security.removeProvider(BouncyCastleProvider.PROVIDER_NAME); } catch (SecurityException ex) { LOGGER.warn("Cannot deregister BouncyCastleProvider", ex); } } }
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); } }
public void stop() { if (!isRunning()) { return; } logger.info("Shutting down directory server ..."); try { server.stop(); service.shutdown(); } catch (Exception e) { logger.error("Shutdown failed", e); return; } running = false; if (workingDir.exists()) { logger.info("Deleting working directory " + workingDir.getAbsolutePath()); deleteDir(workingDir); } }
/** * 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 stop() { if (server.isStarted()) { server.stop(); } }
public void start() throws Exception { server.start(); }
private void startServer() throws Exception { service.startup(); server = new LdapServer(); server.setTransports(new TcpTransport(10389)); server.setDirectoryService(service); }
public void synch() throws Exception { ldapServer.getDirectoryService().sync(); }
public DirectoryService getDirectoryService() { return ldapServer.getDirectoryService(); }
public void stop() throws Exception { server.stop(); service.shutdown(); }
// @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(); }