Class Context


  • public class Context
    extends java.lang.Object
    • Field Detail

      • 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​(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 is null 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 is null.
        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 is null 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) Use getId() instead.
        Returns the ID of the Context
      • getId

        public int getId()
        Returns the ID of the Context
        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
      • setUrlParamParser

        public void setUrlParamParser​(ParameterParser paramParser)
      • setPostParamParser

        public void setPostParamParser​(ParameterParser postParamParser)
      • restructureSiteTree

        public void restructureSiteTree()
      • setDataDrivenNodes

        public void setDataDrivenNodes​(java.util.List<StructuralNodeModifier> dataDrivenNodes)
      • 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()
        Returns true if the Context has Custom Pages.
        Returns:
        true if this context has Custom Pages, false otherwise.
      • hasCustomPageOfType

        public boolean hasCustomPageOfType​(CustomPage.Type cpType)
        Returns true if the Context has Custom Page definitions of a specific CustomPage.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.
      • isCustomPageWithFallback

        public boolean isCustomPageWithFallback​(HttpMessage msg,
                                                CustomPage.Type cpType)
        Determines if a HttpMessage is a Custom Page of a particular CustomPage.Type. Falling back to check the message's status code.
        Parameters:
        msg - the HTTP message to be evaluated
        cpType - 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 class java.lang.Object
      • equals

        public boolean equals​(java.lang.Object obj)
        Overrides:
        equals in class java.lang.Object