aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-server-common
diff options
context:
space:
mode:
authorSébastien Lesaint <sebastien.lesaint@sonarsource.com>2019-11-29 15:35:54 +0100
committerSonarTech <sonartech@sonarsource.com>2020-01-13 20:46:25 +0100
commit4eb7a56f67406141b84a1ebe5bed699619abf917 (patch)
tree6f9133dd3b53a550f2b0061eb804d17440864721 /server/sonar-server-common
parentf816ceb0a331f0d166857218c9422512eb15ae9d (diff)
downloadsonarqube-4eb7a56f67406141b84a1ebe5bed699619abf917.tar.gz
sonarqube-4eb7a56f67406141b84a1ebe5bed699619abf917.zip
SONAR-12717 small computation optimization in SecurityStandards
do not cache owaspTop10 and sansTop25 they are not used all the time when used, they are called only once per constructor
Diffstat (limited to 'server/sonar-server-common')
-rw-r--r--server/sonar-server-common/src/main/java/org/sonar/server/security/SecurityStandards.java27
1 files changed, 11 insertions, 16 deletions
diff --git a/server/sonar-server-common/src/main/java/org/sonar/server/security/SecurityStandards.java b/server/sonar-server-common/src/main/java/org/sonar/server/security/SecurityStandards.java
index 267a48bb2e7..b954d454339 100644
--- a/server/sonar-server-common/src/main/java/org/sonar/server/security/SecurityStandards.java
+++ b/server/sonar-server-common/src/main/java/org/sonar/server/security/SecurityStandards.java
@@ -139,16 +139,12 @@ public final class SecurityStandards {
private final Set<String> standards;
private final Set<String> cwe;
- private final Set<String> owaspTop10;
- private final Set<String> sansTop25;
private final SQCategory sqCategory;
private final Set<SQCategory> ignoredSQCategories;
- private SecurityStandards(Set<String> standards, Set<String> cwe, Set<String> owaspTop10, Set<String> sansTop25, SQCategory sqCategory, Set<SQCategory> ignoredSQCategories) {
+ private SecurityStandards(Set<String> standards, Set<String> cwe, SQCategory sqCategory, Set<SQCategory> ignoredSQCategories) {
this.standards = standards;
this.cwe = cwe;
- this.owaspTop10 = owaspTop10;
- this.sansTop25 = sansTop25;
this.sqCategory = sqCategory;
this.ignoredSQCategories = ignoredSQCategories;
}
@@ -162,17 +158,20 @@ public final class SecurityStandards {
}
public Set<String> getOwaspTop10() {
- return owaspTop10;
+ return toOwaspTop10(standards);
}
public Set<String> getSansTop25() {
- return sansTop25;
+ return toSansTop25(cwe);
}
public SQCategory getSqCategory() {
return sqCategory;
}
+ /**
+ * If CWEs mapped to multiple {@link SQCategory}, those which are not taken into account are listed here.
+ */
public Set<SQCategory> getIgnoredSQCategories() {
return ignoredSQCategories;
}
@@ -181,16 +180,12 @@ public final class SecurityStandards {
* @throws IllegalStateException if {@code securityStandards} maps to multiple {@link SQCategory SQCategories}
*/
public static SecurityStandards fromSecurityStandards(Set<String> securityStandards) {
- Set<String> standards = securityStandards.stream()
- .filter(Objects::nonNull)
- .collect(toSet());
- Set<String> cwe = toCwe(standards);
- Set<String> owaspTop10 = toOwaspTop10(standards);
- Set<String> sansTop25 = toSansTop25(cwe);
+ Set<String> standards = securityStandards.stream().filter(Objects::nonNull).collect(toSet());
+ Set<String> cwe = toCwes(standards);
List<SQCategory> sq = toSortedSQCategories(cwe);
SQCategory sqCategory = sq.iterator().next();
- Set<SQCategory> ignoredSQCategories = sq.stream().skip(1).collect(Collectors.toSet());
- return new SecurityStandards(standards, cwe, owaspTop10, sansTop25, sqCategory, ignoredSQCategories);
+ Set<SQCategory> ignoredSQCategories = sq.stream().skip(1).collect(toSet());
+ return new SecurityStandards(standards, cwe, sqCategory, ignoredSQCategories);
}
private static Set<String> toOwaspTop10(Set<String> securityStandards) {
@@ -200,7 +195,7 @@ public final class SecurityStandards {
.collect(toSet());
}
- private static Set<String> toCwe(Collection<String> securityStandards) {
+ private static Set<String> toCwes(Collection<String> securityStandards) {
Set<String> result = securityStandards.stream()
.filter(s -> s.startsWith(CWE_PREFIX))
.map(s -> s.substring(CWE_PREFIX.length()))