/** {@inheritDoc} */ @Override public boolean isConfigurationAcceptable( ConnectionHandlerCfg configuration, List<LocalizableMessage> unacceptableReasons) { LDAPConnectionHandlerCfg config = (LDAPConnectionHandlerCfg) configuration; if (currentConfig == null || (!currentConfig.isEnabled() && config.isEnabled())) { // Attempt to bind to the listen port on all configured addresses to // verify whether the connection handler will be able to start. LocalizableMessage errorMessage = checkAnyListenAddressInUse( config.getListenAddress(), config.getListenPort(), config.isAllowTCPReuseAddress(), config.dn()); if (errorMessage != null) { unacceptableReasons.add(errorMessage); return false; } } if (config.isEnabled() // Check that the SSL configuration is valid. && (config.isUseSSL() || config.isAllowStartTLS())) { try { createSSLEngine(config, createSSLContext(config)); } catch (DirectoryException e) { logger.traceException(e); unacceptableReasons.add(e.getMessageObject()); return false; } } return true; }
private ConnectionHandlerDescriptor getConnectionHandler( ConnectionHandlerCfg connHandler, String name) throws OpenDsException { SortedSet<InetAddress> addresses = new TreeSet<InetAddress>(getInetAddressComparator()); int port; ConnectionHandlerDescriptor.Protocol protocol; ConnectionHandlerDescriptor.State state = connHandler.isEnabled() ? ConnectionHandlerDescriptor.State.ENABLED : ConnectionHandlerDescriptor.State.DISABLED; if (connHandler instanceof LDAPConnectionHandlerCfg) { LDAPConnectionHandlerCfg ldap = (LDAPConnectionHandlerCfg) connHandler; if (ldap.isUseSSL()) { protocol = ConnectionHandlerDescriptor.Protocol.LDAPS; } else if (ldap.isAllowStartTLS()) { protocol = ConnectionHandlerDescriptor.Protocol.LDAP_STARTTLS; } else { protocol = ConnectionHandlerDescriptor.Protocol.LDAP; } addAll(addresses, ldap.getListenAddress()); port = ldap.getListenPort(); } else if (connHandler instanceof HTTPConnectionHandlerCfg) { HTTPConnectionHandlerCfg http = (HTTPConnectionHandlerCfg) connHandler; if (http.isUseSSL()) { protocol = ConnectionHandlerDescriptor.Protocol.HTTPS; } else { protocol = ConnectionHandlerDescriptor.Protocol.HTTP; } addAll(addresses, http.getListenAddress()); port = http.getListenPort(); } else if (connHandler instanceof JMXConnectionHandlerCfg) { JMXConnectionHandlerCfg jmx = (JMXConnectionHandlerCfg) connHandler; if (jmx.isUseSSL()) { protocol = ConnectionHandlerDescriptor.Protocol.JMXS; } else { protocol = ConnectionHandlerDescriptor.Protocol.JMX; } addAll(addresses, jmx.getListenAddress()); port = jmx.getListenPort(); } else if (connHandler instanceof LDIFConnectionHandlerCfg) { protocol = ConnectionHandlerDescriptor.Protocol.LDIF; port = -1; } else if (connHandler instanceof SNMPConnectionHandlerCfg) { protocol = ConnectionHandlerDescriptor.Protocol.SNMP; SNMPConnectionHandlerCfg snmp = (SNMPConnectionHandlerCfg) connHandler; addAll(addresses, snmp.getListenAddress()); port = snmp.getListenPort(); } else { protocol = ConnectionHandlerDescriptor.Protocol.OTHER; port = -1; } Set<CustomSearchResult> emptySet = Collections.emptySet(); return new ConnectionHandlerDescriptor(addresses, port, protocol, state, name, emptySet); }
/** {@inheritDoc} */ @Override public void initializeConnectionHandler(LDAPConnectionHandlerCfg config) throws ConfigException, InitializationException { if (friendlyName == null) { friendlyName = config.dn().rdn().getAttributeValue(0).toString(); } // Open the selector. try { selector = Selector.open(); } catch (Exception e) { logger.traceException(e); LocalizableMessage message = ERR_LDAP_CONNHANDLER_OPEN_SELECTOR_FAILED.get( config.dn(), stackTraceToSingleLineString(e)); throw new InitializationException(message, e); } // Save this configuration for future reference. currentConfig = config; enabled = config.isEnabled(); requestHandlerIndex = 0; allowedClients = config.getAllowedClient(); deniedClients = config.getDeniedClient(); // Configure SSL if needed. try { // This call may disable the connector if wrong SSL settings configureSSL(config); } catch (DirectoryException e) { logger.traceException(e); throw new InitializationException(e.getMessageObject()); } // Save properties that cannot be dynamically modified. allowReuseAddress = config.isAllowTCPReuseAddress(); backlog = config.getAcceptBacklog(); listenAddresses = config.getListenAddress(); listenPort = config.getListenPort(); numRequestHandlers = getNumRequestHandlers(config.getNumRequestHandlers(), friendlyName); // Construct a unique name for this connection handler, and put // together the set of listeners. listeners = new LinkedList<>(); StringBuilder nameBuffer = new StringBuilder(); nameBuffer.append(friendlyName); for (InetAddress a : listenAddresses) { listeners.add(new HostPort(a.getHostAddress(), listenPort)); nameBuffer.append(" "); nameBuffer.append(a.getHostAddress()); } nameBuffer.append(" port "); nameBuffer.append(listenPort); handlerName = nameBuffer.toString(); // Attempt to bind to the listen port on all configured addresses to // verify whether the connection handler will be able to start. LocalizableMessage errorMessage = checkAnyListenAddressInUse(listenAddresses, listenPort, allowReuseAddress, config.dn()); if (errorMessage != null) { logger.error(errorMessage); throw new InitializationException(errorMessage); } // Create a system property to store the LDAP(S) port the server is // listening to. This information can be displayed with jinfo. System.setProperty(protocol + "_port", String.valueOf(listenPort)); // Create and start a connection finalizer thread for this // connection handler. connectionFinalizer = Executors.newSingleThreadScheduledExecutor( new DirectoryThread.Factory( "LDAP Connection Finalizer for connection handler " + toString())); connectionFinalizerActiveJobQueue = new ArrayList<>(); connectionFinalizerPendingJobQueue = new ArrayList<>(); connectionFinalizer.scheduleWithFixedDelay( new ConnectionFinalizerRunnable(), 100, 100, TimeUnit.MILLISECONDS); // Create and start the request handlers. requestHandlers = new LDAPRequestHandler[numRequestHandlers]; for (int i = 0; i < numRequestHandlers; i++) { requestHandlers[i] = new LDAPRequestHandler(this, i); } for (int i = 0; i < numRequestHandlers; i++) { requestHandlers[i].start(); } // Register the set of supported LDAP versions. DirectoryServer.registerSupportedLDAPVersion(3, this); if (config.isAllowLDAPV2()) { DirectoryServer.registerSupportedLDAPVersion(2, this); } // Create and register monitors. statTracker = new LDAPStatistics(handlerName + " Statistics"); DirectoryServer.registerMonitorProvider(statTracker); connMonitor = new ClientConnectionMonitorProvider(this); DirectoryServer.registerMonitorProvider(connMonitor); // Register this as a change listener. config.addLDAPChangeListener(this); }