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

com.denimgroup.threadfix.data.entities.SharedVulnerability Maven / Gradle / Ivy

////////////////////////////////////////////////////////////////////////
//
//     Copyright (c) 2009-2015 Denim Group, Ltd.
//
//     The contents of this file are subject to the Mozilla Public 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.mozilla.org/MPL/
//
//     Software distributed under the License is distributed on an "AS IS"
//     basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
//     License for the specific language governing rights and limitations
//     under the License.
//
//     The Original Code is ThreadFix.
//
//     The Initial Developer of the Original Code is Denim Group, Ltd.
//     Portions created by Denim Group, Ltd. are Copyright (C)
//     Denim Group, Ltd. All Rights Reserved.
//
//     Contributor(s): Denim Group, Ltd.
//
////////////////////////////////////////////////////////////////////////
package com.denimgroup.threadfix.data.entities;

import com.denimgroup.threadfix.views.AllViews;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonView;

import javax.persistence.*;
import java.util.List;

import static com.denimgroup.threadfix.CollectionUtils.list;


@Entity
@Table(name = "SharedVulnerability")
public class SharedVulnerability extends AuditableEntity {

	public enum SharedType{
		DATA_FLOW_ELEMENT,
		SURFACE_LOCATION
	}

	private List vulnerabilities = list();
	private SharedType sharedType;
	private Double backScore;

	@ManyToMany(mappedBy = "sharedVulnerabilities")
	@JsonIgnore
	public List getVulnerabilities() {
		return vulnerabilities;
	}

	public void setVulnerabilities(List vulnerabilities) {
		this.vulnerabilities = vulnerabilities;
	}

	@Column
	@JsonView({ AllViews.SharedVulnerabilityView.class })
	public SharedType getSharedType() {
		return sharedType;
	}

	public void setSharedType(SharedType sharedType) {
		this.sharedType = sharedType;
	}

	@Column
	@JsonView({ AllViews.SharedVulnerabilityView.class })
	public Double getBackScore() {
		return backScore;
	}

	public void setBackScore(Double backScore) {
		this.backScore = backScore;
	}

	@Transient
	@JsonView({ AllViews.SharedVulnerabilityView.class })
	public int getAssociatedVulnCount() {
		return vulnerabilities.size();
	}

	@Transient
	@JsonView({ AllViews.SharedVulnerabilityView.class })
	public GenericSeverity getSeverity() {
		if (vulnerabilities.size() == 0)
			return null;
		GenericSeverity severity = vulnerabilities.get(0).getGenericSeverity();
		for (int i=1; i severity.getIntValue()) {
				severity = vulnerabilities.get(i).getGenericSeverity();
			}
		}

		return severity;
	}

	@Transient
	@JsonView({ AllViews.SharedVulnerabilityView.class })
	public GenericVulnerability getGenericVulnerability() {
		return vulnerabilities.size() > 0 ? vulnerabilities.get(0).getGenericVulnerability() : null;
	}

	@Transient
	@JsonIgnore
	public boolean isInSameApplication() {
		if (getVulnerabilities() == null || getVulnerabilities().size() < 2)
			return true;

		int appId = getVulnerabilities().get(0).getAppId();

		for (int i=1; i< getVulnerabilities().size(); i++) {
			if (appId != getVulnerabilities().get(i).getAppId())
				return false;
		}

		return true;
	}

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy