Commit e78559b1 authored by Guus der Kinderen's avatar Guus der Kinderen

OF-946: Should have single point of SSLContext instantiation

The code to get an instance of SSLContext is duplicated all over the codebase. Code gets more
maintainable by replacing all duplicate code blocks with one utility method.
This already fixes an issue where Clearspace integration used a SSL instead of TLS algorithm.
parent cc6be12e
...@@ -63,7 +63,7 @@ public class SSLProtocolSocketFactory implements SecureProtocolSocketFactory { ...@@ -63,7 +63,7 @@ public class SSLProtocolSocketFactory implements SecureProtocolSocketFactory {
private SSLContext createSSLContext(String host) { private SSLContext createSSLContext(String host) {
try { try {
SSLContext context = SSLContext.getInstance("SSL"); final SSLContext context = SSLConfig.getSSLContext();
context.init( context.init(
null, null,
new TrustManager[] { new TrustManager[] {
......
...@@ -21,10 +21,12 @@ ...@@ -21,10 +21,12 @@
package org.jivesoftware.openfire.net; package org.jivesoftware.openfire.net;
import org.jivesoftware.openfire.keystore.*; import org.jivesoftware.openfire.keystore.*;
import org.jivesoftware.openfire.session.ConnectionSettings;
import org.jivesoftware.util.JiveGlobals; import org.jivesoftware.util.JiveGlobals;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import javax.net.ssl.SSLContext;
import java.io.*; import java.io.*;
import java.nio.file.Path; import java.nio.file.Path;
import java.nio.file.Paths; import java.nio.file.Paths;
...@@ -368,4 +370,11 @@ public class SSLConfig ...@@ -368,4 +370,11 @@ public class SSLConfig
return file.getCanonicalPath(); return file.getCanonicalPath();
} }
public static SSLContext getSSLContext() throws NoSuchAlgorithmException
{
// TODO: allow different algorithms for differetn connection types (eg client/server/bosh etc)
final String algorithm = JiveGlobals.getProperty( ConnectionSettings.Client.TLS_ALGORITHM, "TLS" );
return SSLContext.getInstance( algorithm );
}
} }
...@@ -105,8 +105,7 @@ public class SSLConfigSocketFactory ...@@ -105,8 +105,7 @@ public class SSLConfigSocketFactory
final IdentityStoreConfig identityStoreConfig = (IdentityStoreConfig) SSLConfig.getInstance().getStoreConfig( Purpose.SOCKETBASED_IDENTITYSTORE ); final IdentityStoreConfig identityStoreConfig = (IdentityStoreConfig) SSLConfig.getInstance().getStoreConfig( Purpose.SOCKETBASED_IDENTITYSTORE );
final TrustStoreConfig trustStoreConfig = (TrustStoreConfig) SSLConfig.getInstance().getStoreConfig( Purpose.SOCKETBASED_C2S_TRUSTSTORE ); final TrustStoreConfig trustStoreConfig = (TrustStoreConfig) SSLConfig.getInstance().getStoreConfig( Purpose.SOCKETBASED_C2S_TRUSTSTORE );
final String algorithm = JiveGlobals.getProperty( ConnectionSettings.Client.TLS_ALGORITHM, "TLS" ); final SSLContext context = SSLConfig.getSSLContext();
final SSLContext context = SSLContext.getInstance( algorithm );
context.init( identityStoreConfig.getKeyManagers(), trustStoreConfig.getTrustManagers(), new java.security.SecureRandom() ); context.init( identityStoreConfig.getKeyManagers(), trustStoreConfig.getTrustManagers(), new java.security.SecureRandom() );
return context.getServerSocketFactory(); return context.getServerSocketFactory();
...@@ -117,8 +116,7 @@ public class SSLConfigSocketFactory ...@@ -117,8 +116,7 @@ public class SSLConfigSocketFactory
final IdentityStoreConfig identityStoreConfig = (IdentityStoreConfig) SSLConfig.getInstance().getStoreConfig( Purpose.SOCKETBASED_IDENTITYSTORE ); final IdentityStoreConfig identityStoreConfig = (IdentityStoreConfig) SSLConfig.getInstance().getStoreConfig( Purpose.SOCKETBASED_IDENTITYSTORE );
final TrustStoreConfig trustStoreConfig = (TrustStoreConfig) SSLConfig.getInstance().getStoreConfig( Purpose.SOCKETBASED_S2S_TRUSTSTORE ); final TrustStoreConfig trustStoreConfig = (TrustStoreConfig) SSLConfig.getInstance().getStoreConfig( Purpose.SOCKETBASED_S2S_TRUSTSTORE );
final String algorithm = JiveGlobals.getProperty( ConnectionSettings.Client.TLS_ALGORITHM, "TLS" ); final SSLContext context = SSLConfig.getSSLContext();
final SSLContext context = SSLContext.getInstance( algorithm );
context.init( identityStoreConfig.getKeyManagers(), trustStoreConfig.getTrustManagers(), new java.security.SecureRandom() ); context.init( identityStoreConfig.getKeyManagers(), trustStoreConfig.getTrustManagers(), new java.security.SecureRandom() );
return context.getServerSocketFactory(); return context.getServerSocketFactory();
......
...@@ -97,8 +97,7 @@ public class TLSWrapper { ...@@ -97,8 +97,7 @@ public class TLSWrapper {
} }
final IdentityStoreConfig identityStoreConfig = (IdentityStoreConfig) sslConfig.getStoreConfig( Purpose.SOCKETBASED_IDENTITYSTORE ); final IdentityStoreConfig identityStoreConfig = (IdentityStoreConfig) sslConfig.getStoreConfig( Purpose.SOCKETBASED_IDENTITYSTORE );
final String algorithm = JiveGlobals.getProperty( ConnectionSettings.Client.TLS_ALGORITHM, "TLS" ); final SSLContext tlsContext = SSLConfig.getSSLContext();
final SSLContext tlsContext = SSLContext.getInstance(algorithm);
tlsContext.init( identityStoreConfig.getKeyManagers(), tm, null); tlsContext.init( identityStoreConfig.getKeyManagers(), tm, null);
/* /*
......
...@@ -397,8 +397,7 @@ public class NIOConnection implements Connection { ...@@ -397,8 +397,7 @@ public class NIOConnection implements Connection {
tm = storeConfig.getTrustManagers(); tm = storeConfig.getTrustManagers();
} }
String algorithm = JiveGlobals.getProperty(ConnectionSettings.Client.TLS_ALGORITHM, "TLS"); final SSLContext tlsContext = SSLConfig.getSSLContext();
SSLContext tlsContext = SSLContext.getInstance( algorithm );
final IdentityStoreConfig identityStoreConfig = (IdentityStoreConfig) sslConfig.getStoreConfig( Purpose.SOCKETBASED_IDENTITYSTORE ); final IdentityStoreConfig identityStoreConfig = (IdentityStoreConfig) sslConfig.getStoreConfig( Purpose.SOCKETBASED_IDENTITYSTORE );
tlsContext.init( identityStoreConfig.getKeyManagers(), tm, null); tlsContext.init( identityStoreConfig.getKeyManagers(), tm, null);
......
/** /**
* $RCSfile: ConnectionManagerImpl.java,v $ * $RCSfile: ConnectionManagerImpl.java,v $
* $Revision: $ * $Revision: $
* $Date: $ * $Date: $
* *
* Copyright (C) 2005-2008 Jive Software. All rights reserved. * Copyright (C) 2005-2008 Jive Software. All rights reserved.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package org.jivesoftware.openfire.spi; package org.jivesoftware.openfire.spi;
import java.io.IOException; import java.io.IOException;
import java.lang.management.ManagementFactory; import java.lang.management.ManagementFactory;
import java.net.InetAddress; import java.net.InetAddress;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
import java.net.Socket; import java.net.Socket;
import java.net.UnknownHostException; import java.net.UnknownHostException;
import java.security.KeyStore; import java.security.KeyStore;
import java.security.KeyStoreException; import java.security.KeyStoreException;
import java.security.cert.X509Certificate; import java.security.cert.X509Certificate;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.concurrent.ThreadFactory; import java.util.concurrent.ThreadFactory;
import java.util.concurrent.ThreadPoolExecutor; import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicInteger;
import javax.management.JMException; import javax.management.JMException;
import javax.management.MBeanServer; import javax.management.MBeanServer;
import javax.management.ObjectName; import javax.management.ObjectName;
import javax.net.ssl.SSLContext; import javax.net.ssl.SSLContext;
import org.apache.mina.core.buffer.IoBuffer; import org.apache.mina.core.buffer.IoBuffer;
import org.apache.mina.core.buffer.SimpleBufferAllocator; import org.apache.mina.core.buffer.SimpleBufferAllocator;
import org.apache.mina.core.service.IoService; import org.apache.mina.core.service.IoService;
import org.apache.mina.core.service.IoServiceListener; import org.apache.mina.core.service.IoServiceListener;
import org.apache.mina.core.session.IdleStatus; import org.apache.mina.core.session.IdleStatus;
import org.apache.mina.core.session.IoSession; import org.apache.mina.core.session.IoSession;
import org.apache.mina.filter.codec.ProtocolCodecFilter; import org.apache.mina.filter.codec.ProtocolCodecFilter;
import org.apache.mina.filter.executor.ExecutorFilter; import org.apache.mina.filter.executor.ExecutorFilter;
import org.apache.mina.filter.ssl.SslFilter; import org.apache.mina.filter.ssl.SslFilter;
import org.apache.mina.integration.jmx.IoServiceMBean; import org.apache.mina.integration.jmx.IoServiceMBean;
import org.apache.mina.integration.jmx.IoSessionMBean; import org.apache.mina.integration.jmx.IoSessionMBean;
import org.apache.mina.transport.socket.SocketSessionConfig; import org.apache.mina.transport.socket.SocketSessionConfig;
import org.apache.mina.transport.socket.nio.NioSocketAcceptor; import org.apache.mina.transport.socket.nio.NioSocketAcceptor;
import org.jivesoftware.openfire.ConnectionManager; import org.jivesoftware.openfire.ConnectionManager;
import org.jivesoftware.openfire.JMXManager; import org.jivesoftware.openfire.JMXManager;
import org.jivesoftware.openfire.PacketDeliverer; import org.jivesoftware.openfire.PacketDeliverer;
import org.jivesoftware.openfire.PacketRouter; import org.jivesoftware.openfire.PacketRouter;
import org.jivesoftware.openfire.RoutingTable; import org.jivesoftware.openfire.RoutingTable;
import org.jivesoftware.openfire.ServerPort; import org.jivesoftware.openfire.ServerPort;
import org.jivesoftware.openfire.SessionManager; import org.jivesoftware.openfire.SessionManager;
import org.jivesoftware.openfire.XMPPServer; import org.jivesoftware.openfire.XMPPServer;
import org.jivesoftware.openfire.container.BasicModule; import org.jivesoftware.openfire.container.BasicModule;
import org.jivesoftware.openfire.container.PluginManager; import org.jivesoftware.openfire.container.PluginManager;
import org.jivesoftware.openfire.container.PluginManagerListener; import org.jivesoftware.openfire.container.PluginManagerListener;
import org.jivesoftware.openfire.http.HttpBindManager; import org.jivesoftware.openfire.http.HttpBindManager;
import org.jivesoftware.openfire.keystore.IdentityStoreConfig; import org.jivesoftware.openfire.keystore.IdentityStoreConfig;
import org.jivesoftware.openfire.keystore.Purpose; import org.jivesoftware.openfire.keystore.Purpose;
import org.jivesoftware.openfire.keystore.TrustStoreConfig; import org.jivesoftware.openfire.keystore.TrustStoreConfig;
import org.jivesoftware.openfire.net.*; import org.jivesoftware.openfire.net.*;
import org.jivesoftware.openfire.nio.ClientConnectionHandler; import org.jivesoftware.openfire.nio.ClientConnectionHandler;
import org.jivesoftware.openfire.nio.ComponentConnectionHandler; import org.jivesoftware.openfire.nio.ComponentConnectionHandler;
import org.jivesoftware.openfire.nio.MultiplexerConnectionHandler; import org.jivesoftware.openfire.nio.MultiplexerConnectionHandler;
import org.jivesoftware.openfire.nio.XMPPCodecFactory; import org.jivesoftware.openfire.nio.XMPPCodecFactory;
import org.jivesoftware.openfire.session.ConnectionSettings; import org.jivesoftware.openfire.session.ConnectionSettings;
import org.jivesoftware.util.*; import org.jivesoftware.util.*;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
public class ConnectionManagerImpl extends BasicModule implements ConnectionManager, CertificateEventListener, PropertyEventListener { public class ConnectionManagerImpl extends BasicModule implements ConnectionManager, CertificateEventListener, PropertyEventListener {
private static final int MB = 1024 * 1024; private static final int MB = 1024 * 1024;
public static final String EXECUTOR_FILTER_NAME = "threadModel"; public static final String EXECUTOR_FILTER_NAME = "threadModel";
public static final String TLS_FILTER_NAME = "tls"; public static final String TLS_FILTER_NAME = "tls";
public static final String COMPRESSION_FILTER_NAME = "compression"; public static final String COMPRESSION_FILTER_NAME = "compression";
public static final String XMPP_CODEC_FILTER_NAME = "xmpp"; public static final String XMPP_CODEC_FILTER_NAME = "xmpp";
public static final String CAPACITY_FILTER_NAME = "outCap"; public static final String CAPACITY_FILTER_NAME = "outCap";
private static final String CLIENT_SOCKET_ACCEPTOR_NAME = "client"; private static final String CLIENT_SOCKET_ACCEPTOR_NAME = "client";
private static final String CLIENT_SSL_SOCKET_ACCEPTOR_NAME = "client_ssl"; private static final String CLIENT_SSL_SOCKET_ACCEPTOR_NAME = "client_ssl";
private static final String COMPONENT_SOCKET_ACCEPTOR_NAME = "component"; private static final String COMPONENT_SOCKET_ACCEPTOR_NAME = "component";
private static final String MULTIPLEXER_SOCKET_ACCEPTOR_NAME = "multiplexer"; private static final String MULTIPLEXER_SOCKET_ACCEPTOR_NAME = "multiplexer";
private static final Logger Log = LoggerFactory.getLogger(ConnectionManagerImpl.class); private static final Logger Log = LoggerFactory.getLogger(ConnectionManagerImpl.class);
private NioSocketAcceptor socketAcceptor; private NioSocketAcceptor socketAcceptor;
private NioSocketAcceptor sslSocketAcceptor; private NioSocketAcceptor sslSocketAcceptor;
private NioSocketAcceptor componentAcceptor; private NioSocketAcceptor componentAcceptor;
private SocketAcceptThread serverSocketThread; private SocketAcceptThread serverSocketThread;
private NioSocketAcceptor multiplexerSocketAcceptor; private NioSocketAcceptor multiplexerSocketAcceptor;
private ArrayList<ServerPort> ports; private ArrayList<ServerPort> ports;
private SessionManager sessionManager; private SessionManager sessionManager;
private PacketDeliverer deliverer; private PacketDeliverer deliverer;
private PacketRouter router; private PacketRouter router;
private RoutingTable routingTable; private RoutingTable routingTable;
private String serverName; private String serverName;
private String localIPAddress = null; private String localIPAddress = null;
// Used to know if the sockets have been started // Used to know if the sockets have been started
private boolean isSocketStarted = false; private boolean isSocketStarted = false;
public ConnectionManagerImpl() { public ConnectionManagerImpl() {
super("Connection Manager"); super("Connection Manager");
ports = new ArrayList<>(4); ports = new ArrayList<>(4);
} }
private synchronized void createListeners() { private synchronized void createListeners() {
if (isSocketStarted || sessionManager == null || deliverer == null || router == null || serverName == null) { if (isSocketStarted || sessionManager == null || deliverer == null || router == null || serverName == null) {
return; return;
} }
// Create the port listener for s2s communication // Create the port listener for s2s communication
createServerListener(localIPAddress); createServerListener(localIPAddress);
// Create the port listener for Connections Multiplexers // Create the port listener for Connections Multiplexers
createConnectionManagerListener(); createConnectionManagerListener();
// Create the port listener for external components // Create the port listener for external components
createComponentListener(); createComponentListener();
// Create the port listener for clients // Create the port listener for clients
createClientListeners(); createClientListeners();
// Create the port listener for secured clients // Create the port listener for secured clients
createClientSSLListeners(); createClientSSLListeners();
} }
private synchronized void startListeners() { private synchronized void startListeners() {
if (isSocketStarted || sessionManager == null || deliverer == null || router == null || serverName == null) { if (isSocketStarted || sessionManager == null || deliverer == null || router == null || serverName == null) {
return; return;
} }
// Check if plugins have been loaded // Check if plugins have been loaded
PluginManager pluginManager = XMPPServer.getInstance().getPluginManager(); PluginManager pluginManager = XMPPServer.getInstance().getPluginManager();
if (!pluginManager.isExecuted()) { if (!pluginManager.isExecuted()) {
pluginManager.addPluginManagerListener(new PluginManagerListener() { pluginManager.addPluginManagerListener(new PluginManagerListener() {
@Override @Override
public void pluginsMonitored() { public void pluginsMonitored() {
// Stop listening for plugin events // Stop listening for plugin events
XMPPServer.getInstance().getPluginManager().removePluginManagerListener(this); XMPPServer.getInstance().getPluginManager().removePluginManagerListener(this);
// Start listeners // Start listeners
startListeners(); startListeners();
} }
}); });
return; return;
} }
isSocketStarted = true; isSocketStarted = true;
// Setup port info // Setup port info
try { try {
localIPAddress = InetAddress.getLocalHost().getHostAddress(); localIPAddress = InetAddress.getLocalHost().getHostAddress();
} }
catch (UnknownHostException e) { catch (UnknownHostException e) {
if (localIPAddress == null) { if (localIPAddress == null) {
localIPAddress = "Unknown"; localIPAddress = "Unknown";
} }
} }
// Start the port listener for s2s communication // Start the port listener for s2s communication
startServerListener(); startServerListener();
// Start the port listener for Connections Multiplexers // Start the port listener for Connections Multiplexers
startConnectionManagerListener(localIPAddress); startConnectionManagerListener(localIPAddress);
// Start the port listener for external components // Start the port listener for external components
startComponentListener(); startComponentListener();
// Start the port listener for clients // Start the port listener for clients
startClientListeners(localIPAddress); startClientListeners(localIPAddress);
// Start the port listener for secured clients // Start the port listener for secured clients
startClientSSLListeners(localIPAddress); startClientSSLListeners(localIPAddress);
// Start the HTTP client listener // Start the HTTP client listener
startHTTPBindListeners(); startHTTPBindListeners();
} }
private void createServerListener(String localIPAddress) { private void createServerListener(String localIPAddress) {
// Start servers socket unless it's been disabled. // Start servers socket unless it's been disabled.
if (isServerListenerEnabled()) { if (isServerListenerEnabled()) {
int port = getServerListenerPort(); int port = getServerListenerPort();
try { try {
serverSocketThread = new SocketAcceptThread(this, new ServerPort(port, serverName, serverSocketThread = new SocketAcceptThread(this, new ServerPort(port, serverName,
localIPAddress, false, null, ServerPort.Type.server)); localIPAddress, false, null, ServerPort.Type.server));
ports.add(serverSocketThread.getServerPort()); ports.add(serverSocketThread.getServerPort());
serverSocketThread.setDaemon(true); serverSocketThread.setDaemon(true);
serverSocketThread.setPriority(Thread.MAX_PRIORITY); serverSocketThread.setPriority(Thread.MAX_PRIORITY);
} }
catch (Exception e) { catch (Exception e) {
System.err.println("Error creating server listener on port " + port + ": " + System.err.println("Error creating server listener on port " + port + ": " +
e.getMessage()); e.getMessage());
Log.error(LocaleUtils.getLocalizedString("admin.error.socket-setup"), e); Log.error(LocaleUtils.getLocalizedString("admin.error.socket-setup"), e);
} }
} }
} }
private void startServerListener() { private void startServerListener() {
// Start servers socket unless it's been disabled. // Start servers socket unless it's been disabled.
if (isServerListenerEnabled()) { if (isServerListenerEnabled()) {
int port = getServerListenerPort(); int port = getServerListenerPort();
try { try {
serverSocketThread.start(); serverSocketThread.start();
List<String> params = new ArrayList<>(); List<String> params = new ArrayList<>();
params.add(Integer.toString(serverSocketThread.getPort())); params.add(Integer.toString(serverSocketThread.getPort()));
Log.info(LocaleUtils.getLocalizedString("startup.server", params)); Log.info(LocaleUtils.getLocalizedString("startup.server", params));
} }
catch (Exception e) { catch (Exception e) {
System.err.println("Error starting server listener on port " + port + ": " + System.err.println("Error starting server listener on port " + port + ": " +
e.getMessage()); e.getMessage());
Log.error(LocaleUtils.getLocalizedString("admin.error.socket-setup"), e); Log.error(LocaleUtils.getLocalizedString("admin.error.socket-setup"), e);
} }
} }
} }
private void stopServerListener() { private void stopServerListener() {
if (serverSocketThread != null) { if (serverSocketThread != null) {
serverSocketThread.shutdown(); serverSocketThread.shutdown();
ports.remove(serverSocketThread.getServerPort()); ports.remove(serverSocketThread.getServerPort());
serverSocketThread = null; serverSocketThread = null;
} }
} }
private void createConnectionManagerListener() { private void createConnectionManagerListener() {
// Start multiplexers socket unless it's been disabled. // Start multiplexers socket unless it's been disabled.
if (isConnectionManagerListenerEnabled()) { if (isConnectionManagerListenerEnabled()) {
// Create SocketAcceptor with correct number of processors // Create SocketAcceptor with correct number of processors
multiplexerSocketAcceptor = buildSocketAcceptor(MULTIPLEXER_SOCKET_ACCEPTOR_NAME); multiplexerSocketAcceptor = buildSocketAcceptor(MULTIPLEXER_SOCKET_ACCEPTOR_NAME);
// Customize Executor that will be used by processors to process incoming stanzas // Customize Executor that will be used by processors to process incoming stanzas
int maxPoolSize = JiveGlobals.getIntProperty("xmpp.multiplex.processing.threads", 16); int maxPoolSize = JiveGlobals.getIntProperty("xmpp.multiplex.processing.threads", 16);
ExecutorFilter executorFilter = new ExecutorFilter(getCorePoolSize(maxPoolSize), maxPoolSize, 60, TimeUnit.SECONDS); ExecutorFilter executorFilter = new ExecutorFilter(getCorePoolSize(maxPoolSize), maxPoolSize, 60, TimeUnit.SECONDS);
ThreadPoolExecutor eventExecutor = (ThreadPoolExecutor)executorFilter.getExecutor(); ThreadPoolExecutor eventExecutor = (ThreadPoolExecutor)executorFilter.getExecutor();
ThreadFactory threadFactory = eventExecutor.getThreadFactory(); ThreadFactory threadFactory = eventExecutor.getThreadFactory();
threadFactory = new DelegatingThreadFactory("Multiplexer-Thread-", threadFactory); threadFactory = new DelegatingThreadFactory("Multiplexer-Thread-", threadFactory);
eventExecutor.setThreadFactory(threadFactory); eventExecutor.setThreadFactory(threadFactory);
multiplexerSocketAcceptor.getFilterChain().addFirst(EXECUTOR_FILTER_NAME, executorFilter); multiplexerSocketAcceptor.getFilterChain().addFirst(EXECUTOR_FILTER_NAME, executorFilter);
// Add the XMPP codec filter // Add the XMPP codec filter
multiplexerSocketAcceptor.getFilterChain().addAfter(EXECUTOR_FILTER_NAME, XMPP_CODEC_FILTER_NAME, new ProtocolCodecFilter(new XMPPCodecFactory())); multiplexerSocketAcceptor.getFilterChain().addAfter(EXECUTOR_FILTER_NAME, XMPP_CODEC_FILTER_NAME, new ProtocolCodecFilter(new XMPPCodecFactory()));
} }
} }
private void startConnectionManagerListener(String localIPAddress) { private void startConnectionManagerListener(String localIPAddress) {
// Start multiplexers socket unless it's been disabled. // Start multiplexers socket unless it's been disabled.
if (isConnectionManagerListenerEnabled()) { if (isConnectionManagerListenerEnabled()) {
int port = getConnectionManagerListenerPort(); int port = getConnectionManagerListenerPort();
try { try {
// Listen on a specific network interface if it has been set. // Listen on a specific network interface if it has been set.
String interfaceName = JiveGlobals.getXMLProperty("network.interface"); String interfaceName = JiveGlobals.getXMLProperty("network.interface");
InetAddress bindInterface = null; InetAddress bindInterface = null;
if (interfaceName != null) { if (interfaceName != null) {
if (interfaceName.trim().length() > 0) { if (interfaceName.trim().length() > 0) {
bindInterface = InetAddress.getByName(interfaceName); bindInterface = InetAddress.getByName(interfaceName);
} }
} }
// Start accepting connections // Start accepting connections
multiplexerSocketAcceptor.setHandler(new MultiplexerConnectionHandler(serverName)); multiplexerSocketAcceptor.setHandler(new MultiplexerConnectionHandler(serverName));
multiplexerSocketAcceptor.bind(new InetSocketAddress(bindInterface, port)); multiplexerSocketAcceptor.bind(new InetSocketAddress(bindInterface, port));
ports.add(new ServerPort(port, serverName, localIPAddress, false, null, ServerPort.Type.connectionManager)); ports.add(new ServerPort(port, serverName, localIPAddress, false, null, ServerPort.Type.connectionManager));
List<String> params = new ArrayList<>(); List<String> params = new ArrayList<String>();
params.add(Integer.toString(port)); params.add(Integer.toString(port));
Log.info(LocaleUtils.getLocalizedString("startup.multiplexer", params)); Log.info(LocaleUtils.getLocalizedString("startup.multiplexer", params));
} }
catch (Exception e) { catch (Exception e) {
System.err.println("Error starting multiplexer listener on port " + port + ": " + System.err.println("Error starting multiplexer listener on port " + port + ": " +
e.getMessage()); e.getMessage());
Log.error(LocaleUtils.getLocalizedString("admin.error.socket-setup"), e); Log.error(LocaleUtils.getLocalizedString("admin.error.socket-setup"), e);
} }
} }
} }
private void stopConnectionManagerListener() { private void stopConnectionManagerListener() {
if (multiplexerSocketAcceptor != null) { if (multiplexerSocketAcceptor != null) {
multiplexerSocketAcceptor.unbind(); multiplexerSocketAcceptor.unbind();
for (ServerPort port : ports) { for (ServerPort port : ports) {
if (port.isConnectionManagerPort()) { if (port.isConnectionManagerPort()) {
ports.remove(port); ports.remove(port);
break; break;
} }
} }
multiplexerSocketAcceptor = null; multiplexerSocketAcceptor = null;
} }
} }
private void createComponentListener() { private void createComponentListener() {
// Start components socket unless it's been disabled. // Start components socket unless it's been disabled.
if (isComponentListenerEnabled() && componentAcceptor == null) { if (isComponentListenerEnabled() && componentAcceptor == null) {
// Create SocketAcceptor with correct number of processors // Create SocketAcceptor with correct number of processors
componentAcceptor = buildSocketAcceptor(COMPONENT_SOCKET_ACCEPTOR_NAME); componentAcceptor = buildSocketAcceptor(COMPONENT_SOCKET_ACCEPTOR_NAME);
int maxPoolSize = JiveGlobals.getIntProperty("xmpp.component.processing.threads", 16); int maxPoolSize = JiveGlobals.getIntProperty("xmpp.component.processing.threads", 16);
ExecutorFilter executorFilter = new ExecutorFilter(getCorePoolSize(maxPoolSize), maxPoolSize, 60, TimeUnit.SECONDS); ExecutorFilter executorFilter = new ExecutorFilter(getCorePoolSize(maxPoolSize), maxPoolSize, 60, TimeUnit.SECONDS);
ThreadPoolExecutor eventExecutor = (ThreadPoolExecutor)executorFilter.getExecutor(); ThreadPoolExecutor eventExecutor = (ThreadPoolExecutor)executorFilter.getExecutor();
ThreadFactory threadFactory = eventExecutor.getThreadFactory(); ThreadFactory threadFactory = eventExecutor.getThreadFactory();
threadFactory = new DelegatingThreadFactory("Component-Thread-", threadFactory); threadFactory = new DelegatingThreadFactory("Component-Thread-", threadFactory);
eventExecutor.setThreadFactory(threadFactory); eventExecutor.setThreadFactory(threadFactory);
componentAcceptor.getFilterChain().addFirst(EXECUTOR_FILTER_NAME, executorFilter); componentAcceptor.getFilterChain().addFirst(EXECUTOR_FILTER_NAME, executorFilter);
// Add the XMPP codec filter // Add the XMPP codec filter
componentAcceptor.getFilterChain().addAfter(EXECUTOR_FILTER_NAME, XMPP_CODEC_FILTER_NAME, new ProtocolCodecFilter(new XMPPCodecFactory())); componentAcceptor.getFilterChain().addAfter(EXECUTOR_FILTER_NAME, XMPP_CODEC_FILTER_NAME, new ProtocolCodecFilter(new XMPPCodecFactory()));
} }
} }
private void startComponentListener() { private void startComponentListener() {
// Start components socket unless it's been disabled. // Start components socket unless it's been disabled.
if (isComponentListenerEnabled() && componentAcceptor != null && if (isComponentListenerEnabled() && componentAcceptor != null &&
componentAcceptor.getManagedSessionCount() == 0) { componentAcceptor.getManagedSessionCount() == 0) {
int port = getComponentListenerPort(); int port = getComponentListenerPort();
try { try {
// Listen on a specific network interface if it has been set. // Listen on a specific network interface if it has been set.
String interfaceName = JiveGlobals.getXMLProperty("network.interface"); String interfaceName = JiveGlobals.getXMLProperty("network.interface");
InetAddress bindInterface = null; InetAddress bindInterface = null;
if (interfaceName != null) { if (interfaceName != null) {
if (interfaceName.trim().length() > 0) { if (interfaceName.trim().length() > 0) {
bindInterface = InetAddress.getByName(interfaceName); bindInterface = InetAddress.getByName(interfaceName);
} }
} }
// Start accepting connections // Start accepting connections
componentAcceptor.setHandler(new ComponentConnectionHandler(serverName)); componentAcceptor.setHandler(new ComponentConnectionHandler(serverName));
componentAcceptor.bind(new InetSocketAddress(bindInterface, port)); componentAcceptor.bind(new InetSocketAddress(bindInterface, port));
ports.add(new ServerPort(port, serverName, localIPAddress, false, null, ServerPort.Type.component)); ports.add(new ServerPort(port, serverName, localIPAddress, false, null, ServerPort.Type.component));
List<String> params = new ArrayList<>(); List<String> params = new ArrayList<String>();
params.add(Integer.toString(port)); params.add(Integer.toString(port));
Log.info(LocaleUtils.getLocalizedString("startup.component", params)); Log.info(LocaleUtils.getLocalizedString("startup.component", params));
} }
catch (Exception e) { catch (Exception e) {
System.err.println("Error starting component listener on port " + port + ": " + System.err.println("Error starting component listener on port " + port + ": " +
e.getMessage()); e.getMessage());
Log.error(LocaleUtils.getLocalizedString("admin.error.socket-setup"), e); Log.error(LocaleUtils.getLocalizedString("admin.error.socket-setup"), e);
} }
} }
} }
private void stopComponentListener() { private void stopComponentListener() {
if (componentAcceptor != null) { if (componentAcceptor != null) {
componentAcceptor.unbind(); componentAcceptor.unbind();
for (ServerPort port : ports) { for (ServerPort port : ports) {
if (port.isComponentPort()) { if (port.isComponentPort()) {
ports.remove(port); ports.remove(port);
break; break;
} }
} }
componentAcceptor = null; componentAcceptor = null;
} }
} }
private void createClientListeners() { private void createClientListeners() {
// Start clients plain socket unless it's been disabled. // Start clients plain socket unless it's been disabled.
if (isClientListenerEnabled()) { if (isClientListenerEnabled()) {
// Create SocketAcceptor with correct number of processors // Create SocketAcceptor with correct number of processors
socketAcceptor = buildSocketAcceptor(CLIENT_SOCKET_ACCEPTOR_NAME); socketAcceptor = buildSocketAcceptor(CLIENT_SOCKET_ACCEPTOR_NAME);
// Customize Executor that will be used by processors to process incoming stanzas // Customize Executor that will be used by processors to process incoming stanzas
int maxPoolSize = JiveGlobals.getIntProperty(ConnectionSettings.Client.MAX_THREADS, 16); int maxPoolSize = JiveGlobals.getIntProperty(ConnectionSettings.Client.MAX_THREADS, 16);
ExecutorFilter executorFilter = new ExecutorFilter(getCorePoolSize(maxPoolSize), maxPoolSize, 60, TimeUnit.SECONDS); ExecutorFilter executorFilter = new ExecutorFilter(getCorePoolSize(maxPoolSize), maxPoolSize, 60, TimeUnit.SECONDS);
ThreadPoolExecutor eventExecutor = (ThreadPoolExecutor)executorFilter.getExecutor(); ThreadPoolExecutor eventExecutor = (ThreadPoolExecutor)executorFilter.getExecutor();
ThreadFactory threadFactory = eventExecutor.getThreadFactory(); ThreadFactory threadFactory = eventExecutor.getThreadFactory();
threadFactory = new DelegatingThreadFactory("C2S-Thread-", threadFactory); threadFactory = new DelegatingThreadFactory("C2S-Thread-", threadFactory);
eventExecutor.setThreadFactory(threadFactory); eventExecutor.setThreadFactory(threadFactory);
// Add the XMPP codec filter // Add the XMPP codec filter
socketAcceptor.getFilterChain().addFirst(EXECUTOR_FILTER_NAME, executorFilter); socketAcceptor.getFilterChain().addFirst(EXECUTOR_FILTER_NAME, executorFilter);
socketAcceptor.getFilterChain().addAfter(EXECUTOR_FILTER_NAME, XMPP_CODEC_FILTER_NAME, new ProtocolCodecFilter(new XMPPCodecFactory())); socketAcceptor.getFilterChain().addAfter(EXECUTOR_FILTER_NAME, XMPP_CODEC_FILTER_NAME, new ProtocolCodecFilter(new XMPPCodecFactory()));
// Kill sessions whose outgoing queues keep growing and fail to send traffic // Kill sessions whose outgoing queues keep growing and fail to send traffic
socketAcceptor.getFilterChain().addAfter(XMPP_CODEC_FILTER_NAME, CAPACITY_FILTER_NAME, new StalledSessionsFilter()); socketAcceptor.getFilterChain().addAfter(XMPP_CODEC_FILTER_NAME, CAPACITY_FILTER_NAME, new StalledSessionsFilter());
// Throttle sessions who send data too fast // Throttle sessions who send data too fast
int maxBufferSize = JiveGlobals.getIntProperty(ConnectionSettings.Client.MAX_READ_BUFFER, 10 * MB); int maxBufferSize = JiveGlobals.getIntProperty(ConnectionSettings.Client.MAX_READ_BUFFER, 10 * MB);
socketAcceptor.getSessionConfig().setMaxReadBufferSize(maxBufferSize); socketAcceptor.getSessionConfig().setMaxReadBufferSize(maxBufferSize);
Log.debug("Throttling read buffer for connections from socketAcceptor={} to max={} bytes", Log.debug("Throttling read buffer for connections from socketAcceptor={} to max={} bytes",
socketAcceptor, maxBufferSize); socketAcceptor, maxBufferSize);
} }
} }
private void startClientListeners(String localIPAddress) { private void startClientListeners(String localIPAddress) {
// Start clients plain socket unless it's been disabled. // Start clients plain socket unless it's been disabled.
if (isClientListenerEnabled()) { if (isClientListenerEnabled()) {
int port = getClientListenerPort(); int port = getClientListenerPort();
try { try {
// Listen on a specific network interface if it has been set. // Listen on a specific network interface if it has been set.
String interfaceName = JiveGlobals.getXMLProperty("network.interface"); String interfaceName = JiveGlobals.getXMLProperty("network.interface");
InetAddress bindInterface = null; InetAddress bindInterface = null;
if (interfaceName != null) { if (interfaceName != null) {
if (interfaceName.trim().length() > 0) { if (interfaceName.trim().length() > 0) {
bindInterface = InetAddress.getByName(interfaceName); bindInterface = InetAddress.getByName(interfaceName);
} }
} }
// Start accepting connections // Start accepting connections
socketAcceptor.setHandler(new ClientConnectionHandler(serverName)); socketAcceptor.setHandler(new ClientConnectionHandler(serverName));
socketAcceptor.bind(new InetSocketAddress(bindInterface, port)); socketAcceptor.bind(new InetSocketAddress(bindInterface, port));
ports.add(new ServerPort(port, serverName, localIPAddress, false, null, ServerPort.Type.client)); ports.add(new ServerPort(port, serverName, localIPAddress, false, null, ServerPort.Type.client));
List<String> params = new ArrayList<>(); List<String> params = new ArrayList<String>();
params.add(Integer.toString(port)); params.add(Integer.toString(port));
Log.info(LocaleUtils.getLocalizedString("startup.plain", params)); Log.info(LocaleUtils.getLocalizedString("startup.plain", params));
} }
catch (Exception e) { catch (Exception e) {
System.err.println("Error starting XMPP listener on port " + port + ": " + System.err.println("Error starting XMPP listener on port " + port + ": " +
e.getMessage()); e.getMessage());
Log.error(LocaleUtils.getLocalizedString("admin.error.socket-setup"), e); Log.error(LocaleUtils.getLocalizedString("admin.error.socket-setup"), e);
} }
} }
} }
private void stopClientListeners() { private void stopClientListeners() {
if (socketAcceptor != null) { if (socketAcceptor != null) {
socketAcceptor.unbind(); socketAcceptor.unbind();
for (ServerPort port : ports) { for (ServerPort port : ports) {
if (port.isClientPort() && !port.isSecure()) { if (port.isClientPort() && !port.isSecure()) {
ports.remove(port); ports.remove(port);
break; break;
} }
} }
socketAcceptor = null; socketAcceptor = null;
} }
} }
private void createClientSSLListeners() { private void createClientSSLListeners() {
// Start clients SSL unless it's been disabled. // Start clients SSL unless it's been disabled.
if (isClientSSLListenerEnabled()) { if (isClientSSLListenerEnabled()) {
int port = getClientSSLListenerPort(); int port = getClientSSLListenerPort();
String algorithm = JiveGlobals.getProperty(ConnectionSettings.Client.TLS_ALGORITHM, "TLS"); String algorithm = JiveGlobals.getProperty(ConnectionSettings.Client.TLS_ALGORITHM, "TLS");
try { try {
// Customize Executor that will be used by processors to process incoming stanzas // Customize Executor that will be used by processors to process incoming stanzas
int maxPoolSize = JiveGlobals.getIntProperty(ConnectionSettings.Client.MAX_THREADS_SSL, 16); int maxPoolSize = JiveGlobals.getIntProperty(ConnectionSettings.Client.MAX_THREADS_SSL, 16);
ExecutorFilter executorFilter = new ExecutorFilter(getCorePoolSize(maxPoolSize), maxPoolSize, 60, TimeUnit.SECONDS); ExecutorFilter executorFilter = new ExecutorFilter(getCorePoolSize(maxPoolSize), maxPoolSize, 60, TimeUnit.SECONDS);
ThreadPoolExecutor eventExecutor = (ThreadPoolExecutor)executorFilter.getExecutor(); ThreadPoolExecutor eventExecutor = (ThreadPoolExecutor)executorFilter.getExecutor();
ThreadFactory threadFactory = eventExecutor.getThreadFactory(); ThreadFactory threadFactory = eventExecutor.getThreadFactory();
threadFactory = new DelegatingThreadFactory("LegacySSL-Thread-", threadFactory); threadFactory = new DelegatingThreadFactory("LegacySSL-Thread-", threadFactory);
eventExecutor.setThreadFactory(threadFactory); eventExecutor.setThreadFactory(threadFactory);
// Create SocketAcceptor with correct number of processors // Create SocketAcceptor with correct number of processors
sslSocketAcceptor = buildSocketAcceptor(CLIENT_SSL_SOCKET_ACCEPTOR_NAME); sslSocketAcceptor = buildSocketAcceptor(CLIENT_SSL_SOCKET_ACCEPTOR_NAME);
sslSocketAcceptor.getFilterChain().addFirst(EXECUTOR_FILTER_NAME, executorFilter); sslSocketAcceptor.getFilterChain().addFirst(EXECUTOR_FILTER_NAME, executorFilter);
// Add the XMPP codec filter // Add the XMPP codec filter
sslSocketAcceptor.getFilterChain().addAfter(EXECUTOR_FILTER_NAME, XMPP_CODEC_FILTER_NAME, new ProtocolCodecFilter(new XMPPCodecFactory())); sslSocketAcceptor.getFilterChain().addAfter(EXECUTOR_FILTER_NAME, XMPP_CODEC_FILTER_NAME, new ProtocolCodecFilter(new XMPPCodecFactory()));
// Kill sessions whose outgoing queues keep growing and fail to send traffic // Kill sessions whose outgoing queues keep growing and fail to send traffic
sslSocketAcceptor.getFilterChain().addAfter(XMPP_CODEC_FILTER_NAME, CAPACITY_FILTER_NAME, new StalledSessionsFilter()); sslSocketAcceptor.getFilterChain().addAfter(XMPP_CODEC_FILTER_NAME, CAPACITY_FILTER_NAME, new StalledSessionsFilter());
// Throttle sessions who send data too fast // Throttle sessions who send data too fast
int maxBufferSize = JiveGlobals.getIntProperty(ConnectionSettings.Client.MAX_READ_BUFFER_SSL, 10 * MB); int maxBufferSize = JiveGlobals.getIntProperty(ConnectionSettings.Client.MAX_READ_BUFFER_SSL, 10 * MB);
sslSocketAcceptor.getSessionConfig().setMaxReadBufferSize(maxBufferSize); sslSocketAcceptor.getSessionConfig().setMaxReadBufferSize(maxBufferSize);
Log.debug("Throttling read buffer for connections from sslSocketAcceptor={} to max={} bytes", Log.debug("Throttling read buffer for connections from sslSocketAcceptor={} to max={} bytes",
sslSocketAcceptor, maxBufferSize); sslSocketAcceptor, maxBufferSize);
// Add the SSL filter now since sockets are "borned" encrypted in the old ssl method // Add the SSL filter now since sockets are "borned" encrypted in the old ssl method
final IdentityStoreConfig identityStoreConfig = (IdentityStoreConfig) SSLConfig.getInstance().getStoreConfig( Purpose.SOCKETBASED_IDENTITYSTORE ); final IdentityStoreConfig identityStoreConfig = (IdentityStoreConfig) SSLConfig.getInstance().getStoreConfig( Purpose.SOCKETBASED_IDENTITYSTORE );
final TrustStoreConfig trustStoreConfig = (TrustStoreConfig) SSLConfig.getInstance().getStoreConfig( Purpose.SOCKETBASED_C2S_TRUSTSTORE ); final TrustStoreConfig trustStoreConfig = (TrustStoreConfig) SSLConfig.getInstance().getStoreConfig( Purpose.SOCKETBASED_C2S_TRUSTSTORE );
final SSLContext sslContext = SSLContext.getInstance( algorithm ); final SSLContext sslContext = SSLConfig.getSSLContext();
sslContext.init( identityStoreConfig.getKeyManagers(), trustStoreConfig.getTrustManagers(), new java.security.SecureRandom()); sslContext.init( identityStoreConfig.getKeyManagers(), trustStoreConfig.getTrustManagers(), new java.security.SecureRandom());
SslFilter sslFilter = new SslFilter(sslContext); SslFilter sslFilter = new SslFilter(sslContext);
if (JiveGlobals.getProperty(ConnectionSettings.Client.AUTH_PER_CLIENTCERT_POLICY,"disabled").equals("needed")) { if (JiveGlobals.getProperty(ConnectionSettings.Client.AUTH_PER_CLIENTCERT_POLICY,"disabled").equals("needed")) {
sslFilter.setNeedClientAuth(true); sslFilter.setNeedClientAuth(true);
} }
else if(JiveGlobals.getProperty(ConnectionSettings.Client.AUTH_PER_CLIENTCERT_POLICY,"disabled").equals("wanted")) { else if(JiveGlobals.getProperty(ConnectionSettings.Client.AUTH_PER_CLIENTCERT_POLICY,"disabled").equals("wanted")) {
sslFilter.setWantClientAuth(true); sslFilter.setWantClientAuth(true);
} }
sslSocketAcceptor.getFilterChain().addAfter(EXECUTOR_FILTER_NAME, TLS_FILTER_NAME, sslFilter); sslSocketAcceptor.getFilterChain().addAfter(EXECUTOR_FILTER_NAME, TLS_FILTER_NAME, sslFilter);
} }
catch (Exception e) { catch (Exception e) {
System.err.println("Error starting SSL XMPP listener on port " + port + ": " + System.err.println("Error starting SSL XMPP listener on port " + port + ": " +
e.getMessage()); e.getMessage());
Log.error(LocaleUtils.getLocalizedString("admin.error.ssl"), e); Log.error(LocaleUtils.getLocalizedString("admin.error.ssl"), e);
} }
} }
} }
private void startClientSSLListeners(String localIPAddress) { private void startClientSSLListeners(String localIPAddress) {
// Start clients SSL unless it's been disabled. // Start clients SSL unless it's been disabled.
if (isClientSSLListenerEnabled()) { if (isClientSSLListenerEnabled()) {
int port = getClientSSLListenerPort(); int port = getClientSSLListenerPort();
try { try {
// Listen on a specific network interface if it has been set. // Listen on a specific network interface if it has been set.
String interfaceName = JiveGlobals.getXMLProperty("network.interface"); String interfaceName = JiveGlobals.getXMLProperty("network.interface");
InetAddress bindInterface = null; InetAddress bindInterface = null;
if (interfaceName != null) { if (interfaceName != null) {
if (interfaceName.trim().length() > 0) { if (interfaceName.trim().length() > 0) {
bindInterface = InetAddress.getByName(interfaceName); bindInterface = InetAddress.getByName(interfaceName);
} }
} }
// Start accepting connections // Start accepting connections
sslSocketAcceptor.setHandler(new ClientConnectionHandler(serverName)); sslSocketAcceptor.setHandler(new ClientConnectionHandler(serverName));
sslSocketAcceptor.bind(new InetSocketAddress(bindInterface, port)); sslSocketAcceptor.bind(new InetSocketAddress(bindInterface, port));
ports.add(new ServerPort(port, serverName, localIPAddress, true, null, ServerPort.Type.client)); ports.add(new ServerPort(port, serverName, localIPAddress, true, null, ServerPort.Type.client));
List<String> params = new ArrayList<>(); List<String> params = new ArrayList<>();
params.add(Integer.toString(port)); params.add(Integer.toString(port));
Log.info(LocaleUtils.getLocalizedString("startup.ssl", params)); Log.info(LocaleUtils.getLocalizedString("startup.ssl", params));
} }
catch (Exception e) { catch (Exception e) {
System.err.println("Error starting SSL XMPP listener on port " + port + ": " + System.err.println("Error starting SSL XMPP listener on port " + port + ": " +
e.getMessage()); e.getMessage());
Log.error(LocaleUtils.getLocalizedString("admin.error.ssl"), e); Log.error(LocaleUtils.getLocalizedString("admin.error.ssl"), e);
} }
} }
} }
private void stopClientSSLListeners() { private void stopClientSSLListeners() {
if (sslSocketAcceptor != null) { if (sslSocketAcceptor != null) {
sslSocketAcceptor.unbind(); sslSocketAcceptor.unbind();
for (ServerPort port : ports) { for (ServerPort port : ports) {
if (port.isClientPort() && port.isSecure()) { if (port.isClientPort() && port.isSecure()) {
ports.remove(port); ports.remove(port);
break; break;
} }
} }
sslSocketAcceptor = null; sslSocketAcceptor = null;
} }
} }
private void restartClientSSLListeners() { private void restartClientSSLListeners() {
if (!isSocketStarted) { if (!isSocketStarted) {
return; return;
} }
// Setup port info // Setup port info
try { try {
localIPAddress = InetAddress.getLocalHost().getHostAddress(); localIPAddress = InetAddress.getLocalHost().getHostAddress();
} }
catch (UnknownHostException e) { catch (UnknownHostException e) {
if (localIPAddress == null) { if (localIPAddress == null) {
localIPAddress = "Unknown"; localIPAddress = "Unknown";
} }
} }
stopClientSSLListeners(); stopClientSSLListeners();
createClientSSLListeners(); createClientSSLListeners();
startClientSSLListeners(localIPAddress); startClientSSLListeners(localIPAddress);
} }
@Override @Override
public Collection<ServerPort> getPorts() { public Collection<ServerPort> getPorts() {
return ports; return ports;
} }
@Override @Override
public SocketReader createSocketReader(Socket sock, boolean isSecure, ServerPort serverPort, public SocketReader createSocketReader(Socket sock, boolean isSecure, ServerPort serverPort,
boolean useBlockingMode) throws IOException { boolean useBlockingMode) throws IOException {
if (serverPort.isServerPort()) { if (serverPort.isServerPort()) {
SocketConnection conn = new SocketConnection(deliverer, sock, isSecure); SocketConnection conn = new SocketConnection(deliverer, sock, isSecure);
return new ServerSocketReader(router, routingTable, serverName, sock, conn, return new ServerSocketReader(router, routingTable, serverName, sock, conn,
useBlockingMode); useBlockingMode);
} }
return null; return null;
} }
private void startHTTPBindListeners() { private void startHTTPBindListeners() {
HttpBindManager.getInstance().start(); HttpBindManager.getInstance().start();
} }
@Override @Override
public void initialize(XMPPServer server) { public void initialize(XMPPServer server) {
super.initialize(server); super.initialize(server);
serverName = server.getServerInfo().getXMPPDomain(); serverName = server.getServerInfo().getXMPPDomain();
router = server.getPacketRouter(); router = server.getPacketRouter();
routingTable = server.getRoutingTable(); routingTable = server.getRoutingTable();
deliverer = server.getPacketDeliverer(); deliverer = server.getPacketDeliverer();
sessionManager = server.getSessionManager(); sessionManager = server.getSessionManager();
// Check if we need to configure MINA to use Direct or Heap Buffers // Check if we need to configure MINA to use Direct or Heap Buffers
// Note: It has been reported that heap buffers are 50% faster than direct buffers // Note: It has been reported that heap buffers are 50% faster than direct buffers
if (JiveGlobals.getBooleanProperty("xmpp.socket.heapBuffer", true)) { if (JiveGlobals.getBooleanProperty("xmpp.socket.heapBuffer", true)) {
IoBuffer.setUseDirectBuffer(false); IoBuffer.setUseDirectBuffer(false);
IoBuffer.setAllocator(new SimpleBufferAllocator()); IoBuffer.setAllocator(new SimpleBufferAllocator());
} }
} }
@Override @Override
public void enableClientListener(boolean enabled) { public void enableClientListener(boolean enabled) {
if (enabled == isClientListenerEnabled()) { if (enabled == isClientListenerEnabled()) {
// Ignore new setting // Ignore new setting
return; return;
} }
if (enabled) { if (enabled) {
JiveGlobals.setProperty(ConnectionSettings.Client.SOCKET_ACTIVE, "true"); JiveGlobals.setProperty(ConnectionSettings.Client.SOCKET_ACTIVE, "true");
// Start the port listener for clients // Start the port listener for clients
createClientListeners(); createClientListeners();
startClientListeners(localIPAddress); startClientListeners(localIPAddress);
} }
else { else {
JiveGlobals.setProperty(ConnectionSettings.Client.SOCKET_ACTIVE, "false"); JiveGlobals.setProperty(ConnectionSettings.Client.SOCKET_ACTIVE, "false");
// Stop the port listener for clients // Stop the port listener for clients
stopClientListeners(); stopClientListeners();
} }
} }
@Override @Override
public boolean isClientListenerEnabled() { public boolean isClientListenerEnabled() {
return JiveGlobals.getBooleanProperty(ConnectionSettings.Client.SOCKET_ACTIVE, true); return JiveGlobals.getBooleanProperty(ConnectionSettings.Client.SOCKET_ACTIVE, true);
} }
@Override @Override
public void enableClientSSLListener(boolean enabled) { public void enableClientSSLListener(boolean enabled) {
if (enabled == isClientSSLListenerEnabled()) { if (enabled == isClientSSLListenerEnabled()) {
// Ignore new setting // Ignore new setting
return; return;
} }
if (enabled) { if (enabled) {
JiveGlobals.setProperty(ConnectionSettings.Client.ENABLE_OLD_SSLPORT, "true"); JiveGlobals.setProperty(ConnectionSettings.Client.ENABLE_OLD_SSLPORT, "true");
// Start the port listener for secured clients // Start the port listener for secured clients
createClientSSLListeners(); createClientSSLListeners();
startClientSSLListeners(localIPAddress); startClientSSLListeners(localIPAddress);
} }
else { else {
JiveGlobals.setProperty(ConnectionSettings.Client.ENABLE_OLD_SSLPORT, "false"); JiveGlobals.setProperty(ConnectionSettings.Client.ENABLE_OLD_SSLPORT, "false");
// Stop the port listener for secured clients // Stop the port listener for secured clients
stopClientSSLListeners(); stopClientSSLListeners();
} }
} }
@Override @Override
public boolean isClientSSLListenerEnabled() { public boolean isClientSSLListenerEnabled() {
try { try {
return JiveGlobals.getBooleanProperty(ConnectionSettings.Client.ENABLE_OLD_SSLPORT, false) && SSLConfig.getStore( Purpose.SOCKETBASED_IDENTITYSTORE ).size() > 0; return JiveGlobals.getBooleanProperty(ConnectionSettings.Client.ENABLE_OLD_SSLPORT, false) && SSLConfig.getStore( Purpose.SOCKETBASED_IDENTITYSTORE ).size() > 0;
} catch (KeyStoreException e) { } catch (KeyStoreException e) {
return false; return false;
} }
} }
@Override @Override
public void enableComponentListener(boolean enabled) { public void enableComponentListener(boolean enabled) {
if (enabled == isComponentListenerEnabled()) { if (enabled == isComponentListenerEnabled()) {
// Ignore new setting // Ignore new setting
return; return;
} }
if (enabled) { if (enabled) {
JiveGlobals.setProperty(ConnectionSettings.Component.SOCKET_ACTIVE, "true"); JiveGlobals.setProperty(ConnectionSettings.Component.SOCKET_ACTIVE, "true");
// Start the port listener for external components // Start the port listener for external components
createComponentListener(); createComponentListener();
startComponentListener(); startComponentListener();
} }
else { else {
JiveGlobals.setProperty(ConnectionSettings.Component.SOCKET_ACTIVE, "false"); JiveGlobals.setProperty(ConnectionSettings.Component.SOCKET_ACTIVE, "false");
// Stop the port listener for external components // Stop the port listener for external components
stopComponentListener(); stopComponentListener();
} }
} }
@Override @Override
public boolean isComponentListenerEnabled() { public boolean isComponentListenerEnabled() {
return JiveGlobals.getBooleanProperty(ConnectionSettings.Component.SOCKET_ACTIVE, false); return JiveGlobals.getBooleanProperty(ConnectionSettings.Component.SOCKET_ACTIVE, false);
} }
@Override @Override
public void enableServerListener(boolean enabled) { public void enableServerListener(boolean enabled) {
if (enabled == isServerListenerEnabled()) { if (enabled == isServerListenerEnabled()) {
// Ignore new setting // Ignore new setting
return; return;
} }
if (enabled) { if (enabled) {
JiveGlobals.setProperty(ConnectionSettings.Server.SOCKET_ACTIVE, "true"); JiveGlobals.setProperty(ConnectionSettings.Server.SOCKET_ACTIVE, "true");
// Start the port listener for s2s communication // Start the port listener for s2s communication
createServerListener(localIPAddress); createServerListener(localIPAddress);
startServerListener(); startServerListener();
} }
else { else {
JiveGlobals.setProperty(ConnectionSettings.Server.SOCKET_ACTIVE, "false"); JiveGlobals.setProperty(ConnectionSettings.Server.SOCKET_ACTIVE, "false");
// Stop the port listener for s2s communication // Stop the port listener for s2s communication
stopServerListener(); stopServerListener();
} }
} }
@Override @Override
public boolean isServerListenerEnabled() { public boolean isServerListenerEnabled() {
return JiveGlobals.getBooleanProperty(ConnectionSettings.Server.SOCKET_ACTIVE, true); return JiveGlobals.getBooleanProperty(ConnectionSettings.Server.SOCKET_ACTIVE, true);
} }
@Override @Override
public void enableConnectionManagerListener(boolean enabled) { public void enableConnectionManagerListener(boolean enabled) {
if (enabled == isConnectionManagerListenerEnabled()) { if (enabled == isConnectionManagerListenerEnabled()) {
// Ignore new setting // Ignore new setting
return; return;
} }
if (enabled) { if (enabled) {
JiveGlobals.setProperty(ConnectionSettings.Multiplex.SOCKET_ACTIVE, "true"); JiveGlobals.setProperty(ConnectionSettings.Multiplex.SOCKET_ACTIVE, "true");
// Start the port listener for s2s communication // Start the port listener for s2s communication
createConnectionManagerListener(); createConnectionManagerListener();
startConnectionManagerListener(localIPAddress); startConnectionManagerListener(localIPAddress);
} }
else { else {
JiveGlobals.setProperty(ConnectionSettings.Multiplex.SOCKET_ACTIVE, "false"); JiveGlobals.setProperty(ConnectionSettings.Multiplex.SOCKET_ACTIVE, "false");
// Stop the port listener for s2s communication // Stop the port listener for s2s communication
stopConnectionManagerListener(); stopConnectionManagerListener();
} }
} }
@Override @Override
public boolean isConnectionManagerListenerEnabled() { public boolean isConnectionManagerListenerEnabled() {
return JiveGlobals.getBooleanProperty(ConnectionSettings.Multiplex.SOCKET_ACTIVE, false); return JiveGlobals.getBooleanProperty(ConnectionSettings.Multiplex.SOCKET_ACTIVE, false);
} }
@Override @Override
public void setClientListenerPort(int port) { public void setClientListenerPort(int port) {
if (port == getClientListenerPort()) { if (port == getClientListenerPort()) {
// Ignore new setting // Ignore new setting
return; return;
} }
JiveGlobals.setProperty(ConnectionSettings.Client.PORT, String.valueOf(port)); JiveGlobals.setProperty(ConnectionSettings.Client.PORT, String.valueOf(port));
// Stop the port listener for clients // Stop the port listener for clients
stopClientListeners(); stopClientListeners();
if (isClientListenerEnabled()) { if (isClientListenerEnabled()) {
// Start the port listener for clients // Start the port listener for clients
createClientListeners(); createClientListeners();
startClientListeners(localIPAddress); startClientListeners(localIPAddress);
} }
} }
public NioSocketAcceptor getSocketAcceptor() { public NioSocketAcceptor getSocketAcceptor() {
return socketAcceptor; return socketAcceptor;
} }
@Override @Override
public int getClientListenerPort() { public int getClientListenerPort() {
return JiveGlobals.getIntProperty(ConnectionSettings.Client.PORT, DEFAULT_PORT); return JiveGlobals.getIntProperty(ConnectionSettings.Client.PORT, DEFAULT_PORT);
} }
public NioSocketAcceptor getSSLSocketAcceptor() { public NioSocketAcceptor getSSLSocketAcceptor() {
return sslSocketAcceptor; return sslSocketAcceptor;
} }
@Override @Override
public void setClientSSLListenerPort(int port) { public void setClientSSLListenerPort(int port) {
if (port == getClientSSLListenerPort()) { if (port == getClientSSLListenerPort()) {
// Ignore new setting // Ignore new setting
return; return;
} }
JiveGlobals.setProperty(ConnectionSettings.Client.OLD_SSLPORT, String.valueOf(port)); JiveGlobals.setProperty(ConnectionSettings.Client.OLD_SSLPORT, String.valueOf(port));
// Stop the port listener for secured clients // Stop the port listener for secured clients
stopClientSSLListeners(); stopClientSSLListeners();
if (isClientSSLListenerEnabled()) { if (isClientSSLListenerEnabled()) {
// Start the port listener for secured clients // Start the port listener for secured clients
createClientSSLListeners(); createClientSSLListeners();
startClientSSLListeners(localIPAddress); startClientSSLListeners(localIPAddress);
} }
} }
@Override @Override
public int getClientSSLListenerPort() { public int getClientSSLListenerPort() {
return JiveGlobals.getIntProperty(ConnectionSettings.Client.OLD_SSLPORT, DEFAULT_SSL_PORT); return JiveGlobals.getIntProperty(ConnectionSettings.Client.OLD_SSLPORT, DEFAULT_SSL_PORT);
} }
@Override @Override
public void setComponentListenerPort(int port) { public void setComponentListenerPort(int port) {
if (port == getComponentListenerPort()) { if (port == getComponentListenerPort()) {
// Ignore new setting // Ignore new setting
return; return;
} }
JiveGlobals.setProperty(ConnectionSettings.Component.PORT, String.valueOf(port)); JiveGlobals.setProperty(ConnectionSettings.Component.PORT, String.valueOf(port));
// Stop the port listener for external components // Stop the port listener for external components
stopComponentListener(); stopComponentListener();
if (isComponentListenerEnabled()) { if (isComponentListenerEnabled()) {
// Start the port listener for external components // Start the port listener for external components
createComponentListener(); createComponentListener();
startComponentListener(); startComponentListener();
} }
} }
public NioSocketAcceptor getComponentAcceptor() { public NioSocketAcceptor getComponentAcceptor() {
return componentAcceptor; return componentAcceptor;
} }
@Override @Override
public int getComponentListenerPort() { public int getComponentListenerPort() {
return JiveGlobals.getIntProperty(ConnectionSettings.Component.PORT, DEFAULT_COMPONENT_PORT); return JiveGlobals.getIntProperty(ConnectionSettings.Component.PORT, DEFAULT_COMPONENT_PORT);
} }
@Override @Override
public void setServerListenerPort(int port) { public void setServerListenerPort(int port) {
if (port == getServerListenerPort()) { if (port == getServerListenerPort()) {
// Ignore new setting // Ignore new setting
return; return;
} }
JiveGlobals.setProperty(ConnectionSettings.Server.PORT, String.valueOf(port)); JiveGlobals.setProperty(ConnectionSettings.Server.PORT, String.valueOf(port));
// Stop the port listener for s2s communication // Stop the port listener for s2s communication
stopServerListener(); stopServerListener();
if (isServerListenerEnabled()) { if (isServerListenerEnabled()) {
// Start the port listener for s2s communication // Start the port listener for s2s communication
createServerListener(localIPAddress); createServerListener(localIPAddress);
startServerListener(); startServerListener();
} }
} }
@Override @Override
public int getServerListenerPort() { public int getServerListenerPort() {
return JiveGlobals.getIntProperty(ConnectionSettings.Server.PORT, DEFAULT_SERVER_PORT); return JiveGlobals.getIntProperty(ConnectionSettings.Server.PORT, DEFAULT_SERVER_PORT);
} }
public NioSocketAcceptor getMultiplexerSocketAcceptor() { public NioSocketAcceptor getMultiplexerSocketAcceptor() {
return multiplexerSocketAcceptor; return multiplexerSocketAcceptor;
} }
@Override @Override
public void setConnectionManagerListenerPort(int port) { public void setConnectionManagerListenerPort(int port) {
if (port == getConnectionManagerListenerPort()) { if (port == getConnectionManagerListenerPort()) {
// Ignore new setting // Ignore new setting
return; return;
} }
JiveGlobals.setProperty(ConnectionSettings.Multiplex.PORT, String.valueOf(port)); JiveGlobals.setProperty(ConnectionSettings.Multiplex.PORT, String.valueOf(port));
// Stop the port listener for connection managers // Stop the port listener for connection managers
stopConnectionManagerListener(); stopConnectionManagerListener();
if (isConnectionManagerListenerEnabled()) { if (isConnectionManagerListenerEnabled()) {
// Start the port listener for connection managers // Start the port listener for connection managers
createConnectionManagerListener(); createConnectionManagerListener();
startConnectionManagerListener(localIPAddress); startConnectionManagerListener(localIPAddress);
} }
} }
@Override @Override
public int getConnectionManagerListenerPort() { public int getConnectionManagerListenerPort() {
return JiveGlobals.getIntProperty(ConnectionSettings.Multiplex.PORT, DEFAULT_MULTIPLEX_PORT); return JiveGlobals.getIntProperty(ConnectionSettings.Multiplex.PORT, DEFAULT_MULTIPLEX_PORT);
} }
// ##################################################################### // #####################################################################
// Certificates events // Certificates events
// ##################################################################### // #####################################################################
@Override @Override
public void certificateCreated(KeyStore keyStore, String alias, X509Certificate cert) { public void certificateCreated(KeyStore keyStore, String alias, X509Certificate cert) {
restartClientSSLListeners(); restartClientSSLListeners();
} }
@Override @Override
public void certificateDeleted(KeyStore keyStore, String alias) { public void certificateDeleted(KeyStore keyStore, String alias) {
restartClientSSLListeners(); restartClientSSLListeners();
} }
@Override @Override
public void certificateSigned(KeyStore keyStore, String alias, List<X509Certificate> certificates) { public void certificateSigned(KeyStore keyStore, String alias, List<X509Certificate> certificates) {
restartClientSSLListeners(); restartClientSSLListeners();
} }
// ##################################################################### // #####################################################################
// Property events // Property events
// ##################################################################### // #####################################################################
@Override @Override
public void propertySet( String property, Map<String, Object> params ) { public void propertySet( String property, Map<String, Object> params ) {
processPropertyValueChange( property, params ); processPropertyValueChange( property, params );
} }
@Override @Override
public void propertyDeleted( String property, Map<String, Object> params ) { public void propertyDeleted( String property, Map<String, Object> params ) {
processPropertyValueChange( property, params ); processPropertyValueChange( property, params );
} }
@Override @Override
public void xmlPropertySet( String property, Map<String, Object> params ) { public void xmlPropertySet( String property, Map<String, Object> params ) {
processPropertyValueChange( property, params ); processPropertyValueChange( property, params );
} }
@Override @Override
public void xmlPropertyDeleted( String property, Map<String, Object> params ) { public void xmlPropertyDeleted( String property, Map<String, Object> params ) {
processPropertyValueChange( property, params ); processPropertyValueChange( property, params );
} }
private void processPropertyValueChange( String property, Map<String, Object> params ) { private void processPropertyValueChange( String property, Map<String, Object> params ) {
Log.debug( "Processing property value change for '"+property +"'." ); Log.debug( "Processing property value change for '"+property +"'." );
if ("xmpp.client.cert.policy".equalsIgnoreCase( property )) { if ("xmpp.client.cert.policy".equalsIgnoreCase( property )) {
restartClientSSLListeners(); restartClientSSLListeners();
} }
} }
private NioSocketAcceptor buildSocketAcceptor(String name) { private NioSocketAcceptor buildSocketAcceptor(String name) {
NioSocketAcceptor socketAcceptor; NioSocketAcceptor socketAcceptor;
// Create SocketAcceptor with correct number of processors // Create SocketAcceptor with correct number of processors
int processorCount = JiveGlobals.getIntProperty("xmpp.processor.count", Runtime.getRuntime().availableProcessors()); int processorCount = JiveGlobals.getIntProperty("xmpp.processor.count", Runtime.getRuntime().availableProcessors());
socketAcceptor = new NioSocketAcceptor(processorCount); socketAcceptor = new NioSocketAcceptor(processorCount);
// Set that it will be possible to bind a socket if there is a connection in the timeout state // Set that it will be possible to bind a socket if there is a connection in the timeout state
socketAcceptor.setReuseAddress(true); socketAcceptor.setReuseAddress(true);
// Set the listen backlog (queue) length. Default is 50. // Set the listen backlog (queue) length. Default is 50.
socketAcceptor.setBacklog(JiveGlobals.getIntProperty("xmpp.socket.backlog", 50)); socketAcceptor.setBacklog(JiveGlobals.getIntProperty("xmpp.socket.backlog", 50));
// Set default (low level) settings for new socket connections // Set default (low level) settings for new socket connections
SocketSessionConfig socketSessionConfig = socketAcceptor.getSessionConfig(); SocketSessionConfig socketSessionConfig = socketAcceptor.getSessionConfig();
//socketSessionConfig.setKeepAlive(); //socketSessionConfig.setKeepAlive();
int receiveBuffer = JiveGlobals.getIntProperty("xmpp.socket.buffer.receive", -1); int receiveBuffer = JiveGlobals.getIntProperty("xmpp.socket.buffer.receive", -1);
if (receiveBuffer > 0 ) { if (receiveBuffer > 0 ) {
socketSessionConfig.setReceiveBufferSize(receiveBuffer); socketSessionConfig.setReceiveBufferSize(receiveBuffer);
} }
int sendBuffer = JiveGlobals.getIntProperty("xmpp.socket.buffer.send", -1); int sendBuffer = JiveGlobals.getIntProperty("xmpp.socket.buffer.send", -1);
if (sendBuffer > 0 ) { if (sendBuffer > 0 ) {
socketSessionConfig.setSendBufferSize(sendBuffer); socketSessionConfig.setSendBufferSize(sendBuffer);
} }
int linger = JiveGlobals.getIntProperty("xmpp.socket.linger", -1); int linger = JiveGlobals.getIntProperty("xmpp.socket.linger", -1);
if (linger > 0 ) { if (linger > 0 ) {
socketSessionConfig.setSoLinger(linger); socketSessionConfig.setSoLinger(linger);
} }
socketSessionConfig.setTcpNoDelay( socketSessionConfig.setTcpNoDelay(
JiveGlobals.getBooleanProperty("xmpp.socket.tcp-nodelay", socketSessionConfig.isTcpNoDelay())); JiveGlobals.getBooleanProperty("xmpp.socket.tcp-nodelay", socketSessionConfig.isTcpNoDelay()));
if (JMXManager.isEnabled()) { if (JMXManager.isEnabled()) {
configureJMX(socketAcceptor, name); configureJMX(socketAcceptor, name);
} }
return socketAcceptor; return socketAcceptor;
} }
private void configureJMX(NioSocketAcceptor acceptor, String suffix) { private void configureJMX(NioSocketAcceptor acceptor, String suffix) {
final String prefix = IoServiceMBean.class.getPackage().getName(); final String prefix = IoServiceMBean.class.getPackage().getName();
// monitor the IoService // monitor the IoService
try { try {
IoServiceMBean mbean = new IoServiceMBean(acceptor); IoServiceMBean mbean = new IoServiceMBean(acceptor);
MBeanServer mbs = ManagementFactory.getPlatformMBeanServer(); MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
ObjectName name = new ObjectName(prefix + ":type=SocketAcceptor,name=" + suffix); ObjectName name = new ObjectName(prefix + ":type=SocketAcceptor,name=" + suffix);
mbs.registerMBean( mbean, name ); mbs.registerMBean( mbean, name );
// mbean.startCollectingStats(JiveGlobals.getIntProperty("xmpp.socket.jmx.interval", 60000)); // mbean.startCollectingStats(JiveGlobals.getIntProperty("xmpp.socket.jmx.interval", 60000));
} catch (JMException ex) { } catch (JMException ex) {
Log.warn("Failed to register MINA acceptor mbean (JMX): " + ex); Log.warn("Failed to register MINA acceptor mbean (JMX): " + ex);
} }
// optionally register IoSession mbeans (one per session) // optionally register IoSession mbeans (one per session)
if (JiveGlobals.getBooleanProperty("xmpp.socket.jmx.sessions", false)) { if (JiveGlobals.getBooleanProperty("xmpp.socket.jmx.sessions", false)) {
acceptor.addListener(new IoServiceListener() { acceptor.addListener(new IoServiceListener() {
@Override @Override
public void sessionCreated(IoSession session) { public void sessionCreated(IoSession session) {
try { try {
IoSessionMBean mbean = new IoSessionMBean(session); IoSessionMBean mbean = new IoSessionMBean(session);
MBeanServer mbs = ManagementFactory.getPlatformMBeanServer(); MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
ObjectName name = new ObjectName(prefix + ":type=IoSession,name=" + ObjectName name = new ObjectName(prefix + ":type=IoSession,name=" +
session.getRemoteAddress().toString().replace(':', '/')); session.getRemoteAddress().toString().replace(':', '/'));
mbs.registerMBean(mbean, name); mbs.registerMBean(mbean, name);
} catch(JMException ex) { } catch(JMException ex) {
Log.warn("Failed to register MINA session mbean (JMX): " + ex); Log.warn("Failed to register MINA session mbean (JMX): " + ex);
} }
} }
@Override @Override
public void sessionDestroyed(IoSession session) { public void sessionDestroyed(IoSession session) {
try { try {
ObjectName name = new ObjectName(prefix + ":type=IoSession,name=" + ObjectName name = new ObjectName(prefix + ":type=IoSession,name=" +
session.getRemoteAddress().toString().replace(':', '/')); session.getRemoteAddress().toString().replace(':', '/'));
ManagementFactory.getPlatformMBeanServer().unregisterMBean(name); ManagementFactory.getPlatformMBeanServer().unregisterMBean(name);
} catch(JMException ex) { } catch(JMException ex) {
Log.warn("Failed to unregister MINA session mbean (JMX): " + ex); Log.warn("Failed to unregister MINA session mbean (JMX): " + ex);
} }
} }
@Override @Override
public void serviceActivated(IoService service) throws Exception { } public void serviceActivated(IoService service) throws Exception { }
@Override @Override
public void serviceDeactivated(IoService service) throws Exception { } public void serviceDeactivated(IoService service) throws Exception { }
@Override @Override
public void serviceIdle(IoService service, IdleStatus idleStatus) throws Exception { } public void serviceIdle(IoService service, IdleStatus idleStatus) throws Exception { }
}); });
} }
} }
private int getCorePoolSize(int maxPoolSize) { private int getCorePoolSize(int maxPoolSize) {
return (maxPoolSize/4)+1; return (maxPoolSize/4)+1;
} }
// ##################################################################### // #####################################################################
// Module management // Module management
// ##################################################################### // #####################################################################
@Override @Override
public void start() { public void start() {
super.start(); super.start();
createListeners(); createListeners();
startListeners(); startListeners();
SocketSendingTracker.getInstance().start(); SocketSendingTracker.getInstance().start();
CertificateManager.addListener(this); CertificateManager.addListener(this);
} }
@Override @Override
public void stop() { public void stop() {
super.stop(); super.stop();
stopClientListeners(); stopClientListeners();
stopClientSSLListeners(); stopClientSSLListeners();
stopComponentListener(); stopComponentListener();
stopConnectionManagerListener(); stopConnectionManagerListener();
stopServerListener(); stopServerListener();
HttpBindManager.getInstance().stop(); HttpBindManager.getInstance().stop();
SocketSendingTracker.getInstance().shutdown(); SocketSendingTracker.getInstance().shutdown();
CertificateManager.removeListener(this); CertificateManager.removeListener(this);
serverName = null; serverName = null;
} }
private static class DelegatingThreadFactory implements ThreadFactory { private static class DelegatingThreadFactory implements ThreadFactory {
private final AtomicInteger threadId; private final AtomicInteger threadId;
private final ThreadFactory originalThreadFactory; private final ThreadFactory originalThreadFactory;
private String threadNamePrefix; private String threadNamePrefix;
public DelegatingThreadFactory(String threadNamePrefix, ThreadFactory originalThreadFactory) { public DelegatingThreadFactory(String threadNamePrefix, ThreadFactory originalThreadFactory) {
this.originalThreadFactory = originalThreadFactory; this.originalThreadFactory = originalThreadFactory;
threadId = new AtomicInteger(0); threadId = new AtomicInteger(0);
this.threadNamePrefix = threadNamePrefix; this.threadNamePrefix = threadNamePrefix;
} }
@Override @Override
public Thread newThread(Runnable runnable) public Thread newThread(Runnable runnable)
{ {
Thread t = originalThreadFactory.newThread(runnable); Thread t = originalThreadFactory.newThread(runnable);
t.setName(threadNamePrefix + threadId.incrementAndGet()); t.setName(threadNamePrefix + threadId.incrementAndGet());
t.setDaemon(true); t.setDaemon(true);
return t; return t;
} }
} }
} }
...@@ -40,6 +40,7 @@ import java.security.cert.X509Certificate; ...@@ -40,6 +40,7 @@ import java.security.cert.X509Certificate;
import java.util.Comparator; import java.util.Comparator;
import org.jivesoftware.openfire.net.SSLConfig;
import org.jivesoftware.openfire.session.ConnectionSettings; import org.jivesoftware.openfire.session.ConnectionSettings;
/** /**
...@@ -57,12 +58,11 @@ public class SimpleSSLSocketFactory extends SSLSocketFactory implements Comparat ...@@ -57,12 +58,11 @@ public class SimpleSSLSocketFactory extends SSLSocketFactory implements Comparat
public SimpleSSLSocketFactory() { public SimpleSSLSocketFactory() {
try { try {
String algorithm = JiveGlobals.getProperty( ConnectionSettings.Client.TLS_ALGORITHM, "TLS" ); final SSLContext sslContext = SSLConfig.getSSLContext();
SSLContext sslcontent = SSLContext.getInstance(algorithm); sslContext.init(null, // KeyManager not required
sslcontent.init(null, // KeyManager not required
new TrustManager[] { new DummyTrustManager() }, new TrustManager[] { new DummyTrustManager() },
new java.security.SecureRandom()); new java.security.SecureRandom());
factory = sslcontent.getSocketFactory(); factory = sslContext.getSocketFactory();
} }
catch (NoSuchAlgorithmException | KeyManagementException e) { catch (NoSuchAlgorithmException | KeyManagementException e) {
Log.error(e.getMessage(), e); Log.error(e.getMessage(), e);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment