Search in sources :

Example 51 with Context

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

the class SiteMapPanel method reloadContextTree.

public void reloadContextTree() {
    SiteNode root;
    if (this.contextTree == null) {
        root = new SiteNode(null, -1, Constant.messages.getString("context.list"));
        this.contextTree = new DefaultTreeModel(root);
    } else {
        root = (SiteNode) this.contextTree.getRoot();
        root.removeAllChildren();
    }
    for (Context ctx : Model.getSingleton().getSession().getContexts()) {
        if (ctx.isInScope() || !this.getScopeButton().isSelected()) {
            // Add all in scope contexts, and out of scope ones if scope button not pressed
            SiteNode node = new SiteNode(null, HistoryReference.TYPE_PROXIED, ctx.getName());
            node.setUserObject(new Target(ctx));
            root.add(node);
        }
    }
    this.contextTree.nodeStructureChanged(root);
}
Also used : Context(org.zaproxy.zap.model.Context) Target(org.zaproxy.zap.model.Target) DefaultTreeModel(javax.swing.tree.DefaultTreeModel) SiteNode(org.parosproxy.paros.model.SiteNode)

Example 52 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<String>();
    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 53 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.getIndex());
            // 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 54 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
	 * occured.
	 * 
	 * @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 55 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();
        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(View.getSingleton().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)

Aggregations

Context (org.zaproxy.zap.model.Context)59 ApiException (org.zaproxy.zap.extension.api.ApiException)19 Session (org.parosproxy.paros.model.Session)14 User (org.zaproxy.zap.users.User)14 JSONObject (net.sf.json.JSONObject)12 ApiDynamicActionImplementor (org.zaproxy.zap.extension.api.ApiDynamicActionImplementor)11 RecordContext (org.parosproxy.paros.db.RecordContext)9 ArrayList (java.util.ArrayList)8 DatabaseException (org.parosproxy.paros.db.DatabaseException)8 JMenuItem (javax.swing.JMenuItem)7 ConfigurationException (org.apache.commons.configuration.ConfigurationException)7 ExtensionPopupMenuItem (org.parosproxy.paros.extension.ExtensionPopupMenuItem)7 ApiResponseElement (org.zaproxy.zap.extension.api.ApiResponseElement)6 ExtensionUserManagement (org.zaproxy.zap.extension.users.ExtensionUserManagement)6 JSONException (net.sf.json.JSONException)4 URIException (org.apache.commons.httpclient.URIException)4 SiteNode (org.parosproxy.paros.model.SiteNode)4 SessionDialog (org.parosproxy.paros.view.SessionDialog)4 Tech (org.zaproxy.zap.model.Tech)4 IOException (java.io.IOException)3