use of org.zaproxy.zap.model.Context in project zaproxy by zaproxy.
the class Session method getNewContext.
/**
* Gets a newly created context with the given name.
*
* <p>The context is automatically added to the session.
*
* @param name the name of the context
* @return the new {@code Context}.
* @throws IllegalContextNameException (since 2.6.0) if the given name is {@code null} or empty
* or if a context with the given name already exists.
*/
public Context getNewContext(String name) {
validateContextName(name);
Context c = createContext(name);
this.addContext(c);
return c;
}
use of org.zaproxy.zap.model.Context in project zaproxy by zaproxy.
the class Session method createContext.
/**
* Creates a new context with the given name.
*
* @param name the name of the context
* @return the new {@code Context}.
* @see #getNewContext(String)
*/
private Context createContext(String name) {
Context context = new Context(this, this.nextContextId++);
context.setName(name);
return context;
}
use of org.zaproxy.zap.model.Context in project zaproxy by zaproxy.
the class ContextAPI method handleApiView.
@Override
public ApiResponse handleApiView(String name, JSONObject params) throws ApiException {
log.debug("handleApiView " + name + " " + params.toString());
ApiResponse result;
ApiResponseList resultList;
TechSet techSet;
switch(name) {
case VIEW_EXCLUDE_REGEXS:
resultList = new ApiResponseList(name);
for (String regex : getContext(params).getExcludeFromContextRegexs()) {
resultList.addItem(new ApiResponseElement(REGEX_PARAM, regex));
}
result = resultList;
break;
case VIEW_INCLUDE_REGEXS:
resultList = new ApiResponseList(name);
for (String regex : getContext(params).getIncludeInContextRegexs()) {
resultList.addItem(new ApiResponseElement(REGEX_PARAM, regex));
}
result = resultList;
break;
case VIEW_CONTEXT_LIST:
resultList = new ApiResponseList(name);
for (Context context : Model.getSingleton().getSession().getContexts()) {
resultList.addItem(new ApiResponseElement(CONTEXT_NAME, context.getName()));
}
result = resultList;
break;
case VIEW_CONTEXT:
result = new ApiResponseElement(buildResponseFromContext(getContext(params)));
break;
case VIEW_ALL_TECHS:
resultList = new ApiResponseList(name);
for (Tech tech : Tech.getAll()) {
resultList.addItem(new ApiResponseElement(TECH_NAME, tech.toString()));
}
result = resultList;
break;
case VIEW_INCLUDED_TECHS:
resultList = new ApiResponseList(name);
techSet = getContext(params).getTechSet();
for (Tech tech : techSet.getIncludeTech()) {
resultList.addItem(new ApiResponseElement(TECH_NAME, tech.toString()));
}
result = resultList;
break;
case VIEW_EXCLUDED_TECHS:
resultList = new ApiResponseList(name);
techSet = getContext(params).getTechSet();
for (Tech tech : techSet.getExcludeTech()) {
resultList.addItem(new ApiResponseElement(TECH_NAME, tech.toString()));
}
result = resultList;
break;
case VIEW_URLS:
resultList = new ApiResponseList(name);
Set<String> addedUrls = new HashSet<>();
for (SiteNode node : getContext(params).getNodesInContextFromSiteTree()) {
String uri = node.getHistoryReference().getURI().toString();
if (!addedUrls.contains(uri)) {
resultList.addItem(new ApiResponseElement("url", uri));
addedUrls.add(uri);
}
}
result = resultList;
break;
default:
throw new ApiException(Type.BAD_VIEW);
}
return result;
}
use of org.zaproxy.zap.model.Context in project zaproxy by zaproxy.
the class PopupMenuItemIncludeInContext method performAction.
protected void performAction(String name, String url) {
if (context == null) {
Session session = Model.getSingleton().getSession();
context = session.getNewContext(name);
recreateUISharedContexts(session);
}
Context uiSharedContext = View.getSingleton().getSessionDialog().getUISharedContext(context.getId());
uiSharedContext.addIncludeInContextRegex(url);
}
use of org.zaproxy.zap.model.Context in project zaproxy by zaproxy.
the class PopupMenuItemSiteNodeContextMenuFactory method isButtonEnabledForSiteNode.
@Override
public boolean isButtonEnabledForSiteNode(SiteNode sn) {
final List<JMenuItem> mainPopupMenuItems = View.getSingleton().getPopupList();
for (ExtensionPopupMenuItem menu : subMenus) {
mainPopupMenuItems.remove(menu);
}
subMenus.clear();
// Add the existing contexts
Session session = Model.getSingleton().getSession();
List<Context> contexts = session.getContexts();
for (Context context : contexts) {
ExtensionPopupMenuItem piicm = getContextMenu(context, this.parentMenu);
piicm.setMenuIndex(this.getMenuIndex());
mainPopupMenuItems.add(piicm);
this.subMenus.add(piicm);
}
return false;
}
Aggregations