Search in sources :

Example 71 with Context

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;
}
Also used : Context(org.zaproxy.zap.model.Context) RecordContext(org.parosproxy.paros.db.RecordContext)

Example 72 with Context

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;
}
Also used : Context(org.zaproxy.zap.model.Context) RecordContext(org.parosproxy.paros.db.RecordContext)

Example 73 with 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;
}
Also used : Context(org.zaproxy.zap.model.Context) Tech(org.zaproxy.zap.model.Tech) TechSet(org.zaproxy.zap.model.TechSet) HashSet(java.util.HashSet) SiteNode(org.parosproxy.paros.model.SiteNode)

Example 74 with Context

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);
}
Also used : Context(org.zaproxy.zap.model.Context) Session(org.parosproxy.paros.model.Session)

Example 75 with Context

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;
}
Also used : Context(org.zaproxy.zap.model.Context) ExtensionPopupMenuItem(org.parosproxy.paros.extension.ExtensionPopupMenuItem) JMenuItem(javax.swing.JMenuItem) Session(org.parosproxy.paros.model.Session)

Aggregations

Context (org.zaproxy.zap.model.Context)89 ApiException (org.zaproxy.zap.extension.api.ApiException)22 Test (org.junit.jupiter.api.Test)21 ZapXmlConfiguration (org.zaproxy.zap.utils.ZapXmlConfiguration)17 WithConfigsTest (org.zaproxy.zap.WithConfigsTest)16 User (org.zaproxy.zap.users.User)15 JSONObject (net.sf.json.JSONObject)14 Configuration (org.apache.commons.configuration.Configuration)14 Session (org.parosproxy.paros.model.Session)14 ApiDynamicActionImplementor (org.zaproxy.zap.extension.api.ApiDynamicActionImplementor)13 RecordContext (org.parosproxy.paros.db.RecordContext)12 DatabaseException (org.parosproxy.paros.db.DatabaseException)10 ConfigurationException (org.apache.commons.configuration.ConfigurationException)9 HttpMessage (org.parosproxy.paros.network.HttpMessage)9 ExtensionUserManagement (org.zaproxy.zap.extension.users.ExtensionUserManagement)9 ArrayList (java.util.ArrayList)8 JMenuItem (javax.swing.JMenuItem)7 ExtensionPopupMenuItem (org.parosproxy.paros.extension.ExtensionPopupMenuItem)7 SiteNode (org.parosproxy.paros.model.SiteNode)7 IOException (java.io.IOException)6