You left one thing out. You did create your plugin to be a PacketInterceptor. What you need to do next is to register your new PacketInterceptor to the server.
Openfire keeps a list of PacketInterceptors, to which you need to add your plugin (and of course, remove it from that list if you unload your plugin). Openfire uses the InterceptorManager class to manage PacketInterceptors.
I would suggest modifying your plugin something like this:
public class IntercepteurPlugin implements Plugin, PacketInterceptor { private static final PacketRejectedException REJECTED = new PacketRejectedException(
"Message refusé"); public void destroyPlugin() {
// remove this PacketInterceptor from the server.
final InterceptorManager interceptorManager = InterceptorManager.getInstance();
interceptorManager.removeInterceptor(this);
} public void initializePlugin(PluginManager manager, File pluginDirectory) {
// add this PacketInterceptor to the server.
final InterceptorManager interceptorManager = InterceptorManager.getInstance();
interceptorManager.addInterceptor(this);
} public void interceptPacket(Packet packet, Session session,
boolean incoming, boolean processed) throws PacketRejectedException { if ((packet.getFrom().getNode().startsWith("cabine"))
&& (packet.getTo().getNode().startsWith("cabine"))) { throw REJECTED;
}
}
}
By the way: not that’'s really important, but if you want to check the username of packet, you should probably be using the JID.getNode() result (which typically returns the username), instead of JID.toString() (which returns the entire String). But hey, the end result is the same.