From 6af6f911664d1e65a046c65761684c485ded21f8 Mon Sep 17 00:00:00 2001 From: Edouard DUPIN Date: Sat, 1 Jun 2024 16:48:59 +0200 Subject: [PATCH] [FIX] SpotBug finding some errors --- src/org/kar/archidata/api/DataResource.java | 10 ++++++---- src/org/kar/archidata/dataAccess/DataAccess.java | 10 ++++++++-- .../dataAccess/addOn/model/TableCoversLongLong.java | 4 ---- .../dataAccess/addOn/model/TableCoversLongUUID.java | 4 ---- .../dataAccess/options/DBInterfaceOption.java | 3 +++ src/org/kar/archidata/migration/MigrationEngine.java | 4 ++-- src/org/kar/archidata/model/UserByToken.java | 6 +++--- src/org/kar/archidata/tools/JWTWrapper.java | 7 ++++++- 8 files changed, 28 insertions(+), 20 deletions(-) diff --git a/src/org/kar/archidata/api/DataResource.java b/src/org/kar/archidata/api/DataResource.java index 78d75e2..96738e3 100644 --- a/src/org/kar/archidata/api/DataResource.java +++ b/src/org/kar/archidata/api/DataResource.java @@ -300,9 +300,10 @@ public class DataResource { // logger.info("==================================================="); final Data value = getSmall(uuid); if (value == null) { - Response.status(404).entity("media NOT FOUND: " + uuid).type("text/plain").build(); + return Response.status(404).entity("media NOT FOUND: " + uuid).type("text/plain").build(); } - return buildStream(getFileData(uuid), range, value.mimeType); + return buildStream(getFileData(uuid), range, + value.mimeType == null ? "application/octet-stream" : value.mimeType); } @GET @@ -389,9 +390,10 @@ public class DataResource { // logger.info("==================================================="); final Data value = getSmall(uuid); if (value == null) { - Response.status(404).entity("media NOT FOUND: " + uuid).type("text/plain").build(); + return Response.status(404).entity("media NOT FOUND: " + uuid).type("text/plain").build(); } - return buildStream(getFileData(uuid), range, value.mimeType); + return buildStream(getFileData(uuid), range, + value.mimeType == null ? "application/octet-stream" : value.mimeType); } /** Adapted from http://stackoverflow.com/questions/12768812/video-streaming-to-ipad-does-not-work-with-tapestry5/12829541#12829541 diff --git a/src/org/kar/archidata/dataAccess/DataAccess.java b/src/org/kar/archidata/dataAccess/DataAccess.java index b638a0f..a14825c 100644 --- a/src/org/kar/archidata/dataAccess/DataAccess.java +++ b/src/org/kar/archidata/dataAccess/DataAccess.java @@ -1115,10 +1115,13 @@ public class DataAccess { return updateWhere(data, options); } - public static int updateWhere(final T data, final QueryOptions options) throws Exception { + public static int updateWhere(final T data, QueryOptions options) throws Exception { final Class clazz = data.getClass(); + if (options == null) { + options = new QueryOptions(); + } final Condition condition = conditionFusionOrEmpty(options, true); - final List filters = options.get(FilterValue.class); + final List filters = options != null ? options.get(FilterValue.class) : new ArrayList<>(); if (filters.size() != 1) { throw new DataAccessException("request a gets without/or with more 1 filter of values"); } @@ -1365,6 +1368,9 @@ public class DataAccess { public static Condition conditionFusionOrEmpty(final QueryOptions options, final boolean throwIfEmpty) throws DataAccessException { + if (options == null) { + return new Condition(); + } final List conditions = options.get(Condition.class); if (conditions.size() == 0) { if (throwIfEmpty) { diff --git a/src/org/kar/archidata/dataAccess/addOn/model/TableCoversLongLong.java b/src/org/kar/archidata/dataAccess/addOn/model/TableCoversLongLong.java index 678a9c6..45daf77 100644 --- a/src/org/kar/archidata/dataAccess/addOn/model/TableCoversLongLong.java +++ b/src/org/kar/archidata/dataAccess/addOn/model/TableCoversLongLong.java @@ -6,7 +6,6 @@ import org.kar.archidata.annotation.DataJson; import org.kar.archidata.model.GenericDataSoftDelete; import jakarta.persistence.Column; -import jakarta.persistence.Id; public class TableCoversLongLong extends GenericDataSoftDelete { public TableCoversLongLong() { @@ -18,9 +17,6 @@ public class TableCoversLongLong extends GenericDataSoftDelete { this.covers = covers; } - @Column(nullable = false) - @Id - public Long id; @DataJson() @Column(nullable = false) public List covers; diff --git a/src/org/kar/archidata/dataAccess/addOn/model/TableCoversLongUUID.java b/src/org/kar/archidata/dataAccess/addOn/model/TableCoversLongUUID.java index 17dbb22..af41e88 100644 --- a/src/org/kar/archidata/dataAccess/addOn/model/TableCoversLongUUID.java +++ b/src/org/kar/archidata/dataAccess/addOn/model/TableCoversLongUUID.java @@ -7,7 +7,6 @@ import org.kar.archidata.annotation.DataJson; import org.kar.archidata.model.GenericDataSoftDelete; import jakarta.persistence.Column; -import jakarta.persistence.Id; public class TableCoversLongUUID extends GenericDataSoftDelete { public TableCoversLongUUID() { @@ -19,9 +18,6 @@ public class TableCoversLongUUID extends GenericDataSoftDelete { this.covers = covers; } - @Column(nullable = false) - @Id - public Long id; @DataJson() @Column(nullable = false) public List covers; diff --git a/src/org/kar/archidata/dataAccess/options/DBInterfaceOption.java b/src/org/kar/archidata/dataAccess/options/DBInterfaceOption.java index 1d317bf..a740c0d 100644 --- a/src/org/kar/archidata/dataAccess/options/DBInterfaceOption.java +++ b/src/org/kar/archidata/dataAccess/options/DBInterfaceOption.java @@ -36,6 +36,9 @@ public class DBInterfaceOption extends QueryOption { } public static DBEntry getAutoEntry(final QueryOptions options) throws IOException { + if (options == null) { + return DBEntry.createInterface(GlobalConfiguration.dbConfig, false); + } final List dbOption = options.get(DBInterfaceOption.class); if (dbOption.size() == 0) { final List isRoot = options.get(DBInterfaceRoot.class); diff --git a/src/org/kar/archidata/migration/MigrationEngine.java b/src/org/kar/archidata/migration/MigrationEngine.java index 544c2ea..b37438a 100644 --- a/src/org/kar/archidata/migration/MigrationEngine.java +++ b/src/org/kar/archidata/migration/MigrationEngine.java @@ -318,12 +318,12 @@ public class MigrationEngine { boolean find = false; for (int iii = this.datas.size() - 1; iii >= 0; iii--) { if (!find) { - if (this.datas.get(iii).getName() == currentVersion.name) { + if (this.datas.get(iii).getName().equals(currentVersion.name)) { find = true; } continue; } - if (this.datas.get(iii).getName() == currentVersion.name) { + if (this.datas.get(iii).getName().equals(currentVersion.name)) { break; } toApply.add(this.datas.get(iii)); diff --git a/src/org/kar/archidata/model/UserByToken.java b/src/org/kar/archidata/model/UserByToken.java index d22c355..54a07fb 100644 --- a/src/org/kar/archidata/model/UserByToken.java +++ b/src/org/kar/archidata/model/UserByToken.java @@ -22,7 +22,7 @@ public class UserByToken { final Object data = this.right.get(key); if (data instanceof final Boolean elem) { if (value instanceof final Boolean castVal) { - if (elem == castVal) { + if (elem.equals(castVal)) { return true; } } @@ -38,7 +38,7 @@ public class UserByToken { } if (data instanceof final Long elem) { if (value instanceof final Long castVal) { - if (elem == castVal) { + if (elem.equals(castVal)) { return true; } } @@ -46,7 +46,7 @@ public class UserByToken { } if (data instanceof final Double elem) { if (value instanceof final Double castVal) { - if (elem == castVal) { + if (elem.equals(castVal)) { return true; } } diff --git a/src/org/kar/archidata/tools/JWTWrapper.java b/src/org/kar/archidata/tools/JWTWrapper.java index 6afe1e7..ba39452 100644 --- a/src/org/kar/archidata/tools/JWTWrapper.java +++ b/src/org/kar/archidata/tools/JWTWrapper.java @@ -5,6 +5,7 @@ import java.io.IOException; import java.io.InputStreamReader; import java.net.HttpURLConnection; import java.net.URL; +import java.nio.charset.StandardCharsets; import java.text.ParseException; import java.util.Date; import java.util.Map; @@ -219,6 +220,10 @@ public class JWTWrapper { try { // On the consumer side, parse the JWS and verify its RSA signature final SignedJWT signedJWT = SignedJWT.parse(signedToken); + if (signedJWT == null) { + LOGGER.error("FAIL to parse signing"); + return null; + } if (ConfigBaseVariable.getTestMode() && signedToken.endsWith(TestSigner.test_signature)) { LOGGER.warn("Someone use a test token: {}", signedToken); } else if (rsaPublicJWK == null) { @@ -226,7 +231,7 @@ public class JWTWrapper { if (!ConfigBaseVariable.getTestMode()) { return null; } - final String rawSignature = signedJWT.getSigningInput().toString(); + final String rawSignature = new String(signedJWT.getSigningInput(), StandardCharsets.UTF_8); if (rawSignature.equals(TestSigner.test_signature)) { // Test token : .application.. } else {