| Prev | Next |
Plugins are developed in Java language. Here is a simple example.
package net.jumperz.app.MGuardian.plugin;
import net.jumperz.net.*;
import java.util.*;
/**
* Plugin example
* This simple plugin removes the referer field from HTTP request headers.
*/
public class MExample1
extends MGuardianPlugin
{
//--------------------------------------------------------------------------------
public Map execute( Map sessionInfo )
{
MHttpRequest request = ( MHttpRequest )sessionInfo.get( "request" );
request.removeHeaderValue( "Referer" );
return null;
}
//--------------------------------------------------------------------------------
}
This plugin removes the "Referer" header from the HTTP request.
Plugin must inherit the net.jumperz.app.MGuardian.plugin.MGuardianPlugin class. MGuardianPlugin is an abstract class that has three methods ( execute, startup, and shutdown ). Plugin must implement the "execute" method.
For each plugin, one instance is created at run time. The instance is created at startup of Guardian@JUMPERZ.NET, and the "startup" method is called at this time ( if it is implemented ). If the plugin needs to do some kind of initialization like connecting to a database or opening a file, you can use the "startup" method.
The "execute" method is called by rules during each HTTP session. Here is an example.
<rule>
id=P01
revision=1
name=PluginTest
type=requestLine
pattern=^
condition=match
case_sensitive=no
log=no
action=none
command=none
plugin=net.jumperz.app.MGuardian.plugin.MExample1
</rule>
When this rule triggers, the "execute" method of "MExample1" plugin is called. Plugins are execute by rules like this.
You can call multiple plugins from one rule. See the following example.
<rule>
id=GID2
revision=1
name=ExecDefaultPlugins(request)
type=requestLine
pattern=^
condition=match
case_sensitive=no
log=no
action=none
command=none
plugin=net.jumperz.app.MGuardian.plugin.MIllegalEncodingDetector
plugin=net.jumperz.app.MGuardian.plugin.MIllegalBodyEncodingDetector
plugin=net.jumperz.app.MGuardian.plugin.MUriNormalizer
</rule>
In this example, three plugins are called by one rule.
Because "execute" method may be simultaneously called by two or more threads, you need to create plugins with considering a synchronization. This means that the "execute" method must be thread-safe.
The "shutdown" method is called at shutdown of Guardian@JUMPERZ.NET. If the plugin needs to do some kind of finalization, you can use the "shutdown" method.