Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,19 @@
</plugins>
</build>

<pluginRepositories>
<pluginRepository>
<id>atlassian-public</id>
<url>https://m2proxy.atlassian.com/repository/public/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>

<repositories>
<repository>
<id>atlassian-public</id>
Expand All @@ -175,5 +188,4 @@
</snapshots>
</repository>
</repositories>

</project>
88 changes: 88 additions & 0 deletions src/main/java/neuvector/NeuVectorGlobalConfigurator.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.atlassian.bamboo.configuration.AdministrationConfigurationPersister;
import com.atlassian.bamboo.configuration.GlobalAdminAction;
import com.atlassian.spring.container.ContainerManager;
import org.apache.commons.lang3.math.NumberUtils;

import java.net.InetAddress;

Expand All @@ -19,6 +20,11 @@ public class NeuVectorGlobalConfigurator extends GlobalAdminAction {
private String scannerImageRepository;
private String scannerRegistryUsername;
private String scannerRegistryPassword;

private boolean isCustomThreshold = false;
private String customCriticalThreshold;
private String customHighThreshold;
private String customMediumThreshold;

public String execute() throws Exception {
final AdministrationConfiguration adminConfig = (AdministrationConfiguration) ContainerManager.getComponent("administrationConfiguration");
Expand All @@ -33,11 +39,20 @@ public String execute() throws Exception {
this.scannerImageRepository = adminConfig.getSystemProperty("scannerImageRepository");
this.scannerRegistryUsername = adminConfig.getSystemProperty("scannerRegistryUsername");
this.scannerRegistryPassword = adminConfig.getSystemProperty("scannerRegistryPassword");

this.customCriticalThreshold = adminConfig.getSystemProperty("customCriticalThreshold");
this.customHighThreshold = adminConfig.getSystemProperty("customHighThreshold");
this.customMediumThreshold = adminConfig.getSystemProperty("customMediumThreshold");

return "input";
}

public String save() {
final AdministrationConfiguration adminConfig = (AdministrationConfiguration) ContainerManager.getComponent("administrationConfiguration");
if (!checkCustomThreshold(this.customCriticalThreshold, this.customHighThreshold, this.customMediumThreshold)) {
return "success";
}

adminConfig.setSystemProperty("controllerIP", this.controllerIP);
adminConfig.setSystemProperty("controllerPort", this.controllerPort);
adminConfig.setSystemProperty("nvUsername", this.nvUsername);
Expand All @@ -50,6 +65,12 @@ public String save() {
adminConfig.setSystemProperty("scannerRegistryUsername", this.scannerRegistryUsername);
adminConfig.setSystemProperty("scannerRegistryPassword", this.scannerRegistryPassword);

adminConfig.setSystemProperty("customCriticalThreshold", this.customCriticalThreshold);
adminConfig.setSystemProperty("customHighThreshold", this.customHighThreshold);
adminConfig.setSystemProperty("customMediumThreshold", this.customMediumThreshold);
adminConfig.setSystemProperty("customMediumThreshold", this.customMediumThreshold);
adminConfig.setSystemProperty("isCustomThreshold", String.valueOf(this.isCustomThreshold));

((AdministrationConfigurationPersister) ContainerManager.getComponent("administrationConfigurationPersister")).saveAdministrationConfiguration(adminConfig);
this.addActionMessage("NeuVector Global Configuration Successfully Saved");
return "success";
Expand Down Expand Up @@ -78,6 +99,41 @@ public boolean checkControllerPort(final String value) {
}
}

public boolean checkCustomThreshold(final String customCriticalThreshold, final String customHighThreshold, final String customMediumThreshold) {
if (customCriticalThreshold == null && customHighThreshold == null && customMediumThreshold == null) {
return true;
}

if (!NumberUtils.isParsable(customCriticalThreshold) || !NumberUtils.isParsable(customHighThreshold) || !NumberUtils.isParsable(customMediumThreshold)) {
this.addActionError("One or more thresholds are not valid numbers.");
return false;
}

try {
double criticalSeverityThreshold = Double.parseDouble(customCriticalThreshold.trim());
double highSeverityThreshold = Double.parseDouble(customHighThreshold.trim());
double mediumSeverityThreshold = Double.parseDouble(customMediumThreshold.trim());

if (criticalSeverityThreshold < 0.0 || criticalSeverityThreshold > 10.0 ||
highSeverityThreshold < 0.0 || highSeverityThreshold > 10.0 ||
mediumSeverityThreshold < 0.0 || mediumSeverityThreshold > 10.0) {
this.addActionError("Threshold values must be between 0.0 and 10.0.");
return false;
}

if (criticalSeverityThreshold <= highSeverityThreshold || criticalSeverityThreshold <= mediumSeverityThreshold || highSeverityThreshold <= mediumSeverityThreshold) {
this.addActionError("Thresholds must satisfy: Critical > High > Medium.");
return false;
}

} catch (NumberFormatException e) {
this.addActionError("An unexpected error occurred while parsing the numbers."); // Fallback error
return false;
}
isCustomThreshold = true;
return true;
}

public String getControllerIP() {
return this.controllerIP;
}
Expand Down Expand Up @@ -165,4 +221,36 @@ public String getScannerRegistryPassword() {
public void setScannerRegistryPassword(String scannerRegistryPassword) {
this.scannerRegistryPassword = scannerRegistryPassword;
}

public String getCustomCriticalThreshold() {
return customCriticalThreshold;
}

public void setCustomCriticalThreshold(String customCriticalThreshold) {
this.customCriticalThreshold = customCriticalThreshold;
}

public String getCustomHighThreshold() {
return customHighThreshold;
}

public void setCustomHighThreshold(String customHighThreshold) {
this.customHighThreshold = customHighThreshold;
}

public String getCustomMediumThreshold() {
return customMediumThreshold;
}

public void setCustomMediumThreshold(String customMediumThreshold) {
this.customMediumThreshold = customMediumThreshold;
}

// public boolean getIsCustomizeThresholds() {
// return isCustomizeThresholds;
// }

// public void setCustomizeThresholds(boolean isCustomizeThresholds) {
// this.isCustomizeThresholds = isCustomizeThresholds;
// }
}
Loading