use of org.jivesoftware.openfire.spi.ConnectionManagerImpl in project Openfire by igniterealtime.
the class JmxWebPlugin method initializePlugin.
public void initializePlugin(PluginManager manager, File pluginDirectory) {
Log.info("[" + NAME + "] initialize " + NAME + " plugin resources");
try {
openfire = new Openfire();
openfire.start();
JmxHelper.register(openfire, OBJECTNAME_OPENFIRE);
Log.info("[" + NAME + "] .. started openfire server detector.");
} catch (Exception e) {
Log.debug("cannot start openfire server detector: " + e.getMessage(), e);
}
try {
packetCounter = new PacketCounter();
packetCounter.start();
JmxHelper.register(packetCounter, OBJECTNAME_PACKET_COUNTER);
Log.info("[" + NAME + "] .. started stanza counter.");
} catch (Exception e) {
Log.debug("cannot start stanza counter: " + e.getMessage(), e);
}
try {
client = new CoreThreadPool(((ConnectionManagerImpl) XMPPServer.getInstance().getConnectionManager()).getSocketAcceptor());
client.start();
JmxHelper.register(client, OBJECTNAME_CORE_CLIENT_THREADPOOL);
Log.info("[" + NAME + "] .. started client thread pool monitor.");
} catch (Exception e) {
Log.debug("cannot start client thread pool monitor: " + e.getMessage(), e);
}
try {
database = new DatabasePool();
database.start();
JmxHelper.register(database, OBJECTNAME_DATABASEPOOL);
Log.info("[" + NAME + "] .. started database pool monitor.");
} catch (Exception e) {
Log.debug("cannot start database pool monitor: " + e.getMessage(), e);
}
try {
ContextHandlerCollection contexts = HttpBindManager.getInstance().getContexts();
try {
Log.info("[" + NAME + "] starting jolokia");
WebAppContext context = new WebAppContext(contexts, pluginDirectory.getPath(), "/jolokia");
final List<ContainerInitializer> initializers = new ArrayList<>();
initializers.add(new ContainerInitializer(new JasperInitializer(), null));
context.setAttribute("org.eclipse.jetty.containerInitializers", initializers);
context.setAttribute(InstanceManager.class.getName(), new SimpleInstanceManager());
context.setWelcomeFiles(new String[] { "index.html" });
Log.info("[" + NAME + "] starting hawtio");
WebAppContext context2 = new WebAppContext(contexts, pluginDirectory.getPath() + "/hawtio", "/hawtio");
final List<ContainerInitializer> initializers2 = new ArrayList<>();
initializers2.add(new ContainerInitializer(new JasperInitializer(), null));
context2.setAttribute("org.eclipse.jetty.containerInitializers", initializers2);
context2.setAttribute(InstanceManager.class.getName(), new SimpleInstanceManager());
context2.setWelcomeFiles(new String[] { "index.html" });
if (JiveGlobals.getBooleanProperty("xmpp.jmx.secure", true)) {
SecurityHandler securityHandler = basicAuth("jmxweb");
if (securityHandler != null)
context.setSecurityHandler(securityHandler);
SecurityHandler securityHandler2 = basicAuth("jmxweb");
if (securityHandler2 != null)
context2.setSecurityHandler(securityHandler2);
}
} catch (Exception e) {
Log.error("An error has occurred", e);
}
} catch (Exception e) {
Log.error("Error initializing JmxWeb Plugin", e);
}
if (JiveGlobals.getBooleanProperty("jmxweb.email.monitoring", true)) {
Log.info("[" + NAME + "] starting email monitoring");
emailScheduler = new EmailScheduler();
emailScheduler.startMonitoring();
Log.info("[" + NAME + "] started monitoring");
}
}
use of org.jivesoftware.openfire.spi.ConnectionManagerImpl in project Openfire by igniterealtime.
the class WebSocketConnection method getConfiguration.
@Override
public ConnectionConfiguration getConfiguration() {
if (configuration == null) {
final ConnectionManagerImpl connectionManager = ((ConnectionManagerImpl) XMPPServer.getInstance().getConnectionManager());
configuration = connectionManager.getListener(connectionType, true).generateConnectionConfiguration();
}
return configuration;
}
use of org.jivesoftware.openfire.spi.ConnectionManagerImpl in project Openfire by igniterealtime.
the class CertificateStoreManager method replaceTrustStore.
public void replaceTrustStore(ConnectionType type, CertificateStoreConfiguration configuration, boolean createIfAbsent) throws CertificateStoreConfigException {
if (type == null) {
throw new IllegalArgumentException("Argument 'type' cannot be null.");
}
if (configuration == null) {
throw new IllegalArgumentException("Argument 'configuration' cannot be null.");
}
// can be null if persisted properties are invalid
final CertificateStoreConfiguration oldConfig = typeToTrustStore.get(type);
if (oldConfig == null || !oldConfig.equals(configuration)) {
// If the new store is not already being used by any other type, it'll need to be registered.
if (!trustStores.containsKey(configuration)) {
// This constructor can throw an exception. If it does, the state of the manager should not have already changed.
final TrustStore store = new TrustStore(configuration, createIfAbsent);
trustStores.put(configuration, store);
storeWatcher.watch(store);
}
typeToTrustStore.put(type, configuration);
// If the old store is not used by any other type, it can be shut down.
if (oldConfig != null && !typeToTrustStore.containsValue(oldConfig)) {
final TrustStore store = trustStores.remove(oldConfig);
if (store != null) {
storeWatcher.unwatch(store);
}
}
// Update all connection listeners that were using the old configuration.
final ConnectionManagerImpl connectionManager = ((ConnectionManagerImpl) XMPPServer.getInstance().getConnectionManager());
for (ConnectionListener connectionListener : connectionManager.getListeners(type)) {
try {
connectionListener.setTrustStoreConfiguration(configuration);
} catch (RuntimeException e) {
Log.warn("An exception occurred while trying to update the trust store configuration for connection type '" + type + "'", e);
}
}
}
// Always store the new configuration in properties, to make sure that we override a potential fallback.
// FIXME ensure that this is relative to Openfire home!
JiveGlobals.setProperty(type.getPrefix() + "truststore", configuration.getFile().getPath());
JiveGlobals.setProperty(type.getPrefix() + "trustpass", new String(configuration.getPassword()), true);
}
use of org.jivesoftware.openfire.spi.ConnectionManagerImpl in project Openfire by igniterealtime.
the class CertificateStoreManager method replaceIdentityStore.
public void replaceIdentityStore(ConnectionType type, CertificateStoreConfiguration configuration, boolean createIfAbsent) throws CertificateStoreConfigException {
if (type == null) {
throw new IllegalArgumentException("Argument 'type' cannot be null.");
}
if (configuration == null) {
throw new IllegalArgumentException("Argument 'configuration' cannot be null.");
}
// can be null if persisted properties are invalid
final CertificateStoreConfiguration oldConfig = typeToIdentityStore.get(type);
if (oldConfig == null || !oldConfig.equals(configuration)) {
// If the new store is not already being used by any other type, it'll need to be registered.
if (!identityStores.containsKey(configuration)) {
// This constructor can throw an exception. If it does, the state of the manager should not have already changed.
final IdentityStore store = new IdentityStore(configuration, createIfAbsent);
identityStores.put(configuration, store);
storeWatcher.watch(store);
}
typeToIdentityStore.put(type, configuration);
// If the old store is not used by any other type, it can be shut down.
if (oldConfig != null && !typeToIdentityStore.containsValue(oldConfig)) {
final IdentityStore store = identityStores.remove(oldConfig);
if (store != null) {
storeWatcher.unwatch(store);
}
}
// Update all connection listeners that were using the old configuration.
final ConnectionManagerImpl connectionManager = ((ConnectionManagerImpl) XMPPServer.getInstance().getConnectionManager());
for (ConnectionListener connectionListener : connectionManager.getListeners(type)) {
try {
connectionListener.setIdentityStoreConfiguration(configuration);
} catch (RuntimeException e) {
Log.warn("An exception occurred while trying to update the identity store configuration for connection type '" + type + "'", e);
}
}
}
// Always store the new configuration in properties, to make sure that we override a potential fallback.
// FIXME ensure that this is relative to Openfire home!
JiveGlobals.setProperty(type.getPrefix() + "keystore", configuration.getFile().getPath());
JiveGlobals.setProperty(type.getPrefix() + "keypass", new String(configuration.getPassword()), true);
}
use of org.jivesoftware.openfire.spi.ConnectionManagerImpl in project Openfire by igniterealtime.
the class ServerDialback method sendVerifyKey.
private VerifyResult sendVerifyKey(String key, StreamID streamID, String recipient, String remoteDomain, Writer writer, XMPPPacketReader reader, Socket socket, boolean skipTLS, boolean directTLS) throws IOException, XmlPullParserException, RemoteConnectionFailedException {
final Logger log = LoggerFactory.getLogger(Log.getName() + "[Acting as Receiving Server: Verify key with AS: " + remoteDomain + " for OS: " + recipient + " (id " + streamID + ")]");
VerifyResult result = VerifyResult.error;
final ConnectionManagerImpl connectionManager = ((ConnectionManagerImpl) XMPPServer.getInstance().getConnectionManager());
final TLSStreamHandler tlsStreamHandler = new TLSStreamHandler(socket, connectionManager.getListener(ConnectionType.SOCKET_S2S, directTLS).generateConnectionConfiguration(), true);
if (directTLS) {
// Start handshake
log.debug("Starting Direct TLS handshake.");
tlsStreamHandler.start();
// Use new wrapped writers
writer = new BufferedWriter(new OutputStreamWriter(tlsStreamHandler.getOutputStream(), StandardCharsets.UTF_8));
reader.getXPPParser().setInput(new InputStreamReader(tlsStreamHandler.getInputStream(), StandardCharsets.UTF_8));
}
log.debug("Send the Authoritative Server a stream header and wait for answer.");
StringBuilder stream = new StringBuilder();
stream.append("<stream:stream");
stream.append(" xmlns:stream=\"http://etherx.jabber.org/streams\"");
stream.append(" xmlns=\"jabber:server\"");
stream.append(" xmlns:db=\"jabber:server:dialback\"");
stream.append(" to=\"");
stream.append(remoteDomain);
stream.append("\"");
stream.append(" from=\"");
stream.append(recipient);
stream.append("\"");
stream.append(" version=\"1.0\">");
writer.write(stream.toString());
writer.flush();
// Get the answer from the Authoritative Server
XmlPullParser xpp = reader.getXPPParser();
for (int eventType = xpp.getEventType(); eventType != XmlPullParser.START_TAG; ) {
eventType = xpp.next();
}
// TODO there's code duplication here with LocalOutgoingServerSession.
log.debug("Got a response.");
if ((xpp.getAttributeValue("", "version") != null) && (xpp.getAttributeValue("", "version").equals("1.0"))) {
log.debug("The remote server is XMPP 1.0 compliant (or at least reports to be).");
Document doc;
try {
doc = reader.parseDocument();
} catch (DocumentException e) {
log.warn("Unable to verify key: XML Error!", e);
// Close the stream
writer.write("</stream:stream>");
writer.flush();
return VerifyResult.error;
}
Element features = doc.getRootElement();
Element starttls = features.element("starttls");
if (!directTLS && !skipTLS && starttls != null) {
writer.write("<starttls xmlns='urn:ietf:params:xml:ns:xmpp-tls'/>");
writer.flush();
try {
doc = reader.parseDocument();
} catch (DocumentException e) {
log.warn("Unable to verify key: XML Error!", e);
// Close the stream
writer.write("</stream:stream>");
writer.flush();
return VerifyResult.error;
}
if (!doc.getRootElement().getName().equals("proceed")) {
log.warn("Unable to verify key: Got {} instead of proceed for starttls", doc.getRootElement().getName());
log.debug("Like this: {}", doc.asXML());
// Close the stream
writer.write("</stream:stream>");
writer.flush();
return VerifyResult.error;
}
log.debug("Negotiating StartTLS with AS... ");
// Start handshake
tlsStreamHandler.start();
// Use new wrapped writers
writer = new BufferedWriter(new OutputStreamWriter(tlsStreamHandler.getOutputStream(), StandardCharsets.UTF_8));
reader.getXPPParser().setInput(new InputStreamReader(tlsStreamHandler.getInputStream(), StandardCharsets.UTF_8));
log.debug("Successfully negotiated StartTLS with AS... ");
// / Recurses!
return sendVerifyKey(key, streamID, recipient, remoteDomain, writer, reader, socket, skipTLS, directTLS);
}
}
if ("jabber:server:dialback".equals(xpp.getNamespace("db"))) {
log.debug("Request for verification of the key and wait for response");
StringBuilder sb = new StringBuilder();
sb.append("<db:verify");
sb.append(" from=\"").append(recipient).append("\"");
sb.append(" to=\"").append(remoteDomain).append("\"");
sb.append(" id=\"").append(streamID.getID()).append("\">");
sb.append(key);
sb.append("</db:verify>");
writer.write(sb.toString());
writer.flush();
try {
Element doc = reader.parseDocument().getRootElement();
if ("db".equals(doc.getNamespacePrefix()) && "verify".equals(doc.getName())) {
if (doc.attributeValue("id") == null || !streamID.equals(BasicStreamIDFactory.createStreamID(doc.attributeValue("id")))) {
// Include the invalid-id stream error condition in the response
writer.write(new StreamError(StreamError.Condition.invalid_id).toXML());
writer.write("</stream:stream>");
writer.flush();
// condition is sent to the Originating Server
throw new RemoteConnectionFailedException("Invalid ID");
} else if (isHostUnknown(doc.attributeValue("to"))) {
// Include the host-unknown stream error condition in the response
writer.write(new StreamError(StreamError.Condition.host_unknown).toXML());
writer.write("</stream:stream>");
writer.flush();
// condition is sent to the Originating Server
throw new RemoteConnectionFailedException("Host unknown");
} else if (!remoteDomain.equals(doc.attributeValue("from"))) {
// Include the invalid-from stream error condition in the response
writer.write(new StreamError(StreamError.Condition.invalid_from).toXML());
writer.write("</stream:stream>");
writer.flush();
// condition is sent to the Originating Server
throw new RemoteConnectionFailedException("Invalid From");
} else if ("valid".equals(doc.attributeValue("type"))) {
log.debug("Key was VERIFIED by the Authoritative Server.");
result = VerifyResult.valid;
} else if ("invalid".equals(doc.attributeValue("type"))) {
log.debug("Key was NOT VERIFIED by the Authoritative Server.");
result = VerifyResult.invalid;
} else {
log.debug("Key was ERRORED by the Authoritative Server.");
result = VerifyResult.error;
}
} else {
log.debug("db:verify answer was: " + doc.asXML());
}
} catch (DocumentException | RuntimeException e) {
log.error("An error occurred while connecting to the Authoritative Server: ", e);
// Thrown an error so <remote-connection-failed/> stream error condition is
// sent to the Originating Server
writer.write("</stream:stream>");
writer.flush();
throw new RemoteConnectionFailedException("Error connecting to the Authoritative Server");
}
} else {
// Include the invalid-namespace stream error condition in the response
writer.write(new StreamError(StreamError.Condition.invalid_namespace).toXML());
writer.write("</stream:stream>");
writer.flush();
// sent to the Originating Server
throw new RemoteConnectionFailedException("Invalid namespace");
}
writer.write("</stream:stream>");
writer.flush();
return result;
}
Aggregations