Search in sources :

Example 11 with SiteNode

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

the class FormBasedAuthenticationMethodType method getPopupFlagLoginRequestMenuFactory.

/**
	 * Gets the popup menu factory for flagging login requests.
	 * 
	 * @return the popup flag login request menu factory
	 */
private PopupMenuItemSiteNodeContextMenuFactory getPopupFlagLoginRequestMenuFactory() {
    PopupMenuItemSiteNodeContextMenuFactory popupFlagLoginRequestMenuFactory = new PopupMenuItemSiteNodeContextMenuFactory(Constant.messages.getString("context.flag.popup")) {

        private static final long serialVersionUID = 8927418764L;

        @Override
        public PopupMenuItemContext getContextMenu(Context context, String parentMenu) {
            return new PopupMenuItemContext(context, parentMenu, MessageFormat.format(Constant.messages.getString("authentication.method.fb.popup.login.request"), context.getName())) {

                private static final long serialVersionUID = 1967885623005183801L;

                private ExtensionUserManagement usersExtension;

                private Context uiSharedContext;

                /**
					 * Make sure the user acknowledges the Users corresponding to this context will
					 * be deleted.
					 * 
					 * @return true, if successful
					 */
                private boolean confirmUsersDeletion(Context uiSharedContext) {
                    usersExtension = (ExtensionUserManagement) Control.getSingleton().getExtensionLoader().getExtension(ExtensionUserManagement.NAME);
                    if (usersExtension != null) {
                        if (usersExtension.getSharedContextUsers(uiSharedContext).size() > 0) {
                            int choice = JOptionPane.showConfirmDialog(this, Constant.messages.getString("authentication.dialog.confirmChange.label"), Constant.messages.getString("authentication.dialog.confirmChange.title"), JOptionPane.OK_CANCEL_OPTION);
                            if (choice == JOptionPane.CANCEL_OPTION) {
                                return false;
                            }
                        }
                    }
                    return true;
                }

                @Override
                public void performAction(SiteNode sn) {
                    // Manually create the UI shared contexts so any modifications are done
                    // on an UI shared Context, so changes can be undone by pressing Cancel
                    SessionDialog sessionDialog = View.getSingleton().getSessionDialog();
                    sessionDialog.recreateUISharedContexts(Model.getSingleton().getSession());
                    uiSharedContext = sessionDialog.getUISharedContext(this.getContext().getIndex());
                    // Do the work/changes on the UI shared context
                    if (this.getContext().getAuthenticationMethod() instanceof FormBasedAuthenticationMethod) {
                        log.info("Selected new login request via PopupMenu. Changing existing Form-Based Authentication instance for Context " + getContext().getIndex());
                        FormBasedAuthenticationMethod method = (FormBasedAuthenticationMethod) uiSharedContext.getAuthenticationMethod();
                        try {
                            method.setLoginRequest(sn);
                        } catch (Exception e) {
                            log.error("Failed to set login request: " + e.getMessage(), e);
                            return;
                        }
                        // Show the session dialog without recreating UI Shared contexts
                        View.getSingleton().showSessionDialog(Model.getSingleton().getSession(), ContextAuthenticationPanel.buildName(this.getContext().getIndex()), false);
                    } else {
                        log.info("Selected new login request via PopupMenu. Creating new Form-Based Authentication instance for Context " + getContext().getIndex());
                        FormBasedAuthenticationMethod method = new FormBasedAuthenticationMethod();
                        try {
                            method.setLoginRequest(sn);
                        } catch (Exception e) {
                            log.error("Failed to set login request: " + e.getMessage(), e);
                            return;
                        }
                        if (!confirmUsersDeletion(uiSharedContext)) {
                            log.debug("Cancelled change of authentication type.");
                            return;
                        }
                        uiSharedContext.setAuthenticationMethod(method);
                        // Show the session dialog without recreating UI Shared contexts
                        // NOTE: First init the panels of the dialog so old users data gets
                        // loaded and just then delete the users
                        // from the UI data model, otherwise the 'real' users from the
                        // non-shared context would be loaded
                        // and would override any deletions made.
                        View.getSingleton().showSessionDialog(Model.getSingleton().getSession(), ContextAuthenticationPanel.buildName(this.getContext().getIndex()), false, new Runnable() {

                            @Override
                            public void run() {
                                // save as well
                                if (usersExtension != null)
                                    usersExtension.removeSharedContextUsers(uiSharedContext);
                            }
                        });
                    }
                }
            };
        }

        @Override
        public int getParentMenuIndex() {
            return 3;
        }
    };
    return popupFlagLoginRequestMenuFactory;
}
Also used : Context(org.zaproxy.zap.model.Context) PopupMenuItemContext(org.zaproxy.zap.view.popup.PopupMenuItemContext) RecordContext(org.parosproxy.paros.db.RecordContext) ExtensionUserManagement(org.zaproxy.zap.extension.users.ExtensionUserManagement) PopupMenuItemContext(org.zaproxy.zap.view.popup.PopupMenuItemContext) SessionDialog(org.parosproxy.paros.view.SessionDialog) PopupMenuItemSiteNodeContextMenuFactory(org.zaproxy.zap.view.popup.PopupMenuItemSiteNodeContextMenuFactory) URIException(org.apache.commons.httpclient.URIException) HttpMalformedHeaderException(org.parosproxy.paros.network.HttpMalformedHeaderException) ApiException(org.zaproxy.zap.extension.api.ApiException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) ConfigurationException(org.apache.commons.configuration.ConfigurationException) IOException(java.io.IOException) DatabaseException(org.parosproxy.paros.db.DatabaseException) SiteNode(org.parosproxy.paros.model.SiteNode)

