Search in sources :

Example 66 with Context

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

the class PopupContextMenuItemFactory method isEnableForComponent.

@Override
public boolean isEnableForComponent(Component invoker) {
    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)

Example 67 with Context

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

the class NodeSelectDialog method populateContexts.

private void populateContexts(SiteNode root) {
    // Uncomment to hide contexts tree if there are no valid contexts -
    // not sure if this is a good idea or not :/
    // int contexts = 0;
    int contextsInScope = 0;
    for (Context ctx : Model.getSingleton().getSession().getContexts()) {
        // TODO ignore handle protected mode?
        if (ctx.getIncludeInContextRegexs().size() > 0) {
            SiteNode node = new SiteNode(null, HistoryReference.TYPE_PROXIED, ctx.getName());
            node.setUserObject(new Target(ctx));
            root.add(node);
            // contexts ++;
            if (ctx.isInScope()) {
                contextsInScope++;
            }
        }
    }
    if (contextsInScope > 1) {
        // Allow user to choose everything in scope
        SiteNode node = new SiteNode(null, HistoryReference.TYPE_PROXIED, Constant.messages.getString("context.allInScope"));
        node.setUserObject(new Target(null, null, true, true));
        root.add(node);
    }
    // this.getTreeContext().setVisible(contexts > 0);
    this.getTreeContext().expandRow(0);
}
Also used : Context(org.zaproxy.zap.model.Context) Target(org.zaproxy.zap.model.Target) SiteNode(org.parosproxy.paros.model.SiteNode)

Example 68 with Context

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

the class ExtensionAuthenticationUnitTest method shouldImportAllAuthContextData.

@Test
void shouldImportAllAuthContextData() throws ConfigurationException {
    // Given
    Context context = new Context(null, 0);
    String loggedInIndicator = "logged in";
    String loggedOutIndicator = "logged out";
    String pollUrl = "https://www.example.com/poll";
    String pollData = "example-poll-data";
    String pollHeaders = "aaa : bbb\\Nccc : ddd";
    int pollFreq = 55;
    Configuration config = new ZapXmlConfiguration();
    config.setProperty(AuthenticationMethod.CONTEXT_CONFIG_AUTH_TYPE, 2);
    config.setProperty(AuthenticationMethod.CONTEXT_CONFIG_AUTH_STRATEGY, AuthCheckingStrategy.POLL_URL.name());
    config.setProperty(AuthenticationMethod.CONTEXT_CONFIG_AUTH_POLL_URL, pollUrl);
    config.setProperty(AuthenticationMethod.CONTEXT_CONFIG_AUTH_POLL_DATA, pollData);
    config.setProperty(AuthenticationMethod.CONTEXT_CONFIG_AUTH_POLL_HEADERS, pollHeaders);
    config.setProperty(AuthenticationMethod.CONTEXT_CONFIG_AUTH_POLL_FREQ, pollFreq);
    config.setProperty(AuthenticationMethod.CONTEXT_CONFIG_AUTH_POLL_UNITS, AuthPollFrequencyUnits.REQUESTS.name());
    config.setProperty(AuthenticationMethod.CONTEXT_CONFIG_AUTH_LOGGEDIN, loggedInIndicator);
    config.setProperty(AuthenticationMethod.CONTEXT_CONFIG_AUTH_LOGGEDOUT, loggedOutIndicator);
    ExtensionHook hook = new ExtensionHook(Model.getSingleton(), null);
    extensionAuthentication.hook(hook);
    // When
    extensionAuthentication.importContextData(context, config);
    AuthenticationMethod method = context.getAuthenticationMethod();
    // Then
    assertThat(method.getClass().getCanonicalName(), is(FormBasedAuthenticationMethod.class.getCanonicalName()));
    assertThat(method.getAuthCheckingStrategy(), is(AuthCheckingStrategy.POLL_URL));
    assertThat(method.getPollUrl(), is(pollUrl));
    assertThat(method.getPollData(), is(pollData));
    assertThat(method.getPollHeaders(), is(pollHeaders));
    assertThat(method.getPollFrequencyUnits(), is(AuthPollFrequencyUnits.REQUESTS));
    assertThat(method.getPollFrequency(), is(pollFreq));
    assertThat(method.getLoggedInIndicatorPattern().toString(), is(loggedInIndicator));
    assertThat(method.getLoggedOutIndicatorPattern().toString(), is(loggedOutIndicator));
}
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) ExtensionHook(org.parosproxy.paros.extension.ExtensionHook) FormBasedAuthenticationMethod(org.zaproxy.zap.authentication.FormBasedAuthenticationMethodType.FormBasedAuthenticationMethod) AuthenticationMethod(org.zaproxy.zap.authentication.AuthenticationMethod) Test(org.junit.jupiter.api.Test) WithConfigsTest(org.zaproxy.zap.WithConfigsTest)

Example 69 with Context

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

the class ExtensionAuthenticationUnitTest method shouldImportContextWithNoPollData.

@Test
void shouldImportContextWithNoPollData() throws ConfigurationException {
    // Given
    Context context = new Context(null, 0);
    String loggedInIndicator = "logged in";
    String loggedOutIndicator = "logged out";
    Configuration config = new ZapXmlConfiguration();
    config.setProperty(AuthenticationMethod.CONTEXT_CONFIG_AUTH_TYPE, 2);
    config.setProperty(AuthenticationMethod.CONTEXT_CONFIG_AUTH_LOGGEDIN, loggedInIndicator);
    config.setProperty(AuthenticationMethod.CONTEXT_CONFIG_AUTH_LOGGEDOUT, loggedOutIndicator);
    ExtensionHook hook = new ExtensionHook(Model.getSingleton(), null);
    extensionAuthentication.hook(hook);
    // When
    extensionAuthentication.importContextData(context, config);
    AuthenticationMethod method = context.getAuthenticationMethod();
    // Then
    assertThat(method.getClass().getCanonicalName(), is(FormBasedAuthenticationMethod.class.getCanonicalName()));
    assertThat(method.getAuthCheckingStrategy(), is(AuthCheckingStrategy.EACH_RESP));
    assertThat(method.getLoggedInIndicatorPattern().toString(), is(loggedInIndicator));
    assertThat(method.getLoggedOutIndicatorPattern().toString(), is(loggedOutIndicator));
}
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) ExtensionHook(org.parosproxy.paros.extension.ExtensionHook) FormBasedAuthenticationMethod(org.zaproxy.zap.authentication.FormBasedAuthenticationMethodType.FormBasedAuthenticationMethod) AuthenticationMethod(org.zaproxy.zap.authentication.AuthenticationMethod) Test(org.junit.jupiter.api.Test) WithConfigsTest(org.zaproxy.zap.WithConfigsTest)

Example 70 with Context

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

the class ExtensionAuthenticationUnitTest method shouldImportContextWithUnknownAuthenticationMethod.

@Test
void shouldImportContextWithUnknownAuthenticationMethod() throws ConfigurationException {
    // Given
    Context context = mock(Context.class);
    Configuration config = new ZapXmlConfiguration();
    config.setProperty("context.authentication.type", Integer.MIN_VALUE);
    // When
    extensionAuthentication.importContextData(context, config);
    // Then
    verify(context, times(0)).setAuthenticationMethod(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