org.owasp.webscarab.plugin.proxy
Class Proxy

java.lang.Object
  extended by org.owasp.webscarab.plugin.proxy.Proxy
All Implemented Interfaces:
java.lang.Runnable, Plugin

public class Proxy
extends java.lang.Object
implements Plugin

The Proxy plugin supports multiple Listeners, and starts and stops them as instructed. All requests and responses are submitted to the model, unless there is an error while retrieving the response.


Constructor Summary
Proxy(Framework framework)
          Creates a Proxy Object with a reference to the Framework.
 
Method Summary
 void addListener(java.lang.String address, int port, HttpUrl base, java.lang.String simulator, boolean primary)
          used by the User Interface to start a new proxy listening with the specified parameters
 void addPlugin(ProxyPlugin plugin)
           
 void analyse(ConversationID id, Request request, Response response, java.lang.String origin)
           
protected  void failedResponse(ConversationID id, java.lang.String reason)
          notifies any observers that the request failed to complete, and the reason for it
 void flush()
          called to instruct the plugin to flush any memory-only state to the store.
 java.lang.String getAddress(java.lang.String key)
          used to obtain the address that the referenced Listener is bound to
 HttpUrl getBase(java.lang.String key)
           
 ProxyPlugin getPlugin(java.lang.String name)
          retrieves the named plugin, if it exists
 java.lang.String getPluginName()
          The plugin name
protected  ProxyPlugin[] getPlugins()
          called by ConnectionHandler to see which plugins have been configured.
 int getPort(java.lang.String key)
           
 java.lang.String[] getProxies()
          returns a list of keys describing the configured Listeners
 java.lang.Object getScriptableObject()
           
 Hook[] getScriptingHooks()
           
 java.lang.String getSimulator(java.lang.String key)
           
 java.lang.String[] getSimulators()
          Used to obtain a list of known network simulators, which can be used to simulate a modem or other bandwidth limited connection
 java.lang.String getStatus()
          called to determine what the current status of the plugin is
protected  ConversationID gotRequest(Request request)
          used by ConnectionHandler to notify the Proxy (and any listeners) that it is handling a particular request
protected  void gotResponse(ConversationID id, Response response)
          used by ConnectionHandler to notify the Proxy (and any listeners) that it has handled a particular request and response, and that it should be logged and analysed
 boolean isBusy()
          called to test whether the plugin is able to be stopped
 boolean isModified()
          called to determine whether the data stored within the plugin has been modified and should be saved
 boolean isPrimaryProxy(java.lang.String key)
           
 boolean isRunning()
           
 boolean removeListener(java.lang.String key)
          Used to stop the referenced listener
 void run()
          Starts the Listeners
 void setSession(java.lang.String type, java.lang.Object store, java.lang.String session)
          informs the plugin that the Session has changed
 void setUI(ProxyUI ui)
           
 boolean stop()
          Stops the Listeners
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Proxy

public Proxy(Framework framework)
Creates a Proxy Object with a reference to the Framework. Creates (but does not start) the configured Listeners.

Parameters:
model - The Model to submit requests and responses to
Method Detail

getScriptingHooks

public Hook[] getScriptingHooks()
Specified by:
getScriptingHooks in interface Plugin

getScriptableObject

public java.lang.Object getScriptableObject()
Specified by:
getScriptableObject in interface Plugin

setUI

public void setUI(ProxyUI ui)

addPlugin

public void addPlugin(ProxyPlugin plugin)

getPlugin

public ProxyPlugin getPlugin(java.lang.String name)
retrieves the named plugin, if it exists

Parameters:
name - the name of the plugin
Returns:
the plugin if it exists, or null

getPluginName

public java.lang.String getPluginName()
The plugin name

Specified by:
getPluginName in interface Plugin
Returns:
The name of the plugin

getProxies

public java.lang.String[] getProxies()
returns a list of keys describing the configured Listeners

Returns:
the list of keys

getAddress

public java.lang.String getAddress(java.lang.String key)
used to obtain the address that the referenced Listener is bound to

Parameters:
key - the key referring to a configured Listener
Returns:
the address that the Listener is listening to

getPort

public int getPort(java.lang.String key)

getBase

public HttpUrl getBase(java.lang.String key)

getSimulators

public java.lang.String[] getSimulators()
Used to obtain a list of known network simulators, which can be used to simulate a modem or other bandwidth limited connection

Returns:
an array of Simulator keys

getSimulator

public java.lang.String getSimulator(java.lang.String key)

isPrimaryProxy

public boolean isPrimaryProxy(java.lang.String key)

getPlugins

protected ProxyPlugin[] getPlugins()
called by ConnectionHandler to see which plugins have been configured.

Returns:
an array of ProxyPlugin's

addListener

public void addListener(java.lang.String address,
                        int port,
                        HttpUrl base,
                        java.lang.String simulator,
                        boolean primary)
                 throws java.io.IOException
used by the User Interface to start a new proxy listening with the specified parameters

Parameters:
address - the address to listen to, null or "" implies localhost, "*" implies all interfaces
port - the port to listen on
base - a string such as "http://site:port/" which is used by reverse proxies to indicate the address that it is acting as.
simulator - a String referring to a network simulator
usePlugins - indicates whether the ConnectionHandlers spawned by this Listener should pass Requests and Responses through the defined proxy plugins
Throws:
java.io.IOException - if there are any problems starting the Listener

removeListener

public boolean removeListener(java.lang.String key)
Used to stop the referenced listener

Parameters:
key - the Listener to stop
Returns:
true if the proxy was successfully stopped, false otherwise

run

public void run()
Starts the Listeners

Specified by:
run in interface java.lang.Runnable
Specified by:
run in interface Plugin

stop

public boolean stop()
Stops the Listeners

Specified by:
stop in interface Plugin
Returns:
true if successful, false otherwise

gotRequest

protected ConversationID gotRequest(Request request)
used by ConnectionHandler to notify the Proxy (and any listeners) that it is handling a particular request

Parameters:
request - the request to log
Returns:
the conversation ID

gotResponse

protected void gotResponse(ConversationID id,
                           Response response)
used by ConnectionHandler to notify the Proxy (and any listeners) that it has handled a particular request and response, and that it should be logged and analysed

Parameters:
id - the Conversation ID
response - the Response

failedResponse

protected void failedResponse(ConversationID id,
                              java.lang.String reason)
notifies any observers that the request failed to complete, and the reason for it

Parameters:
reason - the reason for failure
id - the conversation ID

flush

public void flush()
           throws StoreException
Description copied from interface: Plugin
called to instruct the plugin to flush any memory-only state to the store.

Specified by:
flush in interface Plugin
Throws:
StoreException - if there is any problem saving the session data

isBusy

public boolean isBusy()
Description copied from interface: Plugin
called to test whether the plugin is able to be stopped

Specified by:
isBusy in interface Plugin
Returns:
false if the plugin can be stopped

getStatus

public java.lang.String getStatus()
Description copied from interface: Plugin
called to determine what the current status of the plugin is

Specified by:
getStatus in interface Plugin

isModified

public boolean isModified()
Description copied from interface: Plugin
called to determine whether the data stored within the plugin has been modified and should be saved

Specified by:
isModified in interface Plugin

analyse

public void analyse(ConversationID id,
                    Request request,
                    Response response,
                    java.lang.String origin)
Specified by:
analyse in interface Plugin

setSession

public void setSession(java.lang.String type,
                       java.lang.Object store,
                       java.lang.String session)
                throws StoreException
Description copied from interface: Plugin
informs the plugin that the Session has changed

Specified by:
setSession in interface Plugin
Throws:
StoreException

isRunning

public boolean isRunning()
Specified by:
isRunning in interface Plugin