Search in sources :

Example 76 with Context

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

the class PopupMenuItemContextDataDriven method reCreateSubMenu.

protected void reCreateSubMenu(SiteNode sn) {
    final List<JMenuItem> mainPopupMenuItems = View.getSingleton().getPopupList();
    for (ExtensionPopupMenuItem menu : subMenus) {
        mainPopupMenuItems.remove(menu);
    }
    subMenus.clear();
    Session session = Model.getSingleton().getSession();
    List<Context> contexts = session.getContexts();
    for (Context context : contexts) {
        if (context.isIncluded(sn)) {
            ExtensionPopupMenuItem piicm = createPopupDataDrivenNodeMenu(context);
            piicm.setMenuIndex(this.getMenuIndex());
            mainPopupMenuItems.add(piicm);
            this.subMenus.add(piicm);
        }
    }
}
Also used : Context(org.zaproxy.zap.model.Context) ExtensionPopupMenuItem(org.parosproxy.paros.extension.ExtensionPopupMenuItem) JMenuItem(javax.swing.JMenuItem) Session(org.parosproxy.paros.model.Session)

Example 77 with Context

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

the class PopupMenuItemContextExclude method reCreateSubMenu.

protected void reCreateSubMenu() {
    final List<JMenuItem> mainPopupMenuItems = View.getSingleton().getPopupList();
    for (ExtensionPopupMenuItem menu : subMenus) {
        mainPopupMenuItems.remove(menu);
    }
    subMenus.clear();
    Session session = Model.getSingleton().getSession();
    List<Context> contexts = session.getContexts();
    for (Context context : contexts) {
        ExtensionPopupMenuItem piicm = createPopupExcludeFromContextMenu(context);
        piicm.setMenuIndex(this.getMenuIndex());
        mainPopupMenuItems.add(piicm);
        this.subMenus.add(piicm);
    }
}
Also used : Context(org.zaproxy.zap.model.Context) ExtensionPopupMenuItem(org.parosproxy.paros.extension.ExtensionPopupMenuItem) JMenuItem(javax.swing.JMenuItem) Session(org.parosproxy.paros.model.Session)

Example 78 with Context

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

the class ContextSelectComboBox method reloadContexts.

/**
 * Reloads/refreshes the list of {@link Context Contexts} from the {@link Session}.
 *
 * @param keepSelected whether the previously selected context is tried to be restored. If
 *     {@code false}, defaults to no selection.
 */
public void reloadContexts(boolean keepSelected) {
    Context selected = null;
    if (keepSelected)
        selected = (Context) getSelectedItem();
    List<Context> contexts = Model.getSingleton().getSession().getContexts();
    Context[] contextsArray = contexts.toArray(new Context[contexts.size()]);
    ComboBoxModel<Context> model = new DefaultComboBoxModel<>(contextsArray);
    // No matter what, set selected item, so it either defaults to 'nothing selected' or
    // restores the previously selected item
    model.setSelectedItem(selected);
    this.setModel(model);
}
Also used : Context(org.zaproxy.zap.model.Context) DefaultComboBoxModel(javax.swing.DefaultComboBoxModel)

Example 79 with Context

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

the class ExtensionSessionManagementUnitTest method shouldImportContextWithScriptSessionMgmtType.

@Test
void shouldImportContextWithScriptSessionMgmtType() throws ConfigurationException {
    // Given
    Context context = mock(Context.class);
    Configuration config = new ZapXmlConfiguration();
    int sessMgmtTypeId = 2;
    config.addProperty(ExtensionSessionManagement.CONTEXT_CONFIG_SESSION_TYPE, sessMgmtTypeId);
    // When
    extSessMgmt.importContextData(context, config);
    // Then
    verify(context).setSessionManagementMethod(any(ScriptBasedSessionManagementMethod.class));
}
Also used : Context(org.zaproxy.zap.model.Context) ScriptBasedSessionManagementMethod(org.zaproxy.zap.session.ScriptBasedSessionManagementMethodType.ScriptBasedSessionManagementMethod) Configuration(org.apache.commons.configuration.Configuration) ZapXmlConfiguration(org.zaproxy.zap.utils.ZapXmlConfiguration) ZapXmlConfiguration(org.zaproxy.zap.utils.ZapXmlConfiguration) Test(org.junit.jupiter.api.Test) WithConfigsTest(org.zaproxy.zap.WithConfigsTest)

Example 80 with Context

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

the class ExtensionSessionManagementUnitTest method shouldImportContextWithUnknownSessionMgmtType.

@Test
void shouldImportContextWithUnknownSessionMgmtType() throws ConfigurationException {
    // Given
    Context context = mock(Context.class);
    Configuration config = new ZapXmlConfiguration();
    int sessMgmtTypeId = 100;
    config.addProperty(ExtensionSessionManagement.CONTEXT_CONFIG_SESSION_TYPE, sessMgmtTypeId);
    // When
    extSessMgmt.importContextData(context, config);
    // Then
    verify(context, times(0)).setSessionManagementMethod(any());
}
Also used : Context(org.zaproxy.zap.model.Context) Configuration(org.apache.commons.configuration.Configuration) ZapXmlConfiguration(org.zaproxy.zap.utils.ZapXmlConfiguration) ZapXmlConfiguration(org.zaproxy.zap.utils.ZapXmlConfiguration) Test(org.junit.jupiter.api.Test) WithConfigsTest(org.zaproxy.zap.WithConfigsTest)

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