Search in sources :

Example 6 with Session

use of org.parosproxy.paros.model.Session in project zaproxy by zaproxy.

the class SessionStructure method getRootNode.

/**
 * Returns the root node
 *
 * @param model the model
 * @return the root node
 */
public static StructuralNode getRootNode(Model model) {
    if (!Constant.isLowMemoryOptionSet()) {
        return new StructuralSiteNode(model.getSession().getSiteTree().getRoot());
    }
    Session session = model.getSession();
    RecordStructure rs;
    try {
        rs = model.getDb().getTableStructure().find(session.getSessionId(), ROOT, HttpRequestHeader.GET);
        if (rs != null) {
            return new StructuralTableNode(rs);
        }
    } catch (DatabaseException e) {
        log.error(e.getMessage(), e);
    }
    return null;
}
Also used : RecordStructure(org.parosproxy.paros.db.RecordStructure) DatabaseException(org.parosproxy.paros.db.DatabaseException) Session(org.parosproxy.paros.model.Session)

Example 7 with Session

use of org.parosproxy.paros.model.Session in project zaproxy by zaproxy.

the class SessionStructure method addStructure.

private static RecordStructure addStructure(Model model, String host, HttpMessage msg, List<String> paths, int size, int historyId, boolean newOnly) throws DatabaseException, URIException {
    // String nodeUrl = pathsToUrl(host, paths, size);
    Session session = model.getSession();
    String nodeName = getNodeName(session, host, msg, paths, size);
    String parentName = pathsToUrl(host, paths, size - 1);
    String url = "";
    if (msg != null) {
        url = msg.getRequestHeader().getURI().toString();
        String params = getParams(session, msg);
        if (params.length() > 0) {
            nodeName = nodeName + " " + params;
        }
    }
    String method = HttpRequestHeader.GET;
    if (msg != null) {
        method = msg.getRequestHeader().getMethod();
    }
    RecordStructure msgRs = model.getDb().getTableStructure().find(session.getSessionId(), nodeName, method);
    if (msgRs == null) {
        long parentId = -1;
        if (!nodeName.equals(ROOT)) {
            HttpMessage tmpMsg = null;
            int parentHistoryId = -1;
            if (!parentName.equals(ROOT)) {
                tmpMsg = getTempHttpMessage(session, parentName, msg);
                parentHistoryId = tmpMsg.getHistoryRef().getHistoryId();
            }
            RecordStructure parentRs = addStructure(model, host, tmpMsg, paths, size - 1, parentHistoryId, false);
            parentId = parentRs.getStructureId();
        }
        msgRs = model.getDb().getTableStructure().insert(session.getSessionId(), parentId, historyId, nodeName, url, method);
    } else if (newOnly) {
        // Already exists
        return null;
    }
    return msgRs;
}
Also used : RecordStructure(org.parosproxy.paros.db.RecordStructure) HttpMessage(org.parosproxy.paros.network.HttpMessage) Session(org.parosproxy.paros.model.Session)

Example 8 with Session

use of org.parosproxy.paros.model.Session in project zaproxy by zaproxy.

the class SessionStructure method addPath.

/**
 * Adds the message to the Sites tree
 *
 * @param model the model
 * @param ref the history reference
 * @param msg the message
 * @param newOnly Only return a SiteNode if one was newly created
 * @return the SiteNode that corresponds to the HttpMessage, or null if newOnly and the node
 *     already exists
 * @since 2.10.0
 */
public static StructuralNode addPath(Model model, HistoryReference ref, HttpMessage msg, boolean newOnly) {
    Session session = model.getSession();
    if (!Constant.isLowMemoryOptionSet()) {
        SiteNode node = session.getSiteTree().addPath(ref, msg, newOnly);
        if (node != null) {
            return new StructuralSiteNode(node);
        }
        return null;
    } else {
        try {
            List<String> paths = getTreePath(model, msg);
            String host = getHostName(msg.getRequestHeader().getURI());
            RecordStructure rs = addStructure(model, host, msg, paths, paths.size(), ref.getHistoryId(), newOnly);
            if (rs != null) {
                return new StructuralTableNode(rs);
            } else {
                return null;
            }
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            return null;
        }
    }
}
Also used : RecordStructure(org.parosproxy.paros.db.RecordStructure) DatabaseException(org.parosproxy.paros.db.DatabaseException) URIException(org.apache.commons.httpclient.URIException) HttpMalformedHeaderException(org.parosproxy.paros.network.HttpMalformedHeaderException) Session(org.parosproxy.paros.model.Session) SiteNode(org.parosproxy.paros.model.SiteNode)

Example 9 with Session

use of org.parosproxy.paros.model.Session 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 Session

use of org.parosproxy.paros.model.Session in project zaproxy by zaproxy.

the class PopupExcludeFromScanMenu method performAction.

@Override
public void performAction(SiteNode sn) {
    try {
        Session session = Model.getSingleton().getSession();
        session.getExcludeFromScanRegexs().add(new StructuralSiteNode(sn).getRegexPattern());
    } catch (DatabaseException e) {
    // Ignore
    }
}
Also used : StructuralSiteNode(org.zaproxy.zap.model.StructuralSiteNode) DatabaseException(org.parosproxy.paros.db.DatabaseException) Session(org.parosproxy.paros.model.Session)

Aggregations

Session (org.parosproxy.paros.model.Session)51 DatabaseException (org.parosproxy.paros.db.DatabaseException)18 Context (org.zaproxy.zap.model.Context)14 ArrayList (java.util.ArrayList)8 JMenuItem (javax.swing.JMenuItem)7 ExtensionPopupMenuItem (org.parosproxy.paros.extension.ExtensionPopupMenuItem)7 File (java.io.File)5 SiteNode (org.parosproxy.paros.model.SiteNode)5 HttpMalformedHeaderException (org.parosproxy.paros.network.HttpMalformedHeaderException)5 URIException (org.apache.commons.httpclient.URIException)4 RecordStructure (org.parosproxy.paros.db.RecordStructure)4 HttpMessage (org.parosproxy.paros.network.HttpMessage)4 ApiException (org.zaproxy.zap.extension.api.ApiException)4 ApiResponseElement (org.zaproxy.zap.extension.api.ApiResponseElement)4 Date (java.util.Date)3 HashMap (java.util.HashMap)3 PatternSyntaxException (java.util.regex.PatternSyntaxException)3 JFileChooser (javax.swing.JFileChooser)3 JSONException (net.sf.json.JSONException)3 ExtensionHistory (org.parosproxy.paros.extension.history.ExtensionHistory)3