Search in sources :

Example 6 with DomainMatcher

use of org.zaproxy.zap.network.DomainMatcher in project zaproxy by zaproxy.

the class ConnectionParam method setProxyExcludedDomains.

/**
     * Sets the domains that will be excluded from the outgoing proxy.
     * 
     * @param proxyExcludedDomains the domains that will be excluded.
     * @since 2.3.0
     * @see #getProxyExcludedDomains()
     * @see #getProxyExcludedDomainsEnabled()
     */
public void setProxyExcludedDomains(List<DomainMatcher> proxyExcludedDomains) {
    if (proxyExcludedDomains == null || proxyExcludedDomains.isEmpty()) {
        ((HierarchicalConfiguration) getConfig()).clearTree(ALL_PROXY_EXCLUDED_DOMAINS_KEY);
        this.proxyExcludedDomains = Collections.emptyList();
        this.proxyExcludedDomainsEnabled = Collections.emptyList();
        return;
    }
    this.proxyExcludedDomains = new ArrayList<>(proxyExcludedDomains);
    ((HierarchicalConfiguration) getConfig()).clearTree(ALL_PROXY_EXCLUDED_DOMAINS_KEY);
    int size = proxyExcludedDomains.size();
    ArrayList<DomainMatcher> enabledExcludedDomains = new ArrayList<>(size);
    for (int i = 0; i < size; ++i) {
        String elementBaseKey = ALL_PROXY_EXCLUDED_DOMAINS_KEY + "(" + i + ").";
        DomainMatcher excludedDomain = proxyExcludedDomains.get(i);
        getConfig().setProperty(elementBaseKey + PROXY_EXCLUDED_DOMAIN_VALUE_KEY, excludedDomain.getValue());
        getConfig().setProperty(elementBaseKey + PROXY_EXCLUDED_DOMAIN_REGEX_KEY, Boolean.valueOf(excludedDomain.isRegex()));
        getConfig().setProperty(elementBaseKey + PROXY_EXCLUDED_DOMAIN_ENABLED_KEY, Boolean.valueOf(excludedDomain.isEnabled()));
        if (excludedDomain.isEnabled()) {
            enabledExcludedDomains.add(excludedDomain);
        }
    }
    enabledExcludedDomains.trimToSize();
    this.proxyExcludedDomainsEnabled = enabledExcludedDomains;
}
Also used : ArrayList(java.util.ArrayList) HierarchicalConfiguration(org.apache.commons.configuration.HierarchicalConfiguration) DomainMatcher(org.zaproxy.zap.network.DomainMatcher)

Example 7 with DomainMatcher

use of org.zaproxy.zap.network.DomainMatcher in project zaproxy by zaproxy.

the class CoreAPI method setProxyChainExcludedDomainsEnabled.

private void setProxyChainExcludedDomainsEnabled(boolean enabled) {
    ConnectionParam connectionParam = Model.getSingleton().getOptionsParam().getConnectionParam();
    List<DomainMatcher> domains = connectionParam.getProxyExcludedDomains();
    for (DomainMatcher domain : domains) {
        domain.setEnabled(enabled);
    }
    connectionParam.setProxyExcludedDomains(domains);
}
Also used : ConnectionParam(org.parosproxy.paros.network.ConnectionParam) DomainMatcher(org.zaproxy.zap.network.DomainMatcher)

Example 8 with DomainMatcher

use of org.zaproxy.zap.network.DomainMatcher in project zaproxy by zaproxy.

the class DialogAddPermittedAddress method performAction.

@Override
protected void performAction() {
    String value = getAddressTextField().getText();
    if (getRegexCheckBox().isSelected()) {
        Pattern pattern = DomainMatcher.createPattern(value);
        address = new DomainMatcher(pattern);
    } else {
        address = new DomainMatcher(value);
    }
    address.setEnabled(getEnabledCheckBox().isSelected());
}
Also used : Pattern(java.util.regex.Pattern) DomainMatcher(org.zaproxy.zap.network.DomainMatcher)

Example 9 with DomainMatcher

use of org.zaproxy.zap.network.DomainMatcher in project zaproxy by zaproxy.

the class OptionsParamApi method loadPermittedAddresses.

private void loadPermittedAddresses() {
    List<HierarchicalConfiguration> fields = ((HierarchicalConfiguration) getConfig()).configurationsAt(ADDRESS_KEY);
    this.permittedAddresses = new ArrayList<>(fields.size());
    ArrayList<DomainMatcher> addrsEnabled = new ArrayList<>(fields.size());
    for (HierarchicalConfiguration sub : fields) {
        String value = sub.getString(ADDRESS_VALUE_KEY, "");
        if (value.isEmpty()) {
            LOGGER.warn("Failed to read a permitted address entry, required value is empty.");
            continue;
        }
        DomainMatcher addr = null;
        boolean regex = sub.getBoolean(ADDRESS_REGEX_KEY, false);
        if (regex) {
            try {
                Pattern pattern = DomainMatcher.createPattern(value);
                addr = new DomainMatcher(pattern);
            } catch (IllegalArgumentException e) {
                LOGGER.error("Failed to read a permitted address entry with regex: " + value, e);
            }
        } else {
            addr = new DomainMatcher(value);
        }
        if (addr != null) {
            addr.setEnabled(sub.getBoolean(ADDRESS_ENABLED_KEY, true));
            permittedAddresses.add(addr);
            if (addr.isEnabled()) {
                addrsEnabled.add(addr);
            }
        }
    }
    addrsEnabled.trimToSize();
    if (permittedAddresses.size() == 0) {
        // None specified - add in the defaults (which can then be disabled)
        DomainMatcher addr = new DomainMatcher("127.0.0.1");
        permittedAddresses.add(addr);
        addrsEnabled.add(addr);
        addr = new DomainMatcher("localhost");
        permittedAddresses.add(addr);
        addrsEnabled.add(addr);
        addr = new DomainMatcher("zap");
        permittedAddresses.add(addr);
        addrsEnabled.add(addr);
    }
    this.permittedAddressesEnabled = addrsEnabled;
}
Also used : Pattern(java.util.regex.Pattern) ArrayList(java.util.ArrayList) HierarchicalConfiguration(org.apache.commons.configuration.HierarchicalConfiguration) DomainMatcher(org.zaproxy.zap.network.DomainMatcher)

Example 10 with DomainMatcher

use of org.zaproxy.zap.network.DomainMatcher in project zaproxy by zaproxy.

the class PermittedAddressesTableModel method setAddresses.

public void setAddresses(List<DomainMatcher> addrs) {
    this.addresses = new ArrayList<>(addrs.size());
    for (DomainMatcher addr : addrs) {
        this.addresses.add(new DomainMatcher(addr));
    }
    fireTableDataChanged();
}
Also used : DomainMatcher(org.zaproxy.zap.network.DomainMatcher)

Aggregations

DomainMatcher (org.zaproxy.zap.network.DomainMatcher)12 ArrayList (java.util.ArrayList)6 Pattern (java.util.regex.Pattern)5 HierarchicalConfiguration (org.apache.commons.configuration.HierarchicalConfiguration)4 ConnectionParam (org.parosproxy.paros.network.ConnectionParam)2 File (java.io.File)1 IOException (java.io.IOException)1 Path (java.nio.file.Path)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 List (java.util.List)1 PatternSyntaxException (java.util.regex.PatternSyntaxException)1 JSONException (net.sf.json.JSONException)1 JSONObject (net.sf.json.JSONObject)1 URI (org.apache.commons.httpclient.URI)1 URIException (org.apache.commons.httpclient.URIException)1 Mode (org.parosproxy.paros.control.Control.Mode)1 DatabaseException (org.parosproxy.paros.db.DatabaseException)1 Session (org.parosproxy.paros.model.Session)1 SiteMap (org.parosproxy.paros.model.SiteMap)1