Example 12 with SiteNode

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

the class PopupContextTreeMenu method isEnableForComponent.

@Override
public boolean isEnableForComponent(Component invoker) {
    contextId = -1;
    if (invoker instanceof JTree && SiteMapPanel.CONTEXT_TREE_COMPONENT_NAME.equals(invoker.getName())) {
        JTree contextTree = (JTree) invoker;
        SiteNode node = (SiteNode) contextTree.getLastSelectedPathComponent();
        if (node == null || node.isRoot()) {
            return false;
        }
        contextId = ((Target) node.getUserObject()).getContext().getIndex();
        return isEnabledForContext(contextId);
    }
    return false;
}
Also used : JTree(javax.swing.JTree) Target(org.zaproxy.zap.model.Target) SiteNode(org.parosproxy.paros.model.SiteNode)

Example 13 with SiteNode

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

the class Context method checkNode.

private boolean checkNode(SiteNode sn) {
    // Loop backwards through the children TODO change for lowmem!
    // log.debug("checkNode " + sn.getHierarchicNodeName());		// Useful for debugging
    int origChildren = sn.getChildCount();
    int movedChildren = 0;
    for (SiteNode childNode : getChildren(sn)) {
        if (checkNode(childNode)) {
            movedChildren++;
        }
    }
    if (this.isInContext(sn)) {
        SiteMap sitesTree = this.session.getSiteTree();
        HistoryReference href = sn.getHistoryReference();
        try {
            SiteNode sn2;
            if (HttpRequestHeader.POST.equals(href.getMethod())) {
                // Have to go to the db as POST data can be used in the name
                sn2 = sitesTree.findNode(href.getHttpMessage());
            } else {
                // This is better as it doesnt require a db read
                sn2 = sitesTree.findNode(href.getURI());
            }
            if (sn2 == null || !sn.getHierarchicNodeName().equals(sn2.getHierarchicNodeName())) {
                if (!sn.isDataDriven()) {
                    moveNode(sitesTree, sn);
                    return true;
                }
            }
            if (movedChildren > 0 && movedChildren == origChildren && sn.getChildCount() == 0) {
                if (href.getHistoryType() == HistoryReference.TYPE_TEMPORARY) {
                    // Remove temp old node, no need to add new one in - 
                    // that will happen when moving child nodes (if required)
                    deleteNode(sitesTree, sn);
                    return true;
                }
            }
        // log.debug("Didnt need to move " + sn.getHierarchicNodeName());	// Useful for debugging
        } catch (Exception e) {
            log.error(e.getMessage(), e);
        }
    }
    return false;
}
Also used : HistoryReference(org.parosproxy.paros.model.HistoryReference) SiteMap(org.parosproxy.paros.model.SiteMap) PatternSyntaxException(java.util.regex.PatternSyntaxException) SiteNode(org.parosproxy.paros.model.SiteNode)

Example 14 with SiteNode

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

the class Context method getTopNodesInContextFromSiteTree.

/**
	 * Gets the nodes from the site tree which are "In Scope". Searches recursively starting from
	 * the root node. Should be used with care, as it is time-consuming, querying the database for
	 * every node in the Site Tree.
	 * 
	 * @return the nodes in scope from site tree
	 */
public List<SiteNode> getTopNodesInContextFromSiteTree() {
    List<SiteNode> nodes = new LinkedList<>();
    SiteNode rootNode = (SiteNode) session.getSiteTree().getRoot();
    @SuppressWarnings("unchecked") Enumeration<SiteNode> en = rootNode.children();
    while (en.hasMoreElements()) {
        SiteNode sn = en.nextElement();
        if (isContainsNodesInContext(sn)) {
            nodes.add(sn);
        }
    }
    return nodes;
}
Also used : LinkedList(java.util.LinkedList) SiteNode(org.parosproxy.paros.model.SiteNode)

Example 15 with SiteNode

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

the class NodeSelectDialog method contextSelected.

private void contextSelected() {
    SiteNode node = (SiteNode) treeContext.getLastSelectedPathComponent();
    if (node != null && (node.getParent() != null || allowRoot)) {
        selectedTarget = (Target) node.getUserObject();
        selectedSiteNode = null;
        NodeSelectDialog.this.setVisible(false);
    }
}
Also used : SiteNode(org.parosproxy.paros.model.SiteNode)

Aggregations

SiteNode (org.parosproxy.paros.model.SiteNode)53 DatabaseException (org.parosproxy.paros.db.DatabaseException)10 HistoryReference (org.parosproxy.paros.model.HistoryReference)10 JTree (javax.swing.JTree)9 Target (org.zaproxy.zap.model.Target)8 SiteMap (org.parosproxy.paros.model.SiteMap)7 ArrayList (java.util.ArrayList)6 TreePath (javax.swing.tree.TreePath)6 Alert (org.parosproxy.paros.core.scanner.Alert)6 HttpMalformedHeaderException (org.parosproxy.paros.network.HttpMalformedHeaderException)4 Context (org.zaproxy.zap.model.Context)4 StructuralSiteNode (org.zaproxy.zap.model.StructuralSiteNode)4 IOException (java.io.IOException)3 InvalidParameterException (java.security.InvalidParameterException)3 List (java.util.List)3 PatternSyntaxException (java.util.regex.PatternSyntaxException)3 ImageIcon (javax.swing.ImageIcon)3 DefaultTreeModel (javax.swing.tree.DefaultTreeModel)3 URIException (org.apache.commons.httpclient.URIException)3 Session (org.parosproxy.paros.model.Session)3