Skip to content

Commit

Permalink
Custom Pages Initial zaproxy#15
Browse files Browse the repository at this point in the history
CustomPage and DefaultCustomPage javadoc additions.
  • Loading branch information
kingthorin committed Apr 9, 2017
1 parent 9b7f841 commit 98920f9
Show file tree
Hide file tree
Showing 2 changed files with 151 additions and 6 deletions.
64 changes: 63 additions & 1 deletion src/org/zaproxy/zap/extension/custompages/CustomPage.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
93 changes: 88 additions & 5 deletions src/org/zaproxy/zap/extension/custompages/DefaultCustomPage.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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();

Expand All @@ -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
Expand All @@ -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
}
Expand All @@ -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();
Expand Down Expand Up @@ -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
*/
Expand Down

0 comments on commit 98920f9

Please sign in to comment.