From a4b1e4c32927208e92ca9895fa780e18051d3932 Mon Sep 17 00:00:00 2001
From: Roberto Sánchez <roberto.sanchez@curisit.net>
Date: Thu, 18 Sep 2014 14:20:17 +0000
Subject: [PATCH] #0 feature - Fixed some SonarQube issues
---
src/main/java/net/curisit/securis/LicenseValidator.java | 8 +-
src/main/java/net/curisit/securis/utils/Params.java | 10 +-
src/main/java/net/curisit/securis/utils/LicUtils.java | 8 +-
src/main/java/net/curisit/securis/utils/JsonUtils.java | 28 ++++----
src/main/java/net/curisit/securis/LicenseManager.java | 8 +-
src/main/java/net/curisit/securis/utils/HWInfo.java | 16 ++--
src/main/java/net/curisit/securis/ReqGenerator.java | 12 ++--
pom.xml | 2
src/main/java/net/curisit/securis/License.java | 27 ++++----
src/main/java/net/curisit/securis/utils/SignatureHelper.java | 12 ++--
10 files changed, 65 insertions(+), 66 deletions(-)
diff --git a/pom.xml b/pom.xml
index c9eb743..f4c8d55 100644
--- a/pom.xml
+++ b/pom.xml
@@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>net.curisit</groupId>
<artifactId>securis-client</artifactId>
- <version>0.9.5-SNAPSHOT</version>
+ <version>0.9.6-SNAPSHOT</version>
<build>
<plugins>
<plugin>
diff --git a/src/main/java/net/curisit/securis/License.java b/src/main/java/net/curisit/securis/License.java
index 8f08b6f..1d49af8 100644
--- a/src/main/java/net/curisit/securis/License.java
+++ b/src/main/java/net/curisit/securis/License.java
@@ -42,7 +42,7 @@
*/
public class License {
- private static final Logger log = LogManager.getLogger(License.class);
+ private static final Logger LOG = LogManager.getLogger(License.class);
/**
* Aplication entry point when it used as CLI
@@ -51,9 +51,8 @@
* @throws URISyntaxException
*/
public static void main(String[] args) throws URISyntaxException {
- // Configuration conf = XMLConfigurationFactory.getInstance().getConfiguration("config", License.class.getResource("/log4j.xml").toURI());
- log.debug("SeCuris client tool init ");
+ LOG.debug("SeCuris client tool init ");
checkConfigFile();
CommandLine cmd = getCommandLine(args);
@@ -65,7 +64,7 @@
filename = "./license.req";
File file = new File(filename);
LicenseManager.getInstance().createRequestFile(file);
- log.info("Request file {} generated OK", file.getAbsolutePath());
+ LOG.info("Request file {} generated OK", file.getAbsolutePath());
System.exit(0);
}
@@ -76,10 +75,10 @@
File file = new File(filename);
try {
LicenseManager.getInstance().validateLicense(file);
- log.info("License file {} is valid", file.getAbsolutePath());
+ LOG.info("License file {} is valid", file.getAbsolutePath());
} catch (SeCurisException e) {
- log.info("License file {} is NOT valid", file.getAbsolutePath());
- log.info("Reason: {}", e.toString());
+ LOG.info("License file {} is NOT valid", file.getAbsolutePath());
+ LOG.info("Reason: {}", e.toString());
}
System.exit(0);
@@ -89,30 +88,30 @@
String reqFilename = cmd.getOptionValue("rfile");
checkMandatoryParameter(reqFilename, "rfile");
- log.warn("This command is not yet implemented");
+ LOG.warn("This command is not yet implemented");
System.exit(0);
}
if (cmd.hasOption('t')) {
- log.warn("This command is not yet implemented");
+ LOG.warn("This command is not yet implemented");
System.exit(0);
}
if (cmd.hasOption('r')) {
String licFilename = cmd.getOptionValue("renew");
checkMandatoryParameter(licFilename, "renew");
- log.warn("This command is not yet implemented");
+ LOG.warn("This command is not yet implemented");
System.exit(0);
}
} catch (SeCurisException e) {
- log.error("The command generated an error: {}", e.toString());
+ LOG.error("The command generated an error: {}", e.toString());
}
}
private static void checkMandatoryParameter(String value, String param) {
if (value == null) {
- log.error("Parameter {} is mandatory. Use --help to get information about parameters", param);
+ LOG.error("Parameter {} is mandatory. Use --help to get information about parameters", param);
System.exit(-5);
}
}
@@ -123,12 +122,12 @@
private static void checkConfigFile() {
String appCode = Params.get(Params.KEYS.APPLICATION_CODE);
if (appCode == null) {
- log.error("Manadatory parameter {} is not set in config file", Params.KEYS.APPLICATION_CODE);
+ LOG.error("Manadatory parameter {} is not set in config file", Params.KEYS.APPLICATION_CODE);
System.exit(-3);
}
String customerCode = Params.get(Params.KEYS.CUSTOMER_CODE);
if (customerCode == null) {
- log.error("Manadatory parameter {} is not set in config file", Params.KEYS.CUSTOMER_CODE);
+ LOG.error("Manadatory parameter {} is not set in config file", Params.KEYS.CUSTOMER_CODE);
System.exit(-4);
}
}
diff --git a/src/main/java/net/curisit/securis/LicenseManager.java b/src/main/java/net/curisit/securis/LicenseManager.java
index 45c71f5..c754def 100644
--- a/src/main/java/net/curisit/securis/LicenseManager.java
+++ b/src/main/java/net/curisit/securis/LicenseManager.java
@@ -25,7 +25,7 @@
*/
public class LicenseManager {
- private static final Logger log = LogManager.getLogger(License.class);
+ private static final Logger LOG = LogManager.getLogger(License.class);
private static LicenseManager singleton = new LicenseManager();
@@ -109,14 +109,14 @@
json = JsonUtils.toJSON(signedLic, true).getBytes("utf-8");
Files.write(Paths.get(file.toURI()), json, StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING);
} catch (UnsupportedEncodingException e) {
- log.error("Error creating json doc from license: " + license, e);
+ LOG.error("Error creating json doc from license: " + license, e);
throw new SeCurisException("Error creating json doc from license: " + license, e);
} catch (IOException e) {
- log.error("Error creating license file: " + file, e);
+ LOG.error("Error creating license file: " + file, e);
throw new SeCurisException("Error creating json doc from license: " + license, e);
}
- log.debug("License saved in {}", file);
+ LOG.debug("License saved in {}", file);
}
diff --git a/src/main/java/net/curisit/securis/LicenseValidator.java b/src/main/java/net/curisit/securis/LicenseValidator.java
index 2b95123..a8d9d7b 100644
--- a/src/main/java/net/curisit/securis/LicenseValidator.java
+++ b/src/main/java/net/curisit/securis/LicenseValidator.java
@@ -14,7 +14,7 @@
public class LicenseValidator {
- private static final Logger log = LogManager.getLogger(LicenseValidator.class);
+ private static final Logger LOG = LogManager.getLogger(LicenseValidator.class);
private static LicenseValidator singleton = new LicenseValidator();
protected static byte[] LOGO_SECRET;
@@ -23,7 +23,7 @@
try {
LOGO_SECRET = "Logo ipsum s3cr3t test áíóú".getBytes("utf-8");
} catch (UnsupportedEncodingException e) {
- log.error("Unexpected error getting LOGO secret", e);
+ LOG.error("Unexpected error getting LOGO secret", e);
}
}
@@ -43,14 +43,14 @@
String shaLogo = LicUtils.sha256(IOUtils.toByteArray(is), LOGO_SECRET);
return shaLogo;
} catch (IOException e) {
- log.warn("Customer logo was not found in images/logo_customer.png");
+ LOG.warn("Customer logo was not found in images/logo_customer.png");
return null;
}
}
public void validateLogo(RequestBean reqBean) throws SeCurisException {
if (reqBean.getCrcLogo() == null) {
- log.info("Customer logo is not included in license file and won't be validated");
+ LOG.info("Customer logo is not included in license file and won't be validated");
} else {
String currentCRC = getCrcLogo();
if (!currentCRC.equals(reqBean.getCrcLogo()))
diff --git a/src/main/java/net/curisit/securis/ReqGenerator.java b/src/main/java/net/curisit/securis/ReqGenerator.java
index f8d4a51..38716bc 100644
--- a/src/main/java/net/curisit/securis/ReqGenerator.java
+++ b/src/main/java/net/curisit/securis/ReqGenerator.java
@@ -19,7 +19,7 @@
public class ReqGenerator {
- private static final Logger log = LogManager.getLogger(ReqGenerator.class);
+ private static final Logger LOG = LogManager.getLogger(ReqGenerator.class);
private static ReqGenerator singleton = new ReqGenerator();
@@ -49,7 +49,7 @@
RequestBean req = JsonUtils.json2object(json, RequestBean.class);
return req;
} catch (IOException e) {
- log.error("Request file {} was not found or is not accesible");
+ LOG.error("Request file {} was not found or is not accesible");
throw new SeCurisException("ERROR accesing request file: " + requestFile.getAbsolutePath(), e);
}
}
@@ -67,14 +67,14 @@
json = JsonUtils.toJSON(req, true).getBytes("utf-8");
Files.write(Paths.get(file.toURI()), json, StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING);
} catch (UnsupportedEncodingException e) {
- log.error("Error creating json doc from request: " + req, e);
+ LOG.error("Error creating json doc from request: " + req, e);
throw new SeCurisException("Error creating json doc from request: " + req, e);
} catch (IOException e) {
- log.error("Error creating request file: " + file, e);
+ LOG.error("Error creating request file: " + file, e);
throw new SeCurisException("Error creating request file: " + file, e);
}
- log.debug("License saved in {}", file);
+ LOG.debug("License saved in {}", file);
}
@@ -87,7 +87,7 @@
String shaLogo = LicUtils.sha256(IOUtils.toByteArray(is), LicenseValidator.LOGO_SECRET);
return shaLogo;
} catch (IOException e) {
- log.error("Customer logo was not found in classpath in " + logResource, e);
+ LOG.error("Customer logo was not found in classpath in " + logResource, e);
return null;
}
}
diff --git a/src/main/java/net/curisit/securis/utils/HWInfo.java b/src/main/java/net/curisit/securis/utils/HWInfo.java
index 1baecdb..0b60796 100644
--- a/src/main/java/net/curisit/securis/utils/HWInfo.java
+++ b/src/main/java/net/curisit/securis/utils/HWInfo.java
@@ -21,7 +21,7 @@
*/
public class HWInfo {
- private static final Logger log = LogManager.getLogger(HWInfo.class);
+ private static final Logger LOG = LogManager.getLogger(HWInfo.class);
public static String getOsName() {
return System.getProperty("os.name");
@@ -47,7 +47,7 @@
for (NetworkInterface network : Collections.list(NetworkInterface.getNetworkInterfaces())) {
if (!network.isLoopback() && !network.isVirtual() && !network.isPointToPoint() && network.getHardwareAddress() != null) {
macs.add(network.getHardwareAddress());
- log.debug("Interface added {}, MAC: {}", network.getName(), network.getHardwareAddress());
+ LOG.debug("Interface added {}, MAC: {}", network.getName(), network.getHardwareAddress());
logInterface(network);
}
}
@@ -57,7 +57,7 @@
NetworkInterface network = NetworkInterface.getByInetAddress(InetAddress.getLocalHost());
if (network.getHardwareAddress() != null)
macs.add(network.getHardwareAddress());
- log.debug("Selected interface (Inet Address rule)");
+ LOG.debug("Selected interface (Inet Address rule)");
logInterface(network);
}
@@ -67,7 +67,7 @@
if (!network.isLoopback() && !network.isVirtual() && !network.isPointToPoint() && network.getHardwareAddress() != null) {
if (network.getHardwareAddress() != null)
macs.add(network.getHardwareAddress());
- log.debug("Selected interface (Any with MAC rule)");
+ LOG.debug("Selected interface (Any with MAC rule)");
logInterface(network);
break;
}
@@ -81,7 +81,7 @@
for (byte[] mac : macs) {
macAddresses.add(printMacAddress(mac));
}
- log.debug("MAC Addresses: {}", macAddresses);
+ LOG.debug("MAC Addresses: {}", macAddresses);
return macAddresses;
} catch (UnknownHostException e) {
@@ -103,10 +103,10 @@
}
private static void logInterface(NetworkInterface network) {
- log.debug("Interface name: {}", network.getName());
- log.debug("Interface display name: {}", network.getDisplayName());
+ LOG.debug("Interface name: {}", network.getName());
+ LOG.debug("Interface display name: {}", network.getDisplayName());
try {
- log.debug("Interface mac: {}", printMacAddress(network.getHardwareAddress()));
+ LOG.debug("Interface mac: {}", printMacAddress(network.getHardwareAddress()));
} catch (SocketException e) {
// Silent
}
diff --git a/src/main/java/net/curisit/securis/utils/JsonUtils.java b/src/main/java/net/curisit/securis/utils/JsonUtils.java
index c134c05..3ac49c3 100644
--- a/src/main/java/net/curisit/securis/utils/JsonUtils.java
+++ b/src/main/java/net/curisit/securis/utils/JsonUtils.java
@@ -22,7 +22,7 @@
*/
public class JsonUtils {
- private static final Logger log = LogManager.getLogger(JsonUtils.class);
+ private static final Logger LOG = LogManager.getLogger(JsonUtils.class);
final private static ObjectMapper MAPPER = new ObjectMapper();
@@ -58,12 +58,12 @@
}
return MAPPER.readValue(json, type);
} catch (JsonParseException e) {
- log.error("Error parsing JSON string to obejct: {}", json, e);
+ LOG.error("Error parsing JSON string to obejct: {}", json, e);
if (json.length() > 60)
json = json.substring(0, 50) + "...";
throw new SeCurisException("Error parsing JSON string to object: " + json, e);
} catch (IOException e) {
- log.error("Error parsing JSON string to object: {}", json, e);
+ LOG.error("Error parsing JSON string to object: {}", json, e);
if (json.length() > 60)
json = json.substring(0, 50) + "...";
throw new SeCurisException("Error parsing JSON string to object: " + json, e);
@@ -85,10 +85,10 @@
}
return MAPPER.writeValueAsString(obj);
} catch (JsonProcessingException e) {
- log.error("Error formating JSON from object: {}", obj, e);
+ LOG.error("Error formating JSON from object: {}", obj, e);
throw new SeCurisException("Error formating JSON from object: " + obj, e);
} catch (IOException e) {
- log.error("Error formating JSON from object: {}", obj, e);
+ LOG.error("Error formating JSON from object: {}", obj, e);
throw new SeCurisException("Error formating JSON from object: " + obj, e);
}
}
@@ -111,10 +111,10 @@
MAPPER.disable(SerializationConfig.Feature.INDENT_OUTPUT);
return json;
} catch (JsonProcessingException e) {
- log.error("Error formating JSON from object: {}", obj, e);
+ LOG.error("Error formating JSON from object: {}", obj, e);
throw new SeCurisException("Error formating JSON from object: " + obj, e);
} catch (IOException e) {
- log.error("Error formating JSON from object: {}", obj, e);
+ LOG.error("Error formating JSON from object: {}", obj, e);
throw new SeCurisException("Error formating JSON from object: " + obj, e);
}
}
@@ -137,10 +137,10 @@
}
return MAPPER.readValue(json, Map.class);
} catch (JsonParseException e) {
- log.error("Error parsing JSON string to map: {}", json, e);
+ LOG.error("Error parsing JSON string to map: {}", json, e);
throw e;
} catch (IOException e) {
- log.error("Error parsing JSON string to map: {}", json, e);
+ LOG.error("Error parsing JSON string to map: {}", json, e);
}
return null;
}
@@ -160,9 +160,9 @@
}
return MAPPER.writeValueAsString(map);
} catch (JsonProcessingException e) {
- log.error("Error formating JSON from map: {}", map, e);
+ LOG.error("Error formating JSON from map: {}", map, e);
} catch (IOException e) {
- log.error("Error formating JSON from map: {}", map, e);
+ LOG.error("Error formating JSON from map: {}", map, e);
}
return null;
@@ -182,10 +182,10 @@
try {
return MAPPER.readValue(json, List.class);
} catch (JsonParseException e) {
- log.error("Error converting JSON string to object {}", json, e);
+ LOG.error("Error converting JSON string to object {}", json, e);
throw new SeCurisException("Error converting JSON to object", e);
} catch (IOException e) {
- log.error("Error converting JSON string to object {}", json, e);
+ LOG.error("Error converting JSON string to object {}", json, e);
throw new SeCurisException("Error converting JSON to object", e);
}
}
@@ -206,7 +206,7 @@
} catch (JsonParseException e) {
throw new SeCurisException("Error converting JSON to object", e);
} catch (IOException e) {
- log.error("Error converting JSON to object", e);
+ LOG.error("Error converting JSON to object", e);
throw new SeCurisException("Error converting JSON to object", e);
}
}
diff --git a/src/main/java/net/curisit/securis/utils/LicUtils.java b/src/main/java/net/curisit/securis/utils/LicUtils.java
index c3e19cd..964cca8 100644
--- a/src/main/java/net/curisit/securis/utils/LicUtils.java
+++ b/src/main/java/net/curisit/securis/utils/LicUtils.java
@@ -9,7 +9,7 @@
public class LicUtils {
- private static final Logger log = LogManager.getLogger(LicUtils.class);
+ private static final Logger LOG = LogManager.getLogger(LicUtils.class);
public static String md5(String str) {
try {
@@ -18,7 +18,7 @@
BigInteger i = new BigInteger(1, mDigest.digest());
return String.format("%1$032x", i);
} catch (NoSuchAlgorithmException e) {
- log.error("Error generating MD5 for string: " + str, e);
+ LOG.error("Error generating MD5 for string: " + str, e);
}
return null;
}
@@ -34,7 +34,7 @@
BigInteger i = new BigInteger(1, mDigest.digest());
return String.format("%1$064x", i);
} catch (NoSuchAlgorithmException e) {
- log.error("Error generating SHA-256 for bytes: " + bytes, e);
+ LOG.error("Error generating SHA-256 for bytes: " + bytes, e);
}
return null;
}
@@ -48,7 +48,7 @@
BigInteger i = new BigInteger(1, mDigest.digest());
return String.format("%1$064x", i);
} catch (NoSuchAlgorithmException e) {
- log.error("Error generating SHA-256 for bytes: " + bytes, e);
+ LOG.error("Error generating SHA-256 for bytes: " + bytes, e);
}
return null;
}
diff --git a/src/main/java/net/curisit/securis/utils/Params.java b/src/main/java/net/curisit/securis/utils/Params.java
index 3ccbb66..3127650 100644
--- a/src/main/java/net/curisit/securis/utils/Params.java
+++ b/src/main/java/net/curisit/securis/utils/Params.java
@@ -17,7 +17,7 @@
*/
public class Params {
- private static Logger log = LogManager.getLogger(Params.class);
+ private static final Logger LOG = LogManager.getLogger(Params.class);
/**
* Key used to store config file resource location. In a web application, can be set as initial parameter in a servlet loaded on startup
@@ -30,7 +30,7 @@
try {
loadParameters(KEY_CONFIG_FILE);
} catch (IOException e) {
- log.error("Config file {} was not found in classpath", KEY_CONFIG_FILE);
+ LOG.error("Config file {} was not found in classpath", KEY_CONFIG_FILE);
System.exit(-2);
}
}
@@ -44,16 +44,16 @@
*/
public static void loadParameters(String resource) throws IOException {
- log.debug("Loading params from " + resource);
+ LOG.debug("Loading params from " + resource);
InputStream fileis = Params.class.getResourceAsStream(resource);
params = new Properties();
try {
params.load(fileis);
- log.debug("Params loaded OK from {}", resource);
+ LOG.debug("Params loaded OK from {}", resource);
} catch (IOException e) {
- log.error("Error loading config file: " + e);
+ LOG.error("Error loading config file: " + e);
params = null;
throw e;
}
diff --git a/src/main/java/net/curisit/securis/utils/SignatureHelper.java b/src/main/java/net/curisit/securis/utils/SignatureHelper.java
index 41d41e5..a701a64 100644
--- a/src/main/java/net/curisit/securis/utils/SignatureHelper.java
+++ b/src/main/java/net/curisit/securis/utils/SignatureHelper.java
@@ -31,7 +31,7 @@
*/
public class SignatureHelper {
- private static final Logger log = LogManager.getLogger(SignatureHelper.class);
+ private static final Logger LOG = LogManager.getLogger(SignatureHelper.class);
private static String AUX = "hEDhryRjs2QRE";
private static SignatureHelper singleton = new SignatureHelper();
@@ -66,15 +66,15 @@
if (signature.verify(Base64.decodeBase64(licBean.getSignature())))
return;
} catch (NoSuchAlgorithmException e) {
- log.error("Error validating license for " + licBean, e);
+ LOG.error("Error validating license for " + licBean, e);
} catch (InvalidKeyException e) {
- log.error("Error validating license for " + licBean, e);
+ LOG.error("Error validating license for " + licBean, e);
} catch (InvalidKeySpecException e) {
- log.error("Error validating license for " + licBean, e);
+ LOG.error("Error validating license for " + licBean, e);
} catch (IOException e) {
- log.error("Error validating license for " + licBean, e);
+ LOG.error("Error validating license for " + licBean, e);
} catch (SignatureException e) {
- log.error("Error validating license for " + licBean, e);
+ LOG.error("Error validating license for " + licBean, e);
}
throw new SeCurisException("License could not be validated");
--
Gitblit v1.3.2