From 98920f910a9cdb448ce764d2ed5e5e7746cf0e14 Mon Sep 17 00:00:00 2001 From: kingthorin Date: Mon, 31 Oct 2016 21:45:57 -0400 Subject: [PATCH] Custom Pages Initial #15 CustomPage and DefaultCustomPage javadoc additions. --- .../zap/extension/custompages/CustomPage.java | 64 ++++++++++++- .../custompages/DefaultCustomPage.java | 93 ++++++++++++++++++- 2 files changed, 151 insertions(+), 6 deletions(-) diff --git a/src/org/zaproxy/zap/extension/custompages/CustomPage.java b/src/org/zaproxy/zap/extension/custompages/CustomPage.java index fb14bcb2314..9da9caa4729 100644 --- a/src/org/zaproxy/zap/extension/custompages/CustomPage.java +++ b/src/org/zaproxy/zap/extension/custompages/CustomPage.java @@ -4,32 +4,94 @@ public interface CustomPage { + /** + * Returns the context ID for this {@code CustomPage}. + * + * @return the context ID {@code int} + */ int getContextId(); + /** + * Sets the context ID for this {@code CustomPage}. + * + * @param contextId the ID of the context + */ void setContextId(int contextId); + /** + * Returns the content for this {@code CustomPage}. + * + * @return the content {@code String} + */ String getContent(); + /** + * Sets the content for this {@code CustomPage}. + * + * @param content the content being set + */ void setContent(String content); + /** + * Returns the {@link CustomPageContentType} {@code enum} literal for this {@code CustomPage}. + * + * @return the custom page content type {@code CustomPageContentType} + */ CustomPageContentType getContentType(); + /** + * Sets the {@link CustomPageContentType} {@code enum} literal for this {@code CustomPage}. + * + * @param the {@code CustomPageContentType} being set + */ void setContentType(CustomPageContentType cpct); + /** + * Returns {@code true} if the {@link #content} of this {@code CustomPage} is a Regex pattern, otherwise {@code false}. + * + * @return a boolean representing whether or not the {@code content} is a Regex pattern + */ boolean isRegex(); + /** + * Sets a boolean designating whether or not the {@link content} of this {@code CustomPage} is a Regex pattern. + * + * @param regex the state being set + */ void setRegex(boolean regex); + /** + * Returns the {@code enum} literal {@link CustomPageType} of this {@code CustomPage}. + * + * @return the custom page type + */ CustomPageType getType(); + /** + * Sets the {@link CustomPageType} {@code enum} literal for this {@code CustomPage}. + * + * @param the custom page type to be set + */ void setType(CustomPageType cpt); + /** + * Returns the enabled state of this {@code CustomPage}. {@code true} if enabled, {@code false} if not. + * + * @return a boolean representing the enabled state of this {@code CustomPage} + */ boolean isEnabled(); + /** + * Determines if a {@code HttpMessage} is a {@code CustomPage} of a particular {@code CustomPageType}. + * + * @param msg the HTTP message to be evaluated + * @param cpt the CustomPageType of the Custom Pages against which the HTTP message should be evaluated + * @return {@code true} if the HTTP message is a Custom Page of the type in question, {@code false} otherwise + */ boolean isCustomPage(HttpMessage msg, CustomPageType cpt); /** - * Returns a String representation of the custom page object. + * Returns a String representation of the {@code CustomPage} object. */ String toString(); diff --git a/src/org/zaproxy/zap/extension/custompages/DefaultCustomPage.java b/src/org/zaproxy/zap/extension/custompages/DefaultCustomPage.java index a5cdfc4e432..695a8efeea4 100644 --- a/src/org/zaproxy/zap/extension/custompages/DefaultCustomPage.java +++ b/src/org/zaproxy/zap/extension/custompages/DefaultCustomPage.java @@ -22,7 +22,6 @@ import org.apache.commons.codec.binary.Base64; import org.apache.commons.httpclient.URI; import org.apache.log4j.Logger; -import org.parosproxy.paros.model.Model; import org.parosproxy.paros.network.HttpMessage; import org.zaproxy.zap.utils.Enableable; @@ -41,6 +40,16 @@ public class DefaultCustomPage extends Enableable implements CustomPage { private boolean regex; private CustomPageType type; + /** + * Constructs a {@code DefaultCustomPage} with the given details. + * + * @param contextId the context ID for which the {@code DefaultCustomPage} is being created + * @param content the content of the {@code DefaultCustomPage} + * @param contentType the {@link CustomPageContentType} of the {@code DefaultCustomPage} + * @param regex a boolean specifying whether or not the {@code DefaultCustomPage} content is represented by a Regex pattern + * @param type the {@link CustomPageType} of the {@code DefaultCustomPage} + * @param enabled a boolean specifying whether or not the {@code DefaultCustomPage} is enabled or not + */ public DefaultCustomPage(int contextId, String content, CustomPageContentType contentType, boolean regex, CustomPageType type, boolean enabled) { super(); this.contextId = contextId; @@ -51,6 +60,17 @@ public DefaultCustomPage(int contextId, String content, CustomPageContentType co this.setEnabled(enabled); } + /** + * Constructs a {@code DefaultCustomPage} with the given details. + * {@link CustomPageType} and {@link CustomPageContentType} are specified by {@code int} ID instead of {@code enum} literal. + * + * @param contextId the context ID for which the {@code DefaultCustomPage} is being created + * @param content the content of the {@code DefaultCustomPage} + * @param contentTypeID the ID of the {@link CustomPageContentType} of the {@code DefaultCustomPage} + * @param regex a boolean specifying whether or not the {@code DefaultCustomPage} content is represented by a Regex pattern + * @param typeID the ID of the {@link CustomPageType} of the {@code DefaultCustomPage} + * @param enabled a boolean specifying whether or not the {@code DefaultCustomPage} is enabled or not + */ public DefaultCustomPage(int contextId, String content, int contentTypeID, boolean regex, int typeID, boolean enabled) { super(); this.contextId = contextId; @@ -61,56 +81,113 @@ public DefaultCustomPage(int contextId, String content, int contentTypeID, boole this.setEnabled(enabled); } + /** + * Returns the context ID for this {@code DefaultCustomPage}. + * + * @return the context ID {@code int} + */ @Override public int getContextId() { return contextId; } + /** + * Sets the context ID for this {@code DefaultCustomPage}. + * + * @param contextId the ID of the context + */ @Override public void setContextId(int contextId) { this.contextId = contextId; } + /** + * Returns the content for this {@code DefaultCustomPage}. + * + * @return the content {@code String} + */ @Override public String getContent() { return content; } + /** + * Sets the content for this {@code DefaultCustomPage}. + * + * @param content the content being set + */ @Override public void setContent(String content) { this.content = content; } + /** + * Returns the {@link CustomPageContentType} {@code enum} literal for this {@code DefaultCustomPage}. + * + * @return the custom page content type {@code CustomPageContentType} + */ @Override public CustomPageContentType getContentType() { return contentType; } + /** + * Sets the {@link CustomPageContentType} {@code enum} literal for this {@code DefaultCustomPage}. + * + * @param the {@code CustomPageContentType} being set + */ @Override public void setContentType(CustomPageContentType cpct) { this.contentType = cpct; } + /** + * Returns {@code true} if the {@link #content} of this {@code DefaultCustomPage} is a Regex pattern, otherwise {@code false}. + * + * @return a boolean representing whether or not the {@code content} is a Regex pattern + */ @Override public boolean isRegex() { return regex; } + /** + * Sets a boolean designating whether or not the {@link content} of this {@code DefaultCustomPage} is a Regex pattern. + * + * @param regex the state being set + */ @Override public void setRegex(boolean regex) { this.regex = regex; } + /** + * Returns the {@code enum} literal {@link CustomPageType} of this {@code DefaultCustomPage}. + * + * @return the custom page type + */ @Override public CustomPageType getType() { return type; } + /** + * Sets the {@link CustomPageType} {@code enum} literal for this {@code DefaultCustomPage}. + * + * @param the custom page type to be set + */ @Override public void setType(CustomPageType cpt) { this.type = cpt; } + /** + * Determines if a {@code HttpMessage} is a {@code CustomPage} of a particular {@code CustomPageType}. + * + * @param msg the HTTP message to be evaluated + * @param cpt the CustomPageType of the Custom Pages against which the HTTP message should be evaluated + * @return {@code true} if the HTTP message is a Custom Page of the type in question, {@code false} otherwise + */ public boolean isCustomPage(HttpMessage msg, CustomPageType cpt) { URI uri = msg.getRequestHeader().getURI(); @@ -119,7 +196,7 @@ public boolean isCustomPage(HttpMessage msg, CustomPageType cpt) { for (CustomPage cp : ccpm.getCustomPages()) { if (cp.isEnabled()) { if (cp.getType() == cpt) { - if (Model.getSingleton().getSession().getContext(contextId).isIncluded(uri.toString())) { +// if (Model.getSingleton().getSession().getContext(contextId).isIncluded(uri.toString())) { if (cp.isRegex()) { if (cp.getContentType() == CustomPageContentType.URL) { // Handle Regex URL @@ -141,9 +218,9 @@ public boolean isCustomPage(HttpMessage msg, CustomPageType cpt) { } } } - } else { - return false; // URI not in context - } +// } else { +// return false; // URI not in context +// } } else { return false; // Not matching content type } @@ -154,6 +231,11 @@ public boolean isCustomPage(HttpMessage msg, CustomPageType cpt) { return false; // Default } + /** + * This method returns a {@code String} representation of a {@code CustomPage}. + * + * @return a String representing the details of a CustomPage + */ @Override public String toString() { StringBuilder cp = new StringBuilder(); @@ -194,6 +276,7 @@ public static String encode(DefaultCustomPage custompage) { * Decodes a DefaultCustomPage from an encoded string. The string provided as input * should have been obtained through calls to {@link #encode(DefaultCustomPage)}. * + * @param contextId the ID of the context for which the encoded ({@code DefaultCustomPage}) string is being decoded * @param encodedString the encoded string * @return the DefaultCustomPage */