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 @@ ...@@ -43,10 +43,18 @@
<h1> <h1>
XML Debugger Plugin Changelog XML Debugger Plugin Changelog
</h1> </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> <p><b>1.5.0</b> -- October 12, 2015</p>
<ul> <ul>
......
...@@ -8,8 +8,8 @@ ...@@ -8,8 +8,8 @@
<name>Debugger Plugin</name> <name>Debugger Plugin</name>
<description>Prints XML traffic to the stdout (raw and interpreted XML)</description> <description>Prints XML traffic to the stdout (raw and interpreted XML)</description>
<author>Jive Software</author> <author>Jive Software</author>
<version>1.6.0</version> <version>1.7.0</version>
<date>06/20/2016</date> <date>03/06/2017</date>
<minServerVersion>4.0.0</minServerVersion> <minServerVersion>4.0.0</minServerVersion>
<adminconsole> <adminconsole>
......
...@@ -19,6 +19,10 @@ package org.jivesoftware.openfire.plugin; ...@@ -19,6 +19,10 @@ package org.jivesoftware.openfire.plugin;
import java.io.File; import java.io.File;
import java.util.Map; 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.apache.mina.transport.socket.SocketAcceptor;
import org.jivesoftware.openfire.XMPPServer; import org.jivesoftware.openfire.XMPPServer;
import org.jivesoftware.openfire.container.Plugin; import org.jivesoftware.openfire.container.Plugin;
...@@ -29,6 +33,12 @@ import org.jivesoftware.openfire.spi.ConnectionManagerImpl; ...@@ -29,6 +33,12 @@ import org.jivesoftware.openfire.spi.ConnectionManagerImpl;
import org.jivesoftware.util.JiveGlobals; import org.jivesoftware.util.JiveGlobals;
import org.jivesoftware.util.PropertyEventDispatcher; import org.jivesoftware.util.PropertyEventDispatcher;
import org.jivesoftware.util.PropertyEventListener; 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 * Debugger plugin that prints XML traffic to stdout. By default it will only print
...@@ -39,6 +49,9 @@ import org.jivesoftware.util.PropertyEventListener; ...@@ -39,6 +49,9 @@ import org.jivesoftware.util.PropertyEventListener;
* @author Gaston Dombiak * @author Gaston Dombiak
*/ */
public class DebuggerPlugin implements Plugin, PropertyEventListener { public class DebuggerPlugin implements Plugin, PropertyEventListener {
public static final Logger Log = LoggerFactory.getLogger( DebuggerPlugin.class );
private RawPrintFilter defaultPortFilter; private RawPrintFilter defaultPortFilter;
private RawPrintFilter oldPortFilter; private RawPrintFilter oldPortFilter;
private RawPrintFilter componentPortFilter; private RawPrintFilter componentPortFilter;
...@@ -61,31 +74,65 @@ public class DebuggerPlugin implements Plugin, PropertyEventListener { ...@@ -61,31 +74,65 @@ public class DebuggerPlugin implements Plugin, PropertyEventListener {
} }
} }
private void addInterceptors() { protected void addFilterToChain( final SocketAcceptor acceptor, final String filterName, final IoFilter filter )
// Add filter to filter chain builder {
ConnectionManagerImpl connManager = (ConnectionManagerImpl) XMPPServer.getInstance().getConnectionManager(); if ( acceptor == null )
defaultPortFilter = new RawPrintFilter("C2S"); {
SocketAcceptor socketAcceptor = connManager.getSocketAcceptor(); Log.debug( "Not adding filter '{}' to acceptor that is null.", filterName );
if (socketAcceptor != null) { return;
socketAcceptor.getFilterChain().addFirst("rawDebugger", defaultPortFilter);
} }
oldPortFilter = new RawPrintFilter("SSL");
SocketAcceptor sslAcceptor = connManager.getSSLSocketAcceptor(); final DefaultIoFilterChainBuilder chain = acceptor.getFilterChain();
if (sslAcceptor != null) { if ( chain.contains( COMPRESSION_FILTER_NAME ) )
sslAcceptor.getFilterChain().addFirst("rawDebugger", oldPortFilter); {
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"); protected void removeFilterFromChain( final SocketAcceptor acceptor, final String filterName )
SocketAcceptor componentAcceptor = connManager.getComponentAcceptor(); {
if (componentAcceptor != null) { if ( acceptor == null )
componentAcceptor.getFilterChain().addFirst("rawDebugger", componentPortFilter); {
Log.debug( "Not removing filter '{}' from acceptor that is null.", filterName );
return;
} }
multiplexerPortFilter = new RawPrintFilter("CM"); if ( acceptor.getFilterChain().contains( filterName ) )
SocketAcceptor multiplexerAcceptor = connManager.getMultiplexerSocketAcceptor(); {
if (multiplexerAcceptor != null) { Log.debug( "Removing filter '{}' from acceptor {}", filterName, acceptor );
multiplexerAcceptor.getFilterChain().addFirst("rawDebugger", multiplexerPortFilter); 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(); interpretedPrinter = new InterpretedXMLPrinter();
if (JiveGlobals.getBooleanProperty("plugin.debugger.interpretedAllowed")) { if (JiveGlobals.getBooleanProperty("plugin.debugger.interpretedAllowed")) {
...@@ -101,22 +148,11 @@ public class DebuggerPlugin implements Plugin, PropertyEventListener { ...@@ -101,22 +148,11 @@ public class DebuggerPlugin implements Plugin, PropertyEventListener {
PropertyEventDispatcher.removeListener(this); PropertyEventDispatcher.removeListener(this);
// Remove filter from filter chain builder // Remove filter from filter chain builder
ConnectionManagerImpl connManager = (ConnectionManagerImpl) XMPPServer.getInstance().getConnectionManager(); ConnectionManagerImpl connManager = (ConnectionManagerImpl) XMPPServer.getInstance().getConnectionManager();
if (connManager.getSocketAcceptor() != null && removeFilterFromChain( connManager.getSocketAcceptor(), RawPrintFilter.FILTER_NAME );
connManager.getSocketAcceptor().getFilterChain().contains("rawDebugger")) { removeFilterFromChain( connManager.getSSLSocketAcceptor(), RawPrintFilter.FILTER_NAME );
connManager.getSocketAcceptor().getFilterChain().remove("rawDebugger"); removeFilterFromChain( connManager.getComponentAcceptor(), RawPrintFilter.FILTER_NAME );
} removeFilterFromChain( connManager.getMultiplexerSocketAcceptor(), RawPrintFilter.FILTER_NAME );
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");
}
// Remove the filters from existing sessions // Remove the filters from existing sessions
if (defaultPortFilter != null) { if (defaultPortFilter != null) {
defaultPortFilter.shutdown(); defaultPortFilter.shutdown();
......
...@@ -35,6 +35,9 @@ import org.jivesoftware.util.JiveGlobals; ...@@ -35,6 +35,9 @@ import org.jivesoftware.util.JiveGlobals;
* @author Gaston Dombiak * @author Gaston Dombiak
*/ */
public class RawPrintFilter extends IoFilterAdapter { public class RawPrintFilter extends IoFilterAdapter {
public static final String FILTER_NAME = "rawDebugger";
private boolean enabled = true; private boolean enabled = true;
private String prefix; private String prefix;
private Collection<IoSession> sessions = new ConcurrentLinkedQueue<IoSession>(); private Collection<IoSession> sessions = new ConcurrentLinkedQueue<IoSession>();
...@@ -66,7 +69,7 @@ public class RawPrintFilter extends IoFilterAdapter { ...@@ -66,7 +69,7 @@ public class RawPrintFilter extends IoFilterAdapter {
} }
private String messagePrefix(final IoSession session, final String messageType) { 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 @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