Commit 59f5c85d authored by Guus der Kinderen's avatar Guus der Kinderen Committed by daryl herzmann

OF-1299 / OF-1300: Fixes for XML Debugger plugin. (#759)

* OF-1299 / OF-1300: Fixes for XML Debugger plugin.

Causes the plugin to print the remote address, as well as less 'garbage' (compressed and/or encrypted data).
parent 88f85551
......@@ -43,10 +43,18 @@
<h1>
XML Debugger Plugin Changelog
</h1>
<p><b>1.6.0</b> -- June 20, 2016</p>
<li>[<a href='http://issues.igniterealtime.org/browse/OF-1152'>OF-1152</a>] - Ensure that the plugin prints raw XML.</li>
<li>Requires Openfire 4</li>
<p><b>1.7.0</b> -- March 6, 2017</p>
<ul>
<li>[<a href='http://issues.igniterealtime.org/browse/OF-1299'>OF-1299</a>] - Debugger plugin should not print encrypted or compressed data.</li>
<li>[<a href='http://issues.igniterealtime.org/browse/OF-1300'>OF-1300</a>] - Debugger plugin should display remote address.</li>
</ul>
<p><b>1.6.0</b> -- June 20, 2016</p>
<ul>
<li>[<a href='http://issues.igniterealtime.org/browse/OF-1152'>OF-1152</a>] - Ensure that the plugin prints raw XML.</li>
<li>Requires Openfire 4</li>
</ul>
<p><b>1.5.0</b> -- October 12, 2015</p>
<ul>
......
......@@ -8,8 +8,8 @@
<name>Debugger Plugin</name>
<description>Prints XML traffic to the stdout (raw and interpreted XML)</description>
<author>Jive Software</author>
<version>1.6.0</version>
<date>06/20/2016</date>
<version>1.7.0</version>
<date>03/06/2017</date>
<minServerVersion>4.0.0</minServerVersion>
<adminconsole>
......
......@@ -19,6 +19,10 @@ package org.jivesoftware.openfire.plugin;
import java.io.File;
import java.util.Map;
import org.apache.mina.core.filterchain.DefaultIoFilterChainBuilder;
import org.apache.mina.core.filterchain.IoFilter;
import org.apache.mina.core.filterchain.IoFilterChain;
import org.apache.mina.filter.compression.CompressionFilter;
import org.apache.mina.transport.socket.SocketAcceptor;
import org.jivesoftware.openfire.XMPPServer;
import org.jivesoftware.openfire.container.Plugin;
......@@ -29,6 +33,12 @@ import org.jivesoftware.openfire.spi.ConnectionManagerImpl;
import org.jivesoftware.util.JiveGlobals;
import org.jivesoftware.util.PropertyEventDispatcher;
import org.jivesoftware.util.PropertyEventListener;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import static org.jivesoftware.openfire.spi.ConnectionManagerImpl.COMPRESSION_FILTER_NAME;
import static org.jivesoftware.openfire.spi.ConnectionManagerImpl.EXECUTOR_FILTER_NAME;
import static org.jivesoftware.openfire.spi.ConnectionManagerImpl.TLS_FILTER_NAME;
/**
* Debugger plugin that prints XML traffic to stdout. By default it will only print
......@@ -39,6 +49,9 @@ import org.jivesoftware.util.PropertyEventListener;
* @author Gaston Dombiak
*/
public class DebuggerPlugin implements Plugin, PropertyEventListener {
public static final Logger Log = LoggerFactory.getLogger( DebuggerPlugin.class );
private RawPrintFilter defaultPortFilter;
private RawPrintFilter oldPortFilter;
private RawPrintFilter componentPortFilter;
......@@ -61,31 +74,65 @@ public class DebuggerPlugin implements Plugin, PropertyEventListener {
}
}
private void addInterceptors() {
// Add filter to filter chain builder
ConnectionManagerImpl connManager = (ConnectionManagerImpl) XMPPServer.getInstance().getConnectionManager();
defaultPortFilter = new RawPrintFilter("C2S");
SocketAcceptor socketAcceptor = connManager.getSocketAcceptor();
if (socketAcceptor != null) {
socketAcceptor.getFilterChain().addFirst("rawDebugger", defaultPortFilter);
protected void addFilterToChain( final SocketAcceptor acceptor, final String filterName, final IoFilter filter )
{
if ( acceptor == null )
{
Log.debug( "Not adding filter '{}' to acceptor that is null.", filterName );
return;
}
oldPortFilter = new RawPrintFilter("SSL");
SocketAcceptor sslAcceptor = connManager.getSSLSocketAcceptor();
if (sslAcceptor != null) {
sslAcceptor.getFilterChain().addFirst("rawDebugger", oldPortFilter);
final DefaultIoFilterChainBuilder chain = acceptor.getFilterChain();
if ( chain.contains( COMPRESSION_FILTER_NAME ) )
{
Log.debug( "Adding filter '{}' as the first filter after the compression filter in acceptor {}", filterName, acceptor );
chain.addAfter( COMPRESSION_FILTER_NAME, filterName, filter );
}
else if ( chain.contains( TLS_FILTER_NAME ) )
{
Log.debug( "Adding filter '{}' as the first filter after the TLS filter in acceptor {}", filterName, acceptor );
chain.addAfter( TLS_FILTER_NAME, filterName, filter );
}
else
{
Log.debug( "Adding filter '{}' as the last filter in acceptor {}", filterName, acceptor );
chain.addLast( filterName, filter );
}
}
componentPortFilter = new RawPrintFilter("ExComp");
SocketAcceptor componentAcceptor = connManager.getComponentAcceptor();
if (componentAcceptor != null) {
componentAcceptor.getFilterChain().addFirst("rawDebugger", componentPortFilter);
protected void removeFilterFromChain( final SocketAcceptor acceptor, final String filterName )
{
if ( acceptor == null )
{
Log.debug( "Not removing filter '{}' from acceptor that is null.", filterName );
return;
}
multiplexerPortFilter = new RawPrintFilter("CM");
SocketAcceptor multiplexerAcceptor = connManager.getMultiplexerSocketAcceptor();
if (multiplexerAcceptor != null) {
multiplexerAcceptor.getFilterChain().addFirst("rawDebugger", multiplexerPortFilter);
if ( acceptor.getFilterChain().contains( filterName ) )
{
Log.debug( "Removing filter '{}' from acceptor {}", filterName, acceptor );
acceptor.getFilterChain().remove( filterName );
}
else
{
Log.debug( "Unable to remove non-existing filter '{}' from acceptor {}", filterName, acceptor );
}
}
private void addInterceptors()
{
defaultPortFilter = new RawPrintFilter("C2S");
oldPortFilter = new RawPrintFilter("SSL");
componentPortFilter = new RawPrintFilter("ExComp");
multiplexerPortFilter = new RawPrintFilter("CM");
// Add filter to filter chain builder
final ConnectionManagerImpl connManager = (ConnectionManagerImpl) XMPPServer.getInstance().getConnectionManager();
addFilterToChain( connManager.getSocketAcceptor(), RawPrintFilter.FILTER_NAME, defaultPortFilter );
addFilterToChain( connManager.getSSLSocketAcceptor(), RawPrintFilter.FILTER_NAME, oldPortFilter );
addFilterToChain( connManager.getComponentAcceptor(), RawPrintFilter.FILTER_NAME, componentPortFilter );
addFilterToChain( connManager.getMultiplexerSocketAcceptor(), RawPrintFilter.FILTER_NAME, multiplexerPortFilter );
interpretedPrinter = new InterpretedXMLPrinter();
if (JiveGlobals.getBooleanProperty("plugin.debugger.interpretedAllowed")) {
......@@ -101,22 +148,11 @@ public class DebuggerPlugin implements Plugin, PropertyEventListener {
PropertyEventDispatcher.removeListener(this);
// Remove filter from filter chain builder
ConnectionManagerImpl connManager = (ConnectionManagerImpl) XMPPServer.getInstance().getConnectionManager();
if (connManager.getSocketAcceptor() != null &&
connManager.getSocketAcceptor().getFilterChain().contains("rawDebugger")) {
connManager.getSocketAcceptor().getFilterChain().remove("rawDebugger");
}
if (connManager.getSSLSocketAcceptor() != null &&
connManager.getSSLSocketAcceptor().getFilterChain().contains("rawDebugger")) {
connManager.getSSLSocketAcceptor().getFilterChain().remove("rawDebugger");
}
if (connManager.getComponentAcceptor() != null &&
connManager.getComponentAcceptor().getFilterChain().contains("rawDebugger")) {
connManager.getComponentAcceptor().getFilterChain().remove("rawDebugger");
}
if (connManager.getMultiplexerSocketAcceptor() != null &&
connManager.getMultiplexerSocketAcceptor().getFilterChain().contains("rawDebugger")) {
connManager.getMultiplexerSocketAcceptor().getFilterChain().remove("rawDebugger");
}
removeFilterFromChain( connManager.getSocketAcceptor(), RawPrintFilter.FILTER_NAME );
removeFilterFromChain( connManager.getSSLSocketAcceptor(), RawPrintFilter.FILTER_NAME );
removeFilterFromChain( connManager.getComponentAcceptor(), RawPrintFilter.FILTER_NAME );
removeFilterFromChain( connManager.getMultiplexerSocketAcceptor(), RawPrintFilter.FILTER_NAME );
// Remove the filters from existing sessions
if (defaultPortFilter != null) {
defaultPortFilter.shutdown();
......
......@@ -35,6 +35,9 @@ import org.jivesoftware.util.JiveGlobals;
* @author Gaston Dombiak
*/
public class RawPrintFilter extends IoFilterAdapter {
public static final String FILTER_NAME = "rawDebugger";
private boolean enabled = true;
private String prefix;
private Collection<IoSession> sessions = new ConcurrentLinkedQueue<IoSession>();
......@@ -66,7 +69,7 @@ public class RawPrintFilter extends IoFilterAdapter {
}
private String messagePrefix(final IoSession session, final String messageType) {
return prefix + " - " + messageType + String.format(" - (%1$11s)", session.hashCode());
return String.format("%1$s %2$15s - %3$s - (%4$11s)", prefix, session.getRemoteAddress(), messageType, session.hashCode());
}
@Override
......
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