Package org.parosproxy.paros.model
Class Session
- java.lang.Object
-
- org.parosproxy.paros.model.Session
-
public class Session extends java.lang.Object
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
Session.OnContextsChangedListener
Listener notified whenever the registered list of contexts changes.
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description void
addContext(Context c)
Adds the given context.void
addExcludeFromProxyRegex(java.lang.String ignoredRegex)
void
addExcludeFromScanRegexs(java.lang.String ignoredRegex)
void
addExcludeFromSpiderRegex(java.lang.String ignoredRegex)
Adds the given regular expression to the list of regular expressions used to exclude URLs from the spiders (e.g.void
addOnContextsChangedListener(Session.OnContextsChangedListener l)
void
clearContextData(int contextId)
void
clearContextDataForType(int contextId, int type)
protected void
close()
void
deleteContext(Context c)
protected void
discard()
void
exportContext(int contextId, java.io.File file)
Export the specified context to a filevoid
exportContext(Context c, java.io.File file)
Export the specified context to a filevoid
forceGlobalExcludeURLRefresh()
Deprecated.(2.12.0) No longer used/needed.Context
getContext(int id)
Context
getContext(java.lang.String name)
int
getContextDataInteger(int contextId, int type, int defaultValue)
Returns a context data integer of the given type and using the given default value if the value is not presentjava.lang.String
getContextDataString(int contextId, int type, java.lang.String defaultValue)
Returns a context data string of the given type and using the given default value if the value is not presentjava.util.List<java.lang.String>
getContextDataStrings(int contextId, int type)
java.util.List<Context>
getContexts()
java.util.List<Context>
getContextsForNode(SiteNode sn)
java.util.List<Context>
getContextsForUrl(java.lang.String url)
java.util.List<java.lang.String>
getExcludeFromProxyRegexs()
java.util.List<java.lang.String>
getExcludeFromScanRegexs()
java.util.List<java.lang.String>
getExcludeFromSpiderRegexs()
Gets the regular expressions used to exclude URLs from the spiders (e.g.java.lang.String
getFileName()
java.util.List<NameValuePair>
getFormParameters(org.apache.commons.httpclient.URI uri, java.lang.String formData)
Returns the FORM parameters for the given URL based on the parser associated with the first context found that includes the URL, or the default parser if it is not in a contextParameterParser
getFormParamParser(java.lang.String url)
Returns the form parameter parser associated with the first context found that includes the URL, or the default parser if it is not in a contextjava.util.Map<java.lang.String,java.lang.String>
getFormParams(org.apache.commons.httpclient.URI uri, java.lang.String formData)
Deprecated.2.10.0 use #getFormParameters(String)java.util.List<java.lang.String>
getGlobalExcludeURLRegexs()
Gets the global exclude URLs.Context
getNewContext(java.lang.String name)
Gets a newly created context with the given name.java.util.List<SiteNode>
getNodesInContextFromSiteTree(Context context)
Gets the nodes from the site tree which are "In Scope" in a given context.java.util.List<SiteNode>
getNodesInScopeFromSiteTree()
Gets the nodes from the site tree which are "In Scope".java.util.List<NameValuePair>
getParameters(HttpMessage msg, HtmlParameter.Type type)
Gets the parameters of the giventype
from the givenmessage
.java.util.Map<java.lang.String,java.lang.String>
getParams(HttpMessage msg, HtmlParameter.Type type)
Deprecated.2.10.0 use #getParameters(String) This method will lose duplicated parameter namesjava.lang.String
getSessionDesc()
java.lang.String
getSessionFolder()
long
getSessionId()
java.lang.String
getSessionName()
java.util.List<java.lang.String>
getSessionUrls(int type)
SiteMap
getSiteTree()
java.util.List<SiteNode>
getTopNodesInScopeFromSiteTree()
Gets the top nodes from the site tree which contain nodes that are "In Scope".java.util.List<java.lang.String>
getTreePath(org.apache.commons.httpclient.URI uri)
Deprecated.java.util.List<java.lang.String>
getTreePath(HttpMessage msg)
Deprecated.java.util.List<NameValuePair>
getUrlParameters(org.apache.commons.httpclient.URI uri)
Returns the URL parameters for the given URL based on the parser associated with the first context found that includes the URL, or the default parser if it is not in a contextParameterParser
getUrlParamParser(java.lang.String url)
Returns the url parameter parser associated with the first context found that includes the URL, or the default parser if it is not in a contextjava.util.Map<java.lang.String,java.lang.String>
getUrlParams(org.apache.commons.httpclient.URI uri)
Deprecated.2.10.0 use #getUrlParameters(String)Context
importContext(java.io.File file)
Imports a context from the specified (XML) file.Context
importContext(ZapXmlConfiguration config)
Imports a context from the specified XML config.protected boolean
isExcludedFromScope(SiteNode sn)
protected boolean
isIncludedInScope(SiteNode sn)
boolean
isInScope(java.lang.String url)
boolean
isInScope(HistoryReference href)
boolean
isInScope(SiteNode sn)
boolean
isNewState()
Tells whether this session is in a new state or not.protected void
open(java.io.File file, SessionListener callback)
protected void
open(java.lang.String fileName)
protected void
open(java.lang.String sessionFile, SessionListener callback)
protected void
persistProperties()
Persists the properties (e.g.void
removeOnContextsChangedListener(Session.OnContextsChangedListener l)
protected void
save(java.lang.String fileName)
Synchronous call to save a session.protected void
save(java.lang.String fileName, SessionListener callback)
Asynchronous call to save a session.void
saveAllContexts()
void
saveContext(Context c)
void
setContextData(int contextId, int type, java.lang.String data)
void
setContextData(int contextId, int type, java.util.List<java.lang.String> dataList)
void
setExcludeFromProxyRegexs(java.util.List<java.lang.String> ignoredRegexs)
void
setExcludeFromScanRegexs(java.util.List<java.lang.String> ignoredRegexs)
void
setExcludeFromSpiderRegexs(java.util.List<java.lang.String> ignoredRegexs)
Sets the given regular expressions as the list of regular expressions used to exclude URLs from the spiders (e.g.void
setGlobalExcludedUrlRegexsSupplier(java.util.function.Supplier<java.util.List<java.lang.String>> supplier)
Sets the supplier of global exclude URLs.void
setSessionDesc(java.lang.String sessionDesc)
void
setSessionId(long sessionId)
void
setSessionName(java.lang.String name)
void
setSessionUrl(int type, java.lang.String url)
void
setSessionUrls(int type, java.util.List<java.lang.String> urls)
protected void
snapshot(java.lang.String fileName)
Synchronous call to snapshot a session.protected void
snapshot(java.lang.String fileName, SessionListener callback)
Asynchronous call to snapshot a session.
-
-
-
Constructor Detail
-
Session
public Session(Model model)
Constructor for the current session. The current system time will be used as the session ID.- Parameters:
model
-
-
-
Method Detail
-
discard
protected void discard()
-
close
protected void close()
-
getSessionDesc
public java.lang.String getSessionDesc()
- Returns:
- Returns the sessionDesc.
-
getSessionId
public long getSessionId()
- Returns:
- Returns the sessionId.
-
getSessionName
public java.lang.String getSessionName()
- Returns:
- Returns the name.
-
getSiteTree
public SiteMap getSiteTree()
- Returns:
- Returns the siteTree.
-
isNewState
public boolean isNewState()
Tells whether this session is in a new state or not. A session is in a new state if it was never saved or it was not loaded from an existing session.- Returns:
true
if this session is in a new state,false
otherwise.
-
open
protected void open(java.io.File file, SessionListener callback)
-
open
protected void open(java.lang.String sessionFile, SessionListener callback)
-
open
protected void open(java.lang.String fileName) throws DatabaseException, java.io.IOException, java.lang.Exception
- Throws:
DatabaseException
java.io.IOException
java.lang.Exception
-
save
protected void save(java.lang.String fileName, SessionListener callback)
Asynchronous call to save a session.- Parameters:
fileName
-callback
-
-
save
protected void save(java.lang.String fileName) throws java.lang.Exception
Synchronous call to save a session.- Parameters:
fileName
-- Throws:
java.lang.Exception
-
persistProperties
protected void persistProperties() throws java.lang.Exception
Persists the properties (e.g. name, description) of the session.Should be called only by "core" classes.
- Throws:
java.lang.Exception
- if an error occurred while persisting the properties.- Since:
- 2.7.0
- See Also:
setSessionName(String)
,setSessionDesc(String)
-
snapshot
protected void snapshot(java.lang.String fileName, SessionListener callback)
Asynchronous call to snapshot a session.- Parameters:
fileName
-callback
-
-
snapshot
protected void snapshot(java.lang.String fileName) throws java.lang.Exception
Synchronous call to snapshot a session.- Parameters:
fileName
-- Throws:
java.lang.Exception
-
setSessionDesc
public void setSessionDesc(java.lang.String sessionDesc)
- Parameters:
sessionDesc
- The sessionDesc to set.
-
setSessionId
public void setSessionId(long sessionId)
- Parameters:
sessionId
- The sessionId to set.
-
setSessionName
public void setSessionName(java.lang.String name)
- Parameters:
name
- The name to set.
-
getFileName
public java.lang.String getFileName()
-
getSessionFolder
public java.lang.String getSessionFolder()
-
getExcludeFromProxyRegexs
public java.util.List<java.lang.String> getExcludeFromProxyRegexs()
-
isIncludedInScope
protected boolean isIncludedInScope(SiteNode sn)
-
isExcludedFromScope
protected boolean isExcludedFromScope(SiteNode sn)
-
isInScope
public boolean isInScope(HistoryReference href)
-
isInScope
public boolean isInScope(SiteNode sn)
-
isInScope
public boolean isInScope(java.lang.String url)
-
getNodesInScopeFromSiteTree
public java.util.List<SiteNode> getNodesInScopeFromSiteTree()
Gets the nodes from the site tree which are "In Scope". Searches recursively starting from the root node. Should be used with care, as it is time-consuming, querying the database for every node in the Site Tree.- Returns:
- the nodes in scope from site tree
-
getTopNodesInScopeFromSiteTree
public java.util.List<SiteNode> getTopNodesInScopeFromSiteTree()
Gets the top nodes from the site tree which contain nodes that are "In Scope". Searches recursively starting from the root node. Should be used with care, as it is time-consuming, querying the database for every node in the Site Tree.- Returns:
- the nodes in scope from site tree
-
getNodesInContextFromSiteTree
public java.util.List<SiteNode> getNodesInContextFromSiteTree(Context context)
Gets the nodes from the site tree which are "In Scope" in a given context. Searches recursively starting from the root node. Should be used with care, as it is time-consuming, querying the database for every node in the Site Tree.- Parameters:
context
- the context- Returns:
- the nodes in scope from site tree
-
setExcludeFromProxyRegexs
public void setExcludeFromProxyRegexs(java.util.List<java.lang.String> ignoredRegexs) throws DatabaseException
- Throws:
DatabaseException
-
addExcludeFromProxyRegex
public void addExcludeFromProxyRegex(java.lang.String ignoredRegex) throws DatabaseException
- Throws:
DatabaseException
-
getExcludeFromScanRegexs
public java.util.List<java.lang.String> getExcludeFromScanRegexs()
-
addExcludeFromScanRegexs
public void addExcludeFromScanRegexs(java.lang.String ignoredRegex) throws DatabaseException
- Throws:
DatabaseException
-
setExcludeFromScanRegexs
public void setExcludeFromScanRegexs(java.util.List<java.lang.String> ignoredRegexs) throws DatabaseException
- Throws:
DatabaseException
-
getExcludeFromSpiderRegexs
public java.util.List<java.lang.String> getExcludeFromSpiderRegexs()
Gets the regular expressions used to exclude URLs from the spiders (e.g. traditional, AJAX).- Returns:
- a
List
containing the regular expressions, nevernull
.
-
addExcludeFromSpiderRegex
public void addExcludeFromSpiderRegex(java.lang.String ignoredRegex) throws DatabaseException
Adds the given regular expression to the list of regular expressions used to exclude URLs from the spiders (e.g. traditional, AJAX).- Parameters:
ignoredRegex
- the regular expression to be added- Throws:
java.lang.IllegalArgumentException
- if the regular expression is not valid.DatabaseException
- if an error occurred while persisting the list.
-
setExcludeFromSpiderRegexs
public void setExcludeFromSpiderRegexs(java.util.List<java.lang.String> ignoredRegexs) throws DatabaseException
Sets the given regular expressions as the list of regular expressions used to exclude URLs from the spiders (e.g. traditional, AJAX).- Parameters:
ignoredRegexs
- the regular expressions to be set- Throws:
java.lang.IllegalArgumentException
- if any of the regular expressions is not valid.DatabaseException
- if an error occurred while persisting the list.
-
forceGlobalExcludeURLRefresh
@Deprecated public void forceGlobalExcludeURLRefresh()
Deprecated.(2.12.0) No longer used/needed. It will be removed in a future release.Resets the global exclude URLs of the Local Proxy.This should be considered an internal method, to be called only by core code.
- Since:
- 2.3.0
-
getGlobalExcludeURLRegexs
public java.util.List<java.lang.String> getGlobalExcludeURLRegexs()
Gets the global exclude URLs.Note: This method is only provided as a convenience, the global exclude URLs are not saved in the session.
- Returns:
- an unmodifiable
List
containing the URLs that should be excluded globally. - Since:
- 2.3.0
-
setGlobalExcludedUrlRegexsSupplier
public void setGlobalExcludedUrlRegexsSupplier(java.util.function.Supplier<java.util.List<java.lang.String>> supplier)
Sets the supplier of global exclude URLs.Note: Not part of the public API.
- Parameters:
supplier
- the supplier of global exclude URLs.- Since:
- 2.13.0
-
setSessionUrls
public void setSessionUrls(int type, java.util.List<java.lang.String> urls) throws DatabaseException
- Throws:
DatabaseException
-
setSessionUrl
public void setSessionUrl(int type, java.lang.String url) throws DatabaseException
- Throws:
DatabaseException
-
getSessionUrls
public java.util.List<java.lang.String> getSessionUrls(int type) throws DatabaseException
- Throws:
DatabaseException
-
getContextDataStrings
public java.util.List<java.lang.String> getContextDataStrings(int contextId, int type) throws DatabaseException
- Throws:
DatabaseException
-
getContextDataString
public java.lang.String getContextDataString(int contextId, int type, java.lang.String defaultValue) throws DatabaseException
Returns a context data string of the given type and using the given default value if the value is not present- Parameters:
contextId
- the context Idtype
- the data type requireddefaultValue
- the default value to use if the type is not present- Returns:
- the context data string
- Throws:
DatabaseException
- Since:
- 2.10.0
-
getContextDataInteger
public int getContextDataInteger(int contextId, int type, int defaultValue) throws DatabaseException
Returns a context data integer of the given type and using the given default value if the value is not present- Parameters:
contextId
- the context Idtype
- the data type requireddefaultValue
- the default value to use if the type is not present- Returns:
- the context data integer
- Throws:
DatabaseException
- Since:
- 2.10.0
-
setContextData
public void setContextData(int contextId, int type, java.lang.String data) throws DatabaseException
- Throws:
DatabaseException
-
setContextData
public void setContextData(int contextId, int type, java.util.List<java.lang.String> dataList) throws DatabaseException
- Throws:
DatabaseException
-
clearContextDataForType
public void clearContextDataForType(int contextId, int type) throws DatabaseException
- Throws:
DatabaseException
-
clearContextData
public void clearContextData(int contextId) throws DatabaseException
- Throws:
DatabaseException
-
saveContext
public void saveContext(Context c)
-
saveAllContexts
public void saveAllContexts()
-
getNewContext
public Context getNewContext(java.lang.String name)
Gets a newly created context with the given name.The context is automatically added to the session.
- Parameters:
name
- the name of the context- Returns:
- the new
Context
. - Throws:
IllegalContextNameException
- (since 2.6.0) if the given name isnull
or empty or if a context with the given name already exists.
-
addContext
public void addContext(Context c)
Adds the given context.- Parameters:
c
- the context to be added- Throws:
java.lang.IllegalArgumentException
- (since 2.6.0) if the given context isnull
.IllegalContextNameException
- (since 2.6.0) if context's name isnull
or empty or if a context with the same name already exists.
-
deleteContext
public void deleteContext(Context c)
-
getContext
public Context getContext(int id)
-
getContext
public Context getContext(java.lang.String name)
-
getContexts
public java.util.List<Context> getContexts()
-
getContextsForUrl
public java.util.List<Context> getContextsForUrl(java.lang.String url)
-
exportContext
public void exportContext(int contextId, java.io.File file) throws org.apache.commons.configuration.ConfigurationException
Export the specified context to a file- Parameters:
contextId
- the ID of the Context to be exportedfile
- the File to which the Context should be exported- Throws:
org.apache.commons.configuration.ConfigurationException
-
exportContext
public void exportContext(Context c, java.io.File file) throws org.apache.commons.configuration.ConfigurationException
Export the specified context to a file- Parameters:
c
-file
-- Throws:
org.apache.commons.configuration.ConfigurationException
-
importContext
public Context importContext(java.io.File file) throws org.apache.commons.configuration.ConfigurationException, java.lang.ClassNotFoundException, java.lang.InstantiationException, java.lang.IllegalAccessException, java.lang.IllegalArgumentException, java.lang.reflect.InvocationTargetException, java.lang.NoSuchMethodException, java.lang.SecurityException
Imports a context from the specified (XML) file.- Parameters:
file
- the (XML) file that contains the context data- Returns:
- the imported
Context
, already added to the session. - Throws:
org.apache.commons.configuration.ConfigurationException
java.lang.ClassNotFoundException
java.lang.InstantiationException
java.lang.IllegalAccessException
java.lang.IllegalArgumentException
java.lang.reflect.InvocationTargetException
java.lang.NoSuchMethodException
java.lang.SecurityException
IllegalContextNameException
- (since 2.6.0) if context's name is not provided or it's empty or if a context with the same name already exists.
-
importContext
public Context importContext(ZapXmlConfiguration config) throws org.apache.commons.configuration.ConfigurationException, java.lang.ClassNotFoundException, java.lang.InstantiationException, java.lang.IllegalAccessException, java.lang.IllegalArgumentException, java.lang.reflect.InvocationTargetException, java.lang.NoSuchMethodException, java.lang.SecurityException
Imports a context from the specified XML config.- Parameters:
config
- the XML config that contains the context data- Returns:
- the imported
Context
, already added to the session. - Throws:
org.apache.commons.configuration.ConfigurationException
java.lang.ClassNotFoundException
java.lang.InstantiationException
java.lang.IllegalAccessException
java.lang.IllegalArgumentException
java.lang.reflect.InvocationTargetException
java.lang.NoSuchMethodException
java.lang.SecurityException
IllegalContextNameException
- if context's name is not provided or it's empty or if a context with the same name already exists.- Since:
- 2.13.0
-
getUrlParamParser
public ParameterParser getUrlParamParser(java.lang.String url)
Returns the url parameter parser associated with the first context found that includes the URL, or the default parser if it is not in a context- Parameters:
url
-- Returns:
-
getFormParamParser
public ParameterParser getFormParamParser(java.lang.String url)
Returns the form parameter parser associated with the first context found that includes the URL, or the default parser if it is not in a context- Parameters:
url
-- Returns:
-
getParams
@Deprecated public java.util.Map<java.lang.String,java.lang.String> getParams(HttpMessage msg, HtmlParameter.Type type)
Deprecated.2.10.0 use #getParameters(String) This method will lose duplicated parameter namesReturns the specified parameters for the given message based on the parser associated with the first context found that includes the URL for the message, or the default parser if it is not in a context- Parameters:
msg
-type
-- Returns:
-
getParameters
public java.util.List<NameValuePair> getParameters(HttpMessage msg, HtmlParameter.Type type)
Gets the parameters of the giventype
from the givenmessage
.Parameters' names and values are in decoded form.
- Parameters:
msg
- the message whose parameters will be extracted fromtype
- the type of parameters to extract- Returns:
- a
List
containing the parameters - Throws:
java.lang.IllegalArgumentException
- if any of the parameters isnull
or if the giventype
is noturl
orform
.- Since:
- 2.5.0
- See Also:
StandardParameterParser.getParameters(HttpMessage, org.parosproxy.paros.network.HtmlParameter.Type)
-
getUrlParams
@Deprecated public java.util.Map<java.lang.String,java.lang.String> getUrlParams(org.apache.commons.httpclient.URI uri) throws org.apache.commons.httpclient.URIException
Deprecated.2.10.0 use #getUrlParameters(String)Returns the URL parameters for the given URL based on the parser associated with the first context found that includes the URL, or the default parser if it is not in a context- Parameters:
uri
-- Returns:
- Throws:
org.apache.commons.httpclient.URIException
-
getUrlParameters
public java.util.List<NameValuePair> getUrlParameters(org.apache.commons.httpclient.URI uri) throws org.apache.commons.httpclient.URIException
Returns the URL parameters for the given URL based on the parser associated with the first context found that includes the URL, or the default parser if it is not in a context- Parameters:
uri
-- Returns:
- the URL parameters for the given URL
- Throws:
org.apache.commons.httpclient.URIException
- Since:
- 2.10.0
-
getFormParams
@Deprecated public java.util.Map<java.lang.String,java.lang.String> getFormParams(org.apache.commons.httpclient.URI uri, java.lang.String formData) throws org.apache.commons.httpclient.URIException
Deprecated.2.10.0 use #getFormParameters(String)Returns the FORM parameters for the given URL based on the parser associated with the first context found that includes the URL, or the default parser if it is not in a context- Parameters:
uri
-formData
-- Returns:
- the FORM parameters for the given URL
- Throws:
org.apache.commons.httpclient.URIException
-
getFormParameters
public java.util.List<NameValuePair> getFormParameters(org.apache.commons.httpclient.URI uri, java.lang.String formData) throws org.apache.commons.httpclient.URIException
Returns the FORM parameters for the given URL based on the parser associated with the first context found that includes the URL, or the default parser if it is not in a context- Parameters:
uri
-formData
-- Returns:
- the FORM parameters for the given URL
- Throws:
org.apache.commons.httpclient.URIException
- Since:
- 2.10.0
-
getTreePath
@Deprecated public java.util.List<java.lang.String> getTreePath(org.apache.commons.httpclient.URI uri) throws org.apache.commons.httpclient.URIException
Deprecated.- Throws:
org.apache.commons.httpclient.URIException
-
getTreePath
@Deprecated public java.util.List<java.lang.String> getTreePath(HttpMessage msg) throws org.apache.commons.httpclient.URIException
Deprecated.- Throws:
org.apache.commons.httpclient.URIException
-
addOnContextsChangedListener
public void addOnContextsChangedListener(Session.OnContextsChangedListener l)
-
removeOnContextsChangedListener
public void removeOnContextsChangedListener(Session.OnContextsChangedListener l)
-
-