All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.zaproxy.zap.model.TechSet Maven / Gradle / Ivy

Go to download

The Zed Attack Proxy (ZAP) is an easy to use integrated penetration testing tool for finding vulnerabilities in web applications. It is designed to be used by people with a wide range of security experience and as such is ideal for developers and functional testers who are new to penetration testing. ZAP provides automated scanners as well as a set of tools that allow you to find security vulnerabilities manually.

There is a newer version: 2.7.0
Show newest version
/*
 * Zed Attack Proxy (ZAP) and its related class files.
 *
 * ZAP is an HTTP/HTTPS proxy for assessing web application security.
 *
 * Copyright 2012 The ZAP Development Team
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.zaproxy.zap.model;

import java.util.Objects;
import java.util.Set;
import java.util.TreeSet;

public class TechSet {

    /**
     * @deprecated Not for public use. Replaced by {@link #getAllTech()}.
     */
    @Deprecated public static final TechSet AllTech = new TechSet(Tech.getTopLevel());

    private TreeSet includeTech = new TreeSet<>();
    private TreeSet excludeTech = new TreeSet<>();

    public TechSet() {}

    public TechSet(Tech... include) {
        this(include, (Tech[]) null);
    }

    public TechSet(Tech[] include, Tech[] exclude) {
        if (include != null) {
            for (Tech tech : include) {
                this.include(tech);
            }
        }
        if (exclude != null) {
            for (Tech tech : exclude) {
                this.exclude(tech);
            }
        }
    }

    public TechSet(Set include) {
        this.includeTech.addAll(include);
    }

    public TechSet(TechSet techSet) {
        this.includeTech.addAll(techSet.includeTech);
        this.excludeTech.addAll(techSet.excludeTech);
    }

    public void include(Tech tech) {
        excludeTech.remove(tech);
        includeTech.add(tech);
    }

    /**
     * Includes the {@link Tech} and its children (if any) to the {@code TechSet}.
     *
     * @param tech the {@code Tech} from which the parent/child set should be established
     * @since 2.15.0
     */
    public void includeAll(Tech tech) {
        Set techs = getAll(tech);
        includeTech.addAll(techs);
        excludeTech.removeAll(techs);
    }

    public void exclude(Tech tech) {
        includeTech.remove(tech);
        excludeTech.add(tech);
    }

    /**
     * Excludes the {@link Tech} and its children (if any) from the {@code TechSet}.
     *
     * @param tech the {@code Tech} from which the parent/child set should be established
     * @since 2.15.0
     */
    public void excludeAll(Tech tech) {
        Set techs = getAll(tech);
        excludeTech.addAll(techs);
        includeTech.removeAll(techs);
    }

    public boolean includes(Tech tech) {
        if (tech == null) {
            return false;
        }
        if (excludeTech.contains(tech)) {
            return false;
        } else if (includeTech.contains(tech)) {
            return true;
        } else {
            return this.includes(tech.getParent());
        }
    }

    /**
     * Tells whether or not any of the given technologies is included.
     *
     * @param techs the technologies that will be checked.
     * @return {@code true} if any of the technologies is included, {@code false} otherwise.
     * @since 2.8.0
     * @see #includes(Tech)
     */
    public boolean includesAny(Tech... techs) {
        if (techs == null || techs.length == 0) {
            return false;
        }
        for (Tech tech : techs) {
            if (includes(tech)) {
                return true;
            }
        }
        return false;
    }

    public TreeSet getIncludeTech() {
        TreeSet copy = new TreeSet<>();
        copy.addAll(this.includeTech);
        return copy;
    }

    public TreeSet getExcludeTech() {
        TreeSet copy = new TreeSet<>();
        copy.addAll(this.excludeTech);
        return copy;
    }

    // Useful for debugging ;)
    public void print() {
        System.out.println("TechSet: " + this.hashCode());
        for (Tech tech : includeTech) {
            System.out.println("\tInclude: " + tech);
        }
        for (Tech tech : excludeTech) {
            System.out.println("\tExclude: " + tech);
        }
    }

    /**
     * Get a TechSet including all Tech currently known
     *
     * 

Info: always returns a new TechSet containing the currently known Tech * * @return TechSet including all Tech */ public static TechSet getAllTech() { return new TechSet(Tech.getTopLevel()); } @Override public int hashCode() { return Objects.hash(excludeTech, includeTech); } @Override public boolean equals(Object obj) { if (this == obj) { return true; } if (!(obj instanceof TechSet)) { return false; } TechSet other = (TechSet) obj; return Objects.equals(excludeTech, other.excludeTech) && Objects.equals(includeTech, other.includeTech); } /** * Gets the {@link Tech} and its children (if any), returning a {@code Set} of individual {@code * Tech}. * * @param aTech the {@code Tech} from which the parent/child set should be established * @return the {@code Set} of {@code Tech} represented by this {@code Tech} and its children (if * any) */ static Set getAll(Tech aTech) { Set techs = new TreeSet<>(); for (Tech tech : Tech.getAll()) { while (tech != null) { if (tech.is(aTech)) { techs.add(tech); } tech = tech.getParent(); } } return techs; } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy