Search in sources :

Example 6 with Context

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

the class PopupMenuItemContextDataDrivenNode method performAction.

@Override
public void performAction(SiteNode sn) {
    Session session = Model.getSingleton().getSession();
    SessionDialog sessionDialog = View.getSingleton().getSessionDialog();
    sessionDialog.recreateUISharedContexts(session);
    Context uiSharedContext = sessionDialog.getUISharedContext(context.getId());
    // We want to form a regex expression like:
    // https://www.example.com/(aa/bb/cc/)(.+?)(/.*)
    StringBuilder sb = new StringBuilder();
    SiteNode parent = sn.getParent();
    while (!parent.getParent().isRoot()) {
        sb.insert(0, "/");
        if (parent.isDataDriven()) {
            // Don't want these in their own regex group
            sb.insert(0, ".+?");
        } else {
            sb.insert(0, parent.getCleanNodeName());
        }
        parent = parent.getParent();
    }
    sb.insert(0, "/(");
    sb.insert(0, parent.getCleanNodeName());
    sb.append(")(.+?)(/.*)");
    Pattern p = Pattern.compile(sb.toString());
    uiSharedContext.addDataDrivenNodes(new StructuralNodeModifier(StructuralNodeModifier.Type.DataDrivenNode, p, uiSharedContext.getDefaultDDNName()));
    // Show the session dialog without recreating UI Shared contexts
    View.getSingleton().showSessionDialog(session, ContextStructurePanel.getPanelName(context.getId()), false);
}
Also used : Context(org.zaproxy.zap.model.Context) Pattern(java.util.regex.Pattern) StructuralNodeModifier(org.zaproxy.zap.model.StructuralNodeModifier) SessionDialog(org.parosproxy.paros.view.SessionDialog) Session(org.parosproxy.paros.model.Session) SiteNode(org.parosproxy.paros.model.SiteNode)

Example 7 with Context

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

the class PopupMenuItemContextInclude 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 = createPopupIncludeInContextMenu(context);
        piicm.setMenuIndex(this.getMenuIndex());
        mainPopupMenuItems.add(piicm);
        this.subMenus.add(piicm);
    }
    // Add the 'new context' menu
    ExtensionPopupMenuItem piicm = createPopupIncludeInContextMenu();
    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 8 with Context

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

the class AbstractContextSelectToolbarStatusPanel method getContextSelectComboBox.

/**
 * Gets the Context select combo box.
 *
 * @return the context select combo box
 */
protected ContextSelectComboBox getContextSelectComboBox() {
    if (contextSelectBox == null) {
        contextSelectBox = new ContextSelectComboBox();
        contextSelectBox.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                contextSelected((Context) contextSelectBox.getSelectedItem());
            }
        });
    }
    return contextSelectBox;
}
Also used : Context(org.zaproxy.zap.model.Context) ActionListener(java.awt.event.ActionListener) ActionEvent(java.awt.event.ActionEvent) ContextSelectComboBox(org.zaproxy.zap.view.widgets.ContextSelectComboBox)

Example 9 with Context

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

the class PopupUserMenuItemHolder 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 users
    Session session = Model.getSingleton().getSession();
    List<Context> contexts = session.getContexts();
    for (Context context : contexts) {
        ContextUserAuthManager manager = extensionUserAuth.getContextUserAuthManager(context.getId());
        for (User user : manager.getUsers()) {
            ExtensionPopupMenuItem piicm;
            if (visibleItself) {
                piicm = getPopupUserMenu(context, user, this.getText());
                this.add(piicm);
            } else {
                piicm = getPopupUserMenu(context, user, this.parentName);
                piicm.setMenuIndex(this.getMenuIndex());
                mainPopupMenuItems.add(piicm);
                subMenuItems.add(piicm);
            }
        }
    }
}
Also used : Context(org.zaproxy.zap.model.Context) ExtensionPopupMenuItem(org.parosproxy.paros.extension.ExtensionPopupMenuItem) User(org.zaproxy.zap.users.User) ContextUserAuthManager(org.zaproxy.zap.extension.users.ContextUserAuthManager) JMenuItem(javax.swing.JMenuItem) Session(org.parosproxy.paros.model.Session)

Example 10 with Context

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

the class UsersAPI method handleApiView.

@Override
public ApiResponse handleApiView(String name, JSONObject params) throws ApiException {
    log.debug("handleApiView " + name + " " + params.toString());
    switch(name) {
        case VIEW_USERS_LIST:
            ApiResponseList usersListResponse = new ApiResponseList(name);
            // Get the users
            List<User> users;
            if (hasContextId(params))
                users = extension.getContextUserAuthManager(getContextId(params)).getUsers();
            else {
                users = new ArrayList<>();
                for (Context c : Model.getSingleton().getSession().getContexts()) users.addAll(extension.getContextUserAuthManager(c.getId()).getUsers());
            }
            // Prepare the response
            for (User user : users) usersListResponse.addItem(buildResponseFromUser(user));
            return usersListResponse;
        case VIEW_GET_USER_BY_ID:
            return buildResponseFromUser(getUser(params));
        case VIEW_GET_AUTH_CREDENTIALS:
            return getUser(params).getAuthenticationCredentials().getApiResponseRepresentation();
        case VIEW_GET_AUTH_CREDENTIALS_CONFIG_PARAMETERS:
            AuthenticationMethodType type = ApiUtils.getContextByParamId(params, PARAM_CONTEXT_ID).getAuthenticationMethod().getType();
            ApiDynamicActionImplementor a = loadedAuthenticationMethodActions.get(type.getUniqueIdentifier());
            return a.buildParamsDescription();
        case VIEW_GET_AUTH_STATE:
            return buildResponseFromAuthState(getUser(params).getAuthenticationState());
        case VIEW_GET_AUTH_SESSION:
            return buildResponseFromAuthSession(getUser(params).getAuthenticatedSession());
        default:
            throw new ApiException(ApiException.Type.BAD_VIEW);
    }
}
Also used : Context(org.zaproxy.zap.model.Context) ApiDynamicActionImplementor(org.zaproxy.zap.extension.api.ApiDynamicActionImplementor) AuthenticationMethodType(org.zaproxy.zap.authentication.AuthenticationMethodType) User(org.zaproxy.zap.users.User) ApiResponseList(org.zaproxy.zap.extension.api.ApiResponseList) ApiException(org.zaproxy.zap.extension.api.ApiException)

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