Roberto Sánchez
2014-09-18 a4b1e4c32927208e92ca9895fa780e18051d3932
#0 feature - Fixed some SonarQube issues
10 files modified
changed files
pom.xml patch | view | blame | history
src/main/java/net/curisit/securis/License.java patch | view | blame | history
src/main/java/net/curisit/securis/LicenseManager.java patch | view | blame | history
src/main/java/net/curisit/securis/LicenseValidator.java patch | view | blame | history
src/main/java/net/curisit/securis/ReqGenerator.java patch | view | blame | history
src/main/java/net/curisit/securis/utils/HWInfo.java patch | view | blame | history
src/main/java/net/curisit/securis/utils/JsonUtils.java patch | view | blame | history
src/main/java/net/curisit/securis/utils/LicUtils.java patch | view | blame | history
src/main/java/net/curisit/securis/utils/Params.java patch | view | blame | history
src/main/java/net/curisit/securis/utils/SignatureHelper.java patch | view | blame | history
pom.xml
....@@ -3,7 +3,7 @@
33 <modelVersion>4.0.0</modelVersion>
44 <groupId>net.curisit</groupId>
55 <artifactId>securis-client</artifactId>
6
- <version>0.9.5-SNAPSHOT</version>
6
+ <version>0.9.6-SNAPSHOT</version>
77 <build>
88 <plugins>
99 <plugin>
src/main/java/net/curisit/securis/License.java
....@@ -42,7 +42,7 @@
4242 */
4343 public class License {
4444
45
- private static final Logger log = LogManager.getLogger(License.class);
45
+ private static final Logger LOG = LogManager.getLogger(License.class);
4646
4747 /**
4848 * Aplication entry point when it used as CLI
....@@ -51,9 +51,8 @@
5151 * @throws URISyntaxException
5252 */
5353 public static void main(String[] args) throws URISyntaxException {
54
- // Configuration conf = XMLConfigurationFactory.getInstance().getConfiguration("config", License.class.getResource("/log4j.xml").toURI());
5554
56
- log.debug("SeCuris client tool init ");
55
+ LOG.debug("SeCuris client tool init ");
5756
5857 checkConfigFile();
5958 CommandLine cmd = getCommandLine(args);
....@@ -65,7 +64,7 @@
6564 filename = "./license.req";
6665 File file = new File(filename);
6766 LicenseManager.getInstance().createRequestFile(file);
68
- log.info("Request file {} generated OK", file.getAbsolutePath());
67
+ LOG.info("Request file {} generated OK", file.getAbsolutePath());
6968 System.exit(0);
7069 }
7170
....@@ -76,10 +75,10 @@
7675 File file = new File(filename);
7776 try {
7877 LicenseManager.getInstance().validateLicense(file);
79
- log.info("License file {} is valid", file.getAbsolutePath());
78
+ LOG.info("License file {} is valid", file.getAbsolutePath());
8079 } catch (SeCurisException e) {
81
- log.info("License file {} is NOT valid", file.getAbsolutePath());
82
- log.info("Reason: {}", e.toString());
80
+ LOG.info("License file {} is NOT valid", file.getAbsolutePath());
81
+ LOG.info("Reason: {}", e.toString());
8382 }
8483
8584 System.exit(0);
....@@ -89,30 +88,30 @@
8988 String reqFilename = cmd.getOptionValue("rfile");
9089 checkMandatoryParameter(reqFilename, "rfile");
9190
92
- log.warn("This command is not yet implemented");
91
+ LOG.warn("This command is not yet implemented");
9392 System.exit(0);
9493 }
9594
9695 if (cmd.hasOption('t')) {
97
- log.warn("This command is not yet implemented");
96
+ LOG.warn("This command is not yet implemented");
9897 System.exit(0);
9998 }
10099
101100 if (cmd.hasOption('r')) {
102101 String licFilename = cmd.getOptionValue("renew");
103102 checkMandatoryParameter(licFilename, "renew");
104
- log.warn("This command is not yet implemented");
103
+ LOG.warn("This command is not yet implemented");
105104 System.exit(0);
106105 }
107106
108107 } catch (SeCurisException e) {
109
- log.error("The command generated an error: {}", e.toString());
108
+ LOG.error("The command generated an error: {}", e.toString());
110109 }
111110 }
112111
113112 private static void checkMandatoryParameter(String value, String param) {
114113 if (value == null) {
115
- log.error("Parameter {} is mandatory. Use --help to get information about parameters", param);
114
+ LOG.error("Parameter {} is mandatory. Use --help to get information about parameters", param);
116115 System.exit(-5);
117116 }
118117 }
....@@ -123,12 +122,12 @@
123122 private static void checkConfigFile() {
124123 String appCode = Params.get(Params.KEYS.APPLICATION_CODE);
125124 if (appCode == null) {
126
- log.error("Manadatory parameter {} is not set in config file", Params.KEYS.APPLICATION_CODE);
125
+ LOG.error("Manadatory parameter {} is not set in config file", Params.KEYS.APPLICATION_CODE);
127126 System.exit(-3);
128127 }
129128 String customerCode = Params.get(Params.KEYS.CUSTOMER_CODE);
130129 if (customerCode == null) {
131
- log.error("Manadatory parameter {} is not set in config file", Params.KEYS.CUSTOMER_CODE);
130
+ LOG.error("Manadatory parameter {} is not set in config file", Params.KEYS.CUSTOMER_CODE);
132131 System.exit(-4);
133132 }
134133 }
src/main/java/net/curisit/securis/LicenseManager.java
....@@ -25,7 +25,7 @@
2525 */
2626 public class LicenseManager {
2727
28
- private static final Logger log = LogManager.getLogger(License.class);
28
+ private static final Logger LOG = LogManager.getLogger(License.class);
2929
3030 private static LicenseManager singleton = new LicenseManager();
3131
....@@ -109,14 +109,14 @@
109109 json = JsonUtils.toJSON(signedLic, true).getBytes("utf-8");
110110 Files.write(Paths.get(file.toURI()), json, StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING);
111111 } catch (UnsupportedEncodingException e) {
112
- log.error("Error creating json doc from license: " + license, e);
112
+ LOG.error("Error creating json doc from license: " + license, e);
113113 throw new SeCurisException("Error creating json doc from license: " + license, e);
114114 } catch (IOException e) {
115
- log.error("Error creating license file: " + file, e);
115
+ LOG.error("Error creating license file: " + file, e);
116116 throw new SeCurisException("Error creating json doc from license: " + license, e);
117117 }
118118
119
- log.debug("License saved in {}", file);
119
+ LOG.debug("License saved in {}", file);
120120
121121 }
122122
src/main/java/net/curisit/securis/LicenseValidator.java
....@@ -14,7 +14,7 @@
1414
1515 public class LicenseValidator {
1616
17
- private static final Logger log = LogManager.getLogger(LicenseValidator.class);
17
+ private static final Logger LOG = LogManager.getLogger(LicenseValidator.class);
1818
1919 private static LicenseValidator singleton = new LicenseValidator();
2020 protected static byte[] LOGO_SECRET;
....@@ -23,7 +23,7 @@
2323 try {
2424 LOGO_SECRET = "Logo ipsum s3cr3t test áíóú".getBytes("utf-8");
2525 } catch (UnsupportedEncodingException e) {
26
- log.error("Unexpected error getting LOGO secret", e);
26
+ LOG.error("Unexpected error getting LOGO secret", e);
2727 }
2828 }
2929
....@@ -43,14 +43,14 @@
4343 String shaLogo = LicUtils.sha256(IOUtils.toByteArray(is), LOGO_SECRET);
4444 return shaLogo;
4545 } catch (IOException e) {
46
- log.warn("Customer logo was not found in images/logo_customer.png");
46
+ LOG.warn("Customer logo was not found in images/logo_customer.png");
4747 return null;
4848 }
4949 }
5050
5151 public void validateLogo(RequestBean reqBean) throws SeCurisException {
5252 if (reqBean.getCrcLogo() == null) {
53
- log.info("Customer logo is not included in license file and won't be validated");
53
+ LOG.info("Customer logo is not included in license file and won't be validated");
5454 } else {
5555 String currentCRC = getCrcLogo();
5656 if (!currentCRC.equals(reqBean.getCrcLogo()))
src/main/java/net/curisit/securis/ReqGenerator.java
....@@ -19,7 +19,7 @@
1919
2020 public class ReqGenerator {
2121
22
- private static final Logger log = LogManager.getLogger(ReqGenerator.class);
22
+ private static final Logger LOG = LogManager.getLogger(ReqGenerator.class);
2323
2424 private static ReqGenerator singleton = new ReqGenerator();
2525
....@@ -49,7 +49,7 @@
4949 RequestBean req = JsonUtils.json2object(json, RequestBean.class);
5050 return req;
5151 } catch (IOException e) {
52
- log.error("Request file {} was not found or is not accesible");
52
+ LOG.error("Request file {} was not found or is not accesible");
5353 throw new SeCurisException("ERROR accesing request file: " + requestFile.getAbsolutePath(), e);
5454 }
5555 }
....@@ -67,14 +67,14 @@
6767 json = JsonUtils.toJSON(req, true).getBytes("utf-8");
6868 Files.write(Paths.get(file.toURI()), json, StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING);
6969 } catch (UnsupportedEncodingException e) {
70
- log.error("Error creating json doc from request: " + req, e);
70
+ LOG.error("Error creating json doc from request: " + req, e);
7171 throw new SeCurisException("Error creating json doc from request: " + req, e);
7272 } catch (IOException e) {
73
- log.error("Error creating request file: " + file, e);
73
+ LOG.error("Error creating request file: " + file, e);
7474 throw new SeCurisException("Error creating request file: " + file, e);
7575 }
7676
77
- log.debug("License saved in {}", file);
77
+ LOG.debug("License saved in {}", file);
7878
7979 }
8080
....@@ -87,7 +87,7 @@
8787 String shaLogo = LicUtils.sha256(IOUtils.toByteArray(is), LicenseValidator.LOGO_SECRET);
8888 return shaLogo;
8989 } catch (IOException e) {
90
- log.error("Customer logo was not found in classpath in " + logResource, e);
90
+ LOG.error("Customer logo was not found in classpath in " + logResource, e);
9191 return null;
9292 }
9393 }
src/main/java/net/curisit/securis/utils/HWInfo.java
....@@ -21,7 +21,7 @@
2121 */
2222 public class HWInfo {
2323
24
- private static final Logger log = LogManager.getLogger(HWInfo.class);
24
+ private static final Logger LOG = LogManager.getLogger(HWInfo.class);
2525
2626 public static String getOsName() {
2727 return System.getProperty("os.name");
....@@ -47,7 +47,7 @@
4747 for (NetworkInterface network : Collections.list(NetworkInterface.getNetworkInterfaces())) {
4848 if (!network.isLoopback() && !network.isVirtual() && !network.isPointToPoint() && network.getHardwareAddress() != null) {
4949 macs.add(network.getHardwareAddress());
50
- log.debug("Interface added {}, MAC: {}", network.getName(), network.getHardwareAddress());
50
+ LOG.debug("Interface added {}, MAC: {}", network.getName(), network.getHardwareAddress());
5151 logInterface(network);
5252 }
5353 }
....@@ -57,7 +57,7 @@
5757 NetworkInterface network = NetworkInterface.getByInetAddress(InetAddress.getLocalHost());
5858 if (network.getHardwareAddress() != null)
5959 macs.add(network.getHardwareAddress());
60
- log.debug("Selected interface (Inet Address rule)");
60
+ LOG.debug("Selected interface (Inet Address rule)");
6161 logInterface(network);
6262 }
6363
....@@ -67,7 +67,7 @@
6767 if (!network.isLoopback() && !network.isVirtual() && !network.isPointToPoint() && network.getHardwareAddress() != null) {
6868 if (network.getHardwareAddress() != null)
6969 macs.add(network.getHardwareAddress());
70
- log.debug("Selected interface (Any with MAC rule)");
70
+ LOG.debug("Selected interface (Any with MAC rule)");
7171 logInterface(network);
7272 break;
7373 }
....@@ -81,7 +81,7 @@
8181 for (byte[] mac : macs) {
8282 macAddresses.add(printMacAddress(mac));
8383 }
84
- log.debug("MAC Addresses: {}", macAddresses);
84
+ LOG.debug("MAC Addresses: {}", macAddresses);
8585 return macAddresses;
8686
8787 } catch (UnknownHostException e) {
....@@ -103,10 +103,10 @@
103103 }
104104
105105 private static void logInterface(NetworkInterface network) {
106
- log.debug("Interface name: {}", network.getName());
107
- log.debug("Interface display name: {}", network.getDisplayName());
106
+ LOG.debug("Interface name: {}", network.getName());
107
+ LOG.debug("Interface display name: {}", network.getDisplayName());
108108 try {
109
- log.debug("Interface mac: {}", printMacAddress(network.getHardwareAddress()));
109
+ LOG.debug("Interface mac: {}", printMacAddress(network.getHardwareAddress()));
110110 } catch (SocketException e) {
111111 // Silent
112112 }
src/main/java/net/curisit/securis/utils/JsonUtils.java
....@@ -22,7 +22,7 @@
2222 */
2323 public class JsonUtils {
2424
25
- private static final Logger log = LogManager.getLogger(JsonUtils.class);
25
+ private static final Logger LOG = LogManager.getLogger(JsonUtils.class);
2626
2727 final private static ObjectMapper MAPPER = new ObjectMapper();
2828
....@@ -58,12 +58,12 @@
5858 }
5959 return MAPPER.readValue(json, type);
6060 } catch (JsonParseException e) {
61
- log.error("Error parsing JSON string to obejct: {}", json, e);
61
+ LOG.error("Error parsing JSON string to obejct: {}", json, e);
6262 if (json.length() > 60)
6363 json = json.substring(0, 50) + "...";
6464 throw new SeCurisException("Error parsing JSON string to object: " + json, e);
6565 } catch (IOException e) {
66
- log.error("Error parsing JSON string to object: {}", json, e);
66
+ LOG.error("Error parsing JSON string to object: {}", json, e);
6767 if (json.length() > 60)
6868 json = json.substring(0, 50) + "...";
6969 throw new SeCurisException("Error parsing JSON string to object: " + json, e);
....@@ -85,10 +85,10 @@
8585 }
8686 return MAPPER.writeValueAsString(obj);
8787 } catch (JsonProcessingException e) {
88
- log.error("Error formating JSON from object: {}", obj, e);
88
+ LOG.error("Error formating JSON from object: {}", obj, e);
8989 throw new SeCurisException("Error formating JSON from object: " + obj, e);
9090 } catch (IOException e) {
91
- log.error("Error formating JSON from object: {}", obj, e);
91
+ LOG.error("Error formating JSON from object: {}", obj, e);
9292 throw new SeCurisException("Error formating JSON from object: " + obj, e);
9393 }
9494 }
....@@ -111,10 +111,10 @@
111111 MAPPER.disable(SerializationConfig.Feature.INDENT_OUTPUT);
112112 return json;
113113 } catch (JsonProcessingException e) {
114
- log.error("Error formating JSON from object: {}", obj, e);
114
+ LOG.error("Error formating JSON from object: {}", obj, e);
115115 throw new SeCurisException("Error formating JSON from object: " + obj, e);
116116 } catch (IOException e) {
117
- log.error("Error formating JSON from object: {}", obj, e);
117
+ LOG.error("Error formating JSON from object: {}", obj, e);
118118 throw new SeCurisException("Error formating JSON from object: " + obj, e);
119119 }
120120 }
....@@ -137,10 +137,10 @@
137137 }
138138 return MAPPER.readValue(json, Map.class);
139139 } catch (JsonParseException e) {
140
- log.error("Error parsing JSON string to map: {}", json, e);
140
+ LOG.error("Error parsing JSON string to map: {}", json, e);
141141 throw e;
142142 } catch (IOException e) {
143
- log.error("Error parsing JSON string to map: {}", json, e);
143
+ LOG.error("Error parsing JSON string to map: {}", json, e);
144144 }
145145 return null;
146146 }
....@@ -160,9 +160,9 @@
160160 }
161161 return MAPPER.writeValueAsString(map);
162162 } catch (JsonProcessingException e) {
163
- log.error("Error formating JSON from map: {}", map, e);
163
+ LOG.error("Error formating JSON from map: {}", map, e);
164164 } catch (IOException e) {
165
- log.error("Error formating JSON from map: {}", map, e);
165
+ LOG.error("Error formating JSON from map: {}", map, e);
166166 }
167167
168168 return null;
....@@ -182,10 +182,10 @@
182182 try {
183183 return MAPPER.readValue(json, List.class);
184184 } catch (JsonParseException e) {
185
- log.error("Error converting JSON string to object {}", json, e);
185
+ LOG.error("Error converting JSON string to object {}", json, e);
186186 throw new SeCurisException("Error converting JSON to object", e);
187187 } catch (IOException e) {
188
- log.error("Error converting JSON string to object {}", json, e);
188
+ LOG.error("Error converting JSON string to object {}", json, e);
189189 throw new SeCurisException("Error converting JSON to object", e);
190190 }
191191 }
....@@ -206,7 +206,7 @@
206206 } catch (JsonParseException e) {
207207 throw new SeCurisException("Error converting JSON to object", e);
208208 } catch (IOException e) {
209
- log.error("Error converting JSON to object", e);
209
+ LOG.error("Error converting JSON to object", e);
210210 throw new SeCurisException("Error converting JSON to object", e);
211211 }
212212 }
src/main/java/net/curisit/securis/utils/LicUtils.java
....@@ -9,7 +9,7 @@
99
1010 public class LicUtils {
1111
12
- private static final Logger log = LogManager.getLogger(LicUtils.class);
12
+ private static final Logger LOG = LogManager.getLogger(LicUtils.class);
1313
1414 public static String md5(String str) {
1515 try {
....@@ -18,7 +18,7 @@
1818 BigInteger i = new BigInteger(1, mDigest.digest());
1919 return String.format("%1$032x", i);
2020 } catch (NoSuchAlgorithmException e) {
21
- log.error("Error generating MD5 for string: " + str, e);
21
+ LOG.error("Error generating MD5 for string: " + str, e);
2222 }
2323 return null;
2424 }
....@@ -34,7 +34,7 @@
3434 BigInteger i = new BigInteger(1, mDigest.digest());
3535 return String.format("%1$064x", i);
3636 } catch (NoSuchAlgorithmException e) {
37
- log.error("Error generating SHA-256 for bytes: " + bytes, e);
37
+ LOG.error("Error generating SHA-256 for bytes: " + bytes, e);
3838 }
3939 return null;
4040 }
....@@ -48,7 +48,7 @@
4848 BigInteger i = new BigInteger(1, mDigest.digest());
4949 return String.format("%1$064x", i);
5050 } catch (NoSuchAlgorithmException e) {
51
- log.error("Error generating SHA-256 for bytes: " + bytes, e);
51
+ LOG.error("Error generating SHA-256 for bytes: " + bytes, e);
5252 }
5353 return null;
5454 }
src/main/java/net/curisit/securis/utils/Params.java
....@@ -17,7 +17,7 @@
1717 */
1818 public class Params {
1919
20
- private static Logger log = LogManager.getLogger(Params.class);
20
+ private static final Logger LOG = LogManager.getLogger(Params.class);
2121
2222 /**
2323 * 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 @@
3030 try {
3131 loadParameters(KEY_CONFIG_FILE);
3232 } catch (IOException e) {
33
- log.error("Config file {} was not found in classpath", KEY_CONFIG_FILE);
33
+ LOG.error("Config file {} was not found in classpath", KEY_CONFIG_FILE);
3434 System.exit(-2);
3535 }
3636 }
....@@ -44,16 +44,16 @@
4444 */
4545 public static void loadParameters(String resource) throws IOException {
4646
47
- log.debug("Loading params from " + resource);
47
+ LOG.debug("Loading params from " + resource);
4848 InputStream fileis = Params.class.getResourceAsStream(resource);
4949
5050 params = new Properties();
5151 try {
5252
5353 params.load(fileis);
54
- log.debug("Params loaded OK from {}", resource);
54
+ LOG.debug("Params loaded OK from {}", resource);
5555 } catch (IOException e) {
56
- log.error("Error loading config file: " + e);
56
+ LOG.error("Error loading config file: " + e);
5757 params = null;
5858 throw e;
5959 }
src/main/java/net/curisit/securis/utils/SignatureHelper.java
....@@ -31,7 +31,7 @@
3131 */
3232 public class SignatureHelper {
3333
34
- private static final Logger log = LogManager.getLogger(SignatureHelper.class);
34
+ private static final Logger LOG = LogManager.getLogger(SignatureHelper.class);
3535 private static String AUX = "hEDhryRjs2QRE";
3636
3737 private static SignatureHelper singleton = new SignatureHelper();
....@@ -66,15 +66,15 @@
6666 if (signature.verify(Base64.decodeBase64(licBean.getSignature())))
6767 return;
6868 } catch (NoSuchAlgorithmException e) {
69
- log.error("Error validating license for " + licBean, e);
69
+ LOG.error("Error validating license for " + licBean, e);
7070 } catch (InvalidKeyException e) {
71
- log.error("Error validating license for " + licBean, e);
71
+ LOG.error("Error validating license for " + licBean, e);
7272 } catch (InvalidKeySpecException e) {
73
- log.error("Error validating license for " + licBean, e);
73
+ LOG.error("Error validating license for " + licBean, e);
7474 } catch (IOException e) {
75
- log.error("Error validating license for " + licBean, e);
75
+ LOG.error("Error validating license for " + licBean, e);
7676 } catch (SignatureException e) {
77
- log.error("Error validating license for " + licBean, e);
77
+ LOG.error("Error validating license for " + licBean, e);
7878 }
7979 throw new SeCurisException("License could not be validated");
8080