Search in sources :

Example 61 with Context

use of org.zaproxy.zap.model.Context in project zaproxy by zaproxy.

the class SpiderDialog method targetSelected.

@Override
public void targetSelected(String field, Target node) {
    List<String> ctxNames = new ArrayList<>();
    if (node != null) {
        // The user has selected a new node
        this.target = node;
        if (node.getStartNode() != null) {
            Session session = Model.getSingleton().getSession();
            List<Context> contexts = session.getContextsForNode(node.getStartNode());
            for (Context context : contexts) {
                ctxNames.add(context.getName());
            }
        } else if (node.getContext() != null) {
            ctxNames.add(node.getContext().getName());
        }
    }
    this.setComboFields(FIELD_CONTEXT, ctxNames, "");
    this.getField(FIELD_CONTEXT).setEnabled(ctxNames.size() > 0);
}
Also used : Context(org.zaproxy.zap.model.Context) ArrayList(java.util.ArrayList) Session(org.parosproxy.paros.model.Session)

Example 62 with Context

use of org.zaproxy.zap.model.Context in project zaproxy by zaproxy.

the class SessionManagementAPI method getContext.

/**
 * Gets the context from the parameters or throws a Missing Parameter exception, if any problems
 * occurred.
 *
 * @param params the params
 * @return the context
 * @throws ApiException the api exception
 */
private Context getContext(JSONObject params) throws ApiException {
    int contextId = getContextId(params);
    Context context = Model.getSingleton().getSession().getContext(contextId);
    if (context == null)
        throw new ApiException(Type.CONTEXT_NOT_FOUND, PARAM_CONTEXT_ID);
    return context;
}
Also used : Context(org.zaproxy.zap.model.Context) ApiException(org.zaproxy.zap.extension.api.ApiException)

Example 63 with Context

use of org.zaproxy.zap.model.Context in project zaproxy by zaproxy.

the class SessionManagementAPI method handleApiAction.

@Override
public ApiResponse handleApiAction(String name, JSONObject params) throws ApiException {
    log.debug("handleApiAction " + name + " " + params.toString());
    switch(name) {
        case ACTION_SET_METHOD:
            // Prepare the params
            JSONObject actionParams;
            if (params.has(PARAM_METHOD_CONFIG_PARAMS))
                actionParams = API.getParams(params.getString(PARAM_METHOD_CONFIG_PARAMS));
            else
                actionParams = new JSONObject();
            Context context = getContext(params);
            actionParams.put(PARAM_CONTEXT_ID, context.getId());
            // Run the method
            getSetMethodActionImplementor(params).handleAction(actionParams);
            context.save();
            return ApiResponseElement.OK;
        default:
            throw new ApiException(Type.BAD_ACTION);
    }
}
Also used : Context(org.zaproxy.zap.model.Context) JSONObject(net.sf.json.JSONObject) ApiException(org.zaproxy.zap.extension.api.ApiException)

Example 64 with Context

use of org.zaproxy.zap.model.Context in project zaproxy by zaproxy.

the class ExtensionStdMenus method getPopupContextTreeMenuExport.

private PopupContextTreeMenu getPopupContextTreeMenuExport() {
    if (popupContextTreeMenuExport == null) {
        popupContextTreeMenuExport = new PopupContextTreeMenu(false);
        popupContextTreeMenuExport.setText(Constant.messages.getString("menu.file.context.export"));
        popupContextTreeMenuExport.setIcon(DisplayUtils.getScaledIcon(new ImageIcon(ExtensionStdMenus.class.getResource("/resource/icon/fugue/application-blue-export.png"))));
        popupContextTreeMenuExport.addActionListener(new java.awt.event.ActionListener() {

            @Override
            public void actionPerformed(java.awt.event.ActionEvent e) {
                Context context = Model.getSingleton().getSession().getContext(popupContextTreeMenuExport.getContextId());
                ContextExportDialog exportDialog = new ContextExportDialog(getView().getMainFrame());
                exportDialog.setSelectedContext(context);
                exportDialog.setVisible(true);
            }
        });
    }
    return popupContextTreeMenuExport;
}
Also used : Context(org.zaproxy.zap.model.Context) ImageIcon(javax.swing.ImageIcon) ContextExportDialog(org.zaproxy.zap.view.ContextExportDialog)

Example 65 with Context

use of org.zaproxy.zap.model.Context in project zaproxy by zaproxy.

the class PopupContextMenuItemHolder method resetMenu.

private void resetMenu() {
    final List<JMenuItem> mainPopupMenuItems = View.getSingleton().getPopupList();
    // Remove existing popup menu items
    if (visibleItself)
        this.removeAll();
    else {
        for (ExtensionPopupMenuItem menu : getSubmenuItems()) {
            mainPopupMenuItems.remove(menu);
        }
        subMenuItems.clear();
    }
    // Add a popup menu item for each existing context
    Session session = Model.getSingleton().getSession();
    List<Context> contexts = session.getContexts();
    for (Context context : contexts) {
        ExtensionPopupMenuItem piicm;
        if (visibleItself) {
            piicm = getPopupContextMenu(context, this.getText());
            this.add(piicm);
        } else {
            piicm = getPopupContextMenu(context, this.parentName);
            piicm.setMenuIndex(this.getMenuIndex());
            mainPopupMenuItems.add(piicm);
            subMenuItems.add(piicm);
        }
    }
}
Also used : PopupMenuItemContext(org.zaproxy.zap.view.popup.PopupMenuItemContext) 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