Package org.zaproxy.zap.model
Class Context
- java.lang.Object
-
- org.zaproxy.zap.model.Context
-
public class Context extends java.lang.Object
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
CONTEXT_CONFIG
static java.lang.String
CONTEXT_CONFIG_DATA_DRIVEN_NODES
static java.lang.String
CONTEXT_CONFIG_DESC
static java.lang.String
CONTEXT_CONFIG_EXC_REGEXES
static java.lang.String
CONTEXT_CONFIG_INC_REGEXES
static java.lang.String
CONTEXT_CONFIG_INSCOPE
static java.lang.String
CONTEXT_CONFIG_NAME
static java.lang.String
CONTEXT_CONFIG_POSTPARSER
static java.lang.String
CONTEXT_CONFIG_POSTPARSER_CLASS
static java.lang.String
CONTEXT_CONFIG_POSTPARSER_CONFIG
static java.lang.String
CONTEXT_CONFIG_TECH
static java.lang.String
CONTEXT_CONFIG_TECH_EXCLUDE
static java.lang.String
CONTEXT_CONFIG_TECH_INCLUDE
static java.lang.String
CONTEXT_CONFIG_URLPARSER
static java.lang.String
CONTEXT_CONFIG_URLPARSER_CLASS
static java.lang.String
CONTEXT_CONFIG_URLPARSER_CONFIG
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description void
addCustomPage(CustomPage customPage)
Adds a custom page.void
addDataDrivenNodes(StructuralNodeModifier ddn)
void
addExcludeFromContextRegex(java.lang.String excludeRegex)
void
addIncludeInContextRegex(java.lang.String includeRegex)
Context
duplicate()
Creates a copy of the Context.boolean
equals(java.lang.Object obj)
void
excludeFromContext(SiteNode sn, boolean recurse)
void
excludeFromContext(StructuralNode sn, boolean recurse)
AuthenticationMethod
getAuthenticationMethod()
Gets the authentication method corresponding to this context.AuthorizationDetectionMethod
getAuthorizationDetectionMethod()
Gets the authorization detection method corresponding to this context.java.util.List<CustomPage>
getCustomPages()
Gets an unmodifiable view of the list of custom pages.java.util.List<StructuralNodeModifier>
getDataDrivenNodes()
java.lang.String
getDefaultDDNName()
java.lang.String
getDescription()
java.util.List<java.lang.String>
getExcludeFromContextRegexs()
int
getId()
Returns the ID of theContext
java.util.List<java.lang.String>
getIncludeInContextRegexs()
int
getIndex()
Deprecated.(2.9.0) UsegetId()
instead.java.lang.String
getName()
Gets the name of the context.java.util.List<SiteNode>
getNodesInContextFromSiteTree()
Gets the nodes from the site tree which are "In Scope".ParameterParser
getPostParamParser()
SessionManagementMethod
getSessionManagementMethod()
Gets the session management method corresponding to this context.TechSet
getTechSet()
java.util.List<SiteNode>
getTopNodesInContextFromSiteTree()
Gets the nodes from the site tree which are "In Scope".ParameterParser
getUrlParamParser()
boolean
hasCustomPageOfType(CustomPage.Type cpType)
Returnstrue
if theContext
has Custom Page definitions of a specificCustomPage.Type
.boolean
hasCustomPages()
Returnstrue
if theContext
has Custom Pages.int
hashCode()
boolean
hasNodesInContextFromSiteTree()
Tells whether or not there's at least one node from the sites tree in context.boolean
isCustomPage(HttpMessage msg, CustomPage.Type cpType)
Determines if aHttpMessage
is a Custom Page of a particularCustomPage.Type
.boolean
isCustomPageWithFallback(HttpMessage msg, CustomPage.Type cpType)
Determines if aHttpMessage
is a Custom Page of a particularCustomPage.Type
.boolean
isExcluded(java.lang.String url)
boolean
isExcluded(SiteNode sn)
boolean
isExcludedFromScope(SiteNode sn)
boolean
isIncluded(java.lang.String url)
boolean
isIncluded(SiteNode sn)
boolean
isIncludedInScope(SiteNode sn)
boolean
isInContext(java.lang.String url)
boolean
isInContext(HistoryReference href)
boolean
isInContext(SiteNode sn)
boolean
isInScope()
void
removeAllCustomPages()
Removes all the custom pages.boolean
removeCustomPage(CustomPage customPage)
Removes a custom page.void
restructureSiteTree()
void
save()
void
setAuthenticationMethod(AuthenticationMethod authenticationMethod)
Sets the authentication method corresponding to this context.void
setAuthorizationDetectionMethod(AuthorizationDetectionMethod authorizationDetectionMethod)
Sets the authorization detection method corresponding to this context.void
setCustomPages(java.util.List<CustomPage> customPages)
Sets a new list of custom pages for this context.void
setDataDrivenNodes(java.util.List<StructuralNodeModifier> dataDrivenNodes)
void
setDescription(java.lang.String description)
void
setExcludeFromContextRegexs(java.util.List<java.lang.String> excludeRegexs)
Sets the regular expressions used to exclude a URL from the context.void
setIncludeInContextRegexs(java.util.List<java.lang.String> includeRegexs)
Sets the regular expressions used to include a URL in context.void
setInScope(boolean inScope)
void
setName(java.lang.String name)
Sets the name of the context.void
setPostParamParser(ParameterParser postParamParser)
void
setSessionManagementMethod(SessionManagementMethod sessionManagementMethod)
Sets the session management method corresponding to this context.void
setTechSet(TechSet techSet)
void
setUrlParamParser(ParameterParser paramParser)
-
-
-
Field Detail
-
CONTEXT_CONFIG
public static final java.lang.String CONTEXT_CONFIG
- See Also:
- Constant Field Values
-
CONTEXT_CONFIG_NAME
public static final java.lang.String CONTEXT_CONFIG_NAME
- See Also:
- Constant Field Values
-
CONTEXT_CONFIG_DESC
public static final java.lang.String CONTEXT_CONFIG_DESC
- See Also:
- Constant Field Values
-
CONTEXT_CONFIG_INSCOPE
public static final java.lang.String CONTEXT_CONFIG_INSCOPE
- See Also:
- Constant Field Values
-
CONTEXT_CONFIG_INC_REGEXES
public static final java.lang.String CONTEXT_CONFIG_INC_REGEXES
- See Also:
- Constant Field Values
-
CONTEXT_CONFIG_EXC_REGEXES
public static final java.lang.String CONTEXT_CONFIG_EXC_REGEXES
- See Also:
- Constant Field Values
-
CONTEXT_CONFIG_TECH
public static final java.lang.String CONTEXT_CONFIG_TECH
- See Also:
- Constant Field Values
-
CONTEXT_CONFIG_TECH_INCLUDE
public static final java.lang.String CONTEXT_CONFIG_TECH_INCLUDE
- See Also:
- Constant Field Values
-
CONTEXT_CONFIG_TECH_EXCLUDE
public static final java.lang.String CONTEXT_CONFIG_TECH_EXCLUDE
- See Also:
- Constant Field Values
-
CONTEXT_CONFIG_URLPARSER
public static final java.lang.String CONTEXT_CONFIG_URLPARSER
- See Also:
- Constant Field Values
-
CONTEXT_CONFIG_URLPARSER_CLASS
public static final java.lang.String CONTEXT_CONFIG_URLPARSER_CLASS
- See Also:
- Constant Field Values
-
CONTEXT_CONFIG_URLPARSER_CONFIG
public static final java.lang.String CONTEXT_CONFIG_URLPARSER_CONFIG
- See Also:
- Constant Field Values
-
CONTEXT_CONFIG_POSTPARSER
public static final java.lang.String CONTEXT_CONFIG_POSTPARSER
- See Also:
- Constant Field Values
-
CONTEXT_CONFIG_POSTPARSER_CLASS
public static final java.lang.String CONTEXT_CONFIG_POSTPARSER_CLASS
- See Also:
- Constant Field Values
-
CONTEXT_CONFIG_POSTPARSER_CONFIG
public static final java.lang.String CONTEXT_CONFIG_POSTPARSER_CONFIG
- See Also:
- Constant Field Values
-
CONTEXT_CONFIG_DATA_DRIVEN_NODES
public static final java.lang.String CONTEXT_CONFIG_DATA_DRIVEN_NODES
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
Context
public Context(Session session, int id)
-
-
Method Detail
-
isIncludedInScope
public boolean isIncludedInScope(SiteNode sn)
-
isIncluded
public boolean isIncluded(SiteNode sn)
-
isIncluded
public boolean isIncluded(java.lang.String url)
-
isExcludedFromScope
public boolean isExcludedFromScope(SiteNode sn)
-
isExcluded
public boolean isExcluded(SiteNode sn)
-
isExcluded
public boolean isExcluded(java.lang.String url)
-
isInContext
public boolean isInContext(HistoryReference href)
-
isInContext
public boolean isInContext(SiteNode sn)
-
isInContext
public boolean isInContext(java.lang.String url)
-
getNodesInContextFromSiteTree
public java.util.List<SiteNode> getNodesInContextFromSiteTree()
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
- See Also:
hasNodesInContextFromSiteTree()
-
hasNodesInContextFromSiteTree
public boolean hasNodesInContextFromSiteTree()
Tells whether or not there's at least one node from the sites tree in context.- Returns:
true
if the context has at least one node from the sites tree in context,false
otherwise- Since:
- 2.5.0
- See Also:
getNodesInContextFromSiteTree()
-
getTopNodesInContextFromSiteTree
public java.util.List<SiteNode> getTopNodesInContextFromSiteTree()
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
-
getIncludeInContextRegexs
public java.util.List<java.lang.String> getIncludeInContextRegexs()
-
setIncludeInContextRegexs
public void setIncludeInContextRegexs(java.util.List<java.lang.String> includeRegexs)
Sets the regular expressions used to include a URL in context.- Parameters:
includeRegexs
- the regular expressions- Throws:
java.lang.IllegalArgumentException
- if one of the regular expressions isnull
or empty.java.util.regex.PatternSyntaxException
- if one of the regular expressions is invalid.
-
excludeFromContext
public void excludeFromContext(SiteNode sn, boolean recurse) throws java.lang.Exception
- Throws:
java.lang.Exception
-
excludeFromContext
public void excludeFromContext(StructuralNode sn, boolean recurse) throws java.lang.Exception
- Throws:
java.lang.Exception
-
addIncludeInContextRegex
public void addIncludeInContextRegex(java.lang.String includeRegex)
-
getExcludeFromContextRegexs
public java.util.List<java.lang.String> getExcludeFromContextRegexs()
-
setExcludeFromContextRegexs
public void setExcludeFromContextRegexs(java.util.List<java.lang.String> excludeRegexs)
Sets the regular expressions used to exclude a URL from the context.- Parameters:
excludeRegexs
- the regular expressions- Throws:
java.lang.IllegalArgumentException
- if one of the regular expressions isnull
.java.util.regex.PatternSyntaxException
- if one of the regular expressions is invalid.
-
addExcludeFromContextRegex
public void addExcludeFromContextRegex(java.lang.String excludeRegex)
-
save
public void save()
-
getTechSet
public TechSet getTechSet()
-
setTechSet
public void setTechSet(TechSet techSet)
-
getName
public java.lang.String getName()
Gets the name of the context.- Returns:
- the name of the context, never
null
(since 2.6.0).
-
setName
public void setName(java.lang.String name)
Sets the name of the context.- Parameters:
name
- the new name of the context- Throws:
IllegalContextNameException
- (since 2.6.0) if the given name isnull
or empty.
-
getDescription
public java.lang.String getDescription()
-
setDescription
public void setDescription(java.lang.String description)
-
getIndex
@Deprecated public int getIndex()
Deprecated.(2.9.0) UsegetId()
instead.Returns the ID of theContext
-
getId
public int getId()
Returns the ID of theContext
- Since:
- 2.9.0
-
isInScope
public boolean isInScope()
-
setInScope
public void setInScope(boolean inScope)
-
getAuthenticationMethod
public AuthenticationMethod getAuthenticationMethod()
Gets the authentication method corresponding to this context.- Returns:
- the authentication method
-
setAuthenticationMethod
public void setAuthenticationMethod(AuthenticationMethod authenticationMethod)
Sets the authentication method corresponding to this context.- Parameters:
authenticationMethod
- the new authentication method
-
getSessionManagementMethod
public SessionManagementMethod getSessionManagementMethod()
Gets the session management method corresponding to this context.- Returns:
- the session management method
-
setSessionManagementMethod
public void setSessionManagementMethod(SessionManagementMethod sessionManagementMethod)
Sets the session management method corresponding to this context.- Parameters:
sessionManagementMethod
- the new session management method
-
getAuthorizationDetectionMethod
public AuthorizationDetectionMethod getAuthorizationDetectionMethod()
Gets the authorization detection method corresponding to this context.- Returns:
- the authorization detection method
-
setAuthorizationDetectionMethod
public void setAuthorizationDetectionMethod(AuthorizationDetectionMethod authorizationDetectionMethod)
Sets the authorization detection method corresponding to this context.- Parameters:
authorizationDetectionMethod
- the new authorization detectionmethod
-
getUrlParamParser
public ParameterParser getUrlParamParser()
-
setUrlParamParser
public void setUrlParamParser(ParameterParser paramParser)
-
getPostParamParser
public ParameterParser getPostParamParser()
-
setPostParamParser
public void setPostParamParser(ParameterParser postParamParser)
-
restructureSiteTree
public void restructureSiteTree()
-
getDataDrivenNodes
public java.util.List<StructuralNodeModifier> getDataDrivenNodes()
-
setDataDrivenNodes
public void setDataDrivenNodes(java.util.List<StructuralNodeModifier> dataDrivenNodes)
-
addDataDrivenNodes
public void addDataDrivenNodes(StructuralNodeModifier ddn)
-
getDefaultDDNName
public java.lang.String getDefaultDDNName()
-
getCustomPages
public java.util.List<CustomPage> getCustomPages()
Gets an unmodifiable view of the list of custom pages.- Returns:
- a List of custom pages
-
hasCustomPages
public boolean hasCustomPages()
Returnstrue
if theContext
has Custom Pages.- Returns:
true
if this context has Custom Pages,false
otherwise.
-
hasCustomPageOfType
public boolean hasCustomPageOfType(CustomPage.Type cpType)
Returnstrue
if theContext
has Custom Page definitions of a specificCustomPage.Type
.- Returns:
true
if this context has Custom Pages,false
otherwise.
-
setCustomPages
public void setCustomPages(java.util.List<CustomPage> customPages)
Sets a new list of custom pages for this context. An internal copy of the provided list is stored.- Parameters:
customPages
- the list of custom pages
-
addCustomPage
public void addCustomPage(CustomPage customPage)
Adds a custom page.- Parameters:
customPage
- the custom page being added
-
removeCustomPage
public boolean removeCustomPage(CustomPage customPage)
Removes a custom page.- Parameters:
customPage
- the defaultCustomPage to be removed
-
removeAllCustomPages
public void removeAllCustomPages()
Removes all the custom pages.
-
isCustomPage
public boolean isCustomPage(HttpMessage msg, CustomPage.Type cpType)
Determines if aHttpMessage
is a Custom Page of a particularCustomPage.Type
.- Parameters:
msg
- the HTTP message to be evaluatedcpType
- the CustomPage.Type of the Custom Pages against which the HTTP message should be evaluated- Returns:
true
if the HTTP message is a Custom Page of the type in question,false
otherwise- Since:
- 2.10.0
- See Also:
isCustomPageWithFallback(HttpMessage, org.zaproxy.zap.extension.custompages.CustomPage.Type)
-
isCustomPageWithFallback
public boolean isCustomPageWithFallback(HttpMessage msg, CustomPage.Type cpType)
Determines if aHttpMessage
is a Custom Page of a particularCustomPage.Type
. Falling back to check the message's status code.- Parameters:
msg
- the HTTP message to be evaluatedcpType
- the CustomPage.Type of the Custom Pages against which the HTTP message should be evaluated- Returns:
true
if the HTTP message is a Custom Page of the type in question or the response has a relevant status code (500, 404, etc),false
otherwise- Since:
- 2.10.0
- See Also:
isCustomPage(HttpMessage, org.zaproxy.zap.extension.custompages.CustomPage.Type)
-
duplicate
public Context duplicate()
Creates a copy of the Context. The copy is deep, with the exception of the TechSet.- Returns:
- the context
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
equals
public boolean equals(java.lang.Object obj)
- Overrides:
equals
in classjava.lang.Object
-
-