Roberto Sánchez
2014-02-24 3ef2ddd5cb1ee57317ffb757aceb86355a612a17
#593 feature - Changed CRC logo inclusion in request to optional, the
server will check if logo is mandatory or not
10 files modified
1 files renamed
changed files
pom.xml patch | view | blame | history
src/main/java/net/curisit/securis/HWInfo.java 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/ReqGenerator.java patch | view | blame | history
src/main/java/net/curisit/securis/SignatureHelper.java patch | view | blame | history
src/main/java/net/curisit/securis/beans/RequestBean.java patch | view | blame | history
src/main/java/net/curisit/securis/utils/Params.java patch | view | blame | history
src/main/resources/images/logo_customer2.png patch | view | blame | history
src/main/resources/securis-client.properties patch | view | blame | history
src/patch/java/net/curisit/securis/LicenseGenerator.java patch | view | blame | history
pom.xml
....@@ -13,6 +13,17 @@
1313 <target>1.7</target>
1414 </configuration>
1515 </plugin>
16
+ <plugin>
17
+ <artifactId>maven-assembly-plugin</artifactId>
18
+ <version>2.4</version>
19
+ <configuration>
20
+ <archive>
21
+ <manifest>
22
+ <mainClass>net.curisit.securis.License</mainClass>
23
+ </manifest>
24
+ </archive>
25
+ </configuration>
26
+ </plugin>
1627 </plugins>
1728 </build>
1829 <dependencies>
....@@ -46,5 +57,11 @@
4657 <artifactId>log4j-core</artifactId>
4758 <version>2.0-rc1</version>
4859 </dependency>
60
+ <dependency>
61
+ <groupId>org.apache.maven.plugins</groupId>
62
+ <artifactId>maven-assembly-plugin</artifactId>
63
+ <version>2.4</version>
64
+ <type>maven-plugin</type>
65
+ </dependency>
4966 </dependencies>
5067 </project>
src/main/java/net/curisit/securis/HWInfo.java
....@@ -79,7 +79,7 @@
7979 for (byte[] mac : macs) {
8080 macAddresses.add(printMacAddress(mac));
8181 }
82
- log.info("MAC Addresses: {}", macAddresses);
82
+ log.debug("MAC Addresses: {}", macAddresses);
8383 return macAddresses;
8484
8585 } catch (UnknownHostException e) {
src/main/java/net/curisit/securis/License.java
....@@ -2,7 +2,6 @@
22
33 import java.io.File;
44 import java.net.URISyntaxException;
5
-import java.util.Date;
65
76 import net.curisit.securis.utils.Params;
87
....@@ -16,21 +15,45 @@
1615 import org.apache.logging.log4j.LogManager;
1716 import org.apache.logging.log4j.Logger;
1817
18
+/**
19
+ * Main class when SeCuris client is used from command line.
20
+ *
21
+ * <pre>
22
+ * usage: securis-client [-c] [-g] [-h] [-l <lic_file>] [-r <lic_file>] [-s
23
+ * <url_license_server>] [-t]
24
+ * -c,--create Request a license file from server.
25
+ * --rfile and --server parameters are
26
+ * mandatory.
27
+ * -g,--gen_request Generate request file. If --rfile
28
+ * parameter is missing then It is
29
+ * generated in current directory.
30
+ * -h,--help Show help.
31
+ * -l,--validate <lic_file> Validate lic file.
32
+ * -r,--renew <lic_file> Synchronize/renew the current license
33
+ * file. --server parameter is mandatory.
34
+ * -s,--server <url_license_server> License server url.
35
+ * -t,--test_lc Test if License Server (LC) is
36
+ * available. --server parameter is
37
+ * mandatory.
38
+ * </pre>
39
+ *
40
+ * @author roberto <roberto.sanchez@curisit.net>
41
+ *
42
+ */
1943 public class License {
2044
21
- static {
22
- // BasicConfigurator.configure(new ConsoleAppender());
23
- // PropertyConfigurator.configure("/log4j.xml");
24
- // LogManager.getRootLogger().
25
- }
26
-
27
- // private static final Logger log = LoggerFactory.getLogger(License.class);
2845 private static final Logger log = LogManager.getLogger(License.class);
2946
47
+ /**
48
+ * Aplication entry point when it used as CLI
49
+ *
50
+ * @param args
51
+ * @throws URISyntaxException
52
+ */
3053 public static void main(String[] args) throws URISyntaxException {
3154 // Configuration conf = XMLConfigurationFactory.getInstance().getConfiguration("config", License.class.getResource("/log4j.xml").toURI());
3255
33
- log.info("Tool init {}", new Date());
56
+ log.debug("SeCuris client tool init ");
3457
3558 checkConfigFile();
3659 CommandLine cmd = getCommandLine(args);
....@@ -61,8 +84,43 @@
6184 System.exit(0);
6285 }
6386
87
+ if (cmd.hasOption('c')) {
88
+ String reqFilename = cmd.getOptionValue("rfile");
89
+ checkMandatoryParameter(reqFilename, "rfile");
90
+ String server = cmd.getOptionValue("server");
91
+ checkMandatoryParameter(server, "server");
92
+
93
+ log.warn("This command is not yet implemented");
94
+ System.exit(0);
95
+ }
96
+
97
+ if (cmd.hasOption('t')) {
98
+ String server = cmd.getOptionValue("server");
99
+ checkMandatoryParameter(server, "server");
100
+
101
+ log.warn("This command is not yet implemented");
102
+ System.exit(0);
103
+ }
104
+
105
+ if (cmd.hasOption('r')) {
106
+ String licFilename = cmd.getOptionValue("sync");
107
+ checkMandatoryParameter(licFilename, "sync");
108
+ String server = cmd.getOptionValue("server");
109
+ checkMandatoryParameter(server, "server");
110
+
111
+ log.warn("This command is not yet implemented");
112
+ System.exit(0);
113
+ }
114
+
64115 } catch (SeCurisException e) {
65116 log.error("The command generated an error: {}", e.toString());
117
+ }
118
+ }
119
+
120
+ private static void checkMandatoryParameter(String value, String param) {
121
+ if (value == null) {
122
+ log.error("Parameter {} is mandatory. Use --help to get information about parameters", param);
123
+ System.exit(-5);
66124 }
67125 }
68126
....@@ -120,7 +178,7 @@
120178 options.addOption("g", "gen_request", false, "Generate request file. If --rfile parameter is missing then It is generated in current directory.");
121179 options.addOption("c", "create", false, "Request a license file from server. --rfile and --server parameters are mandatory.");
122180 options.addOption("t", "test_lc", false, "Test if License Server (LC) is available. --server parameter is mandatory.");
123
- options.addOption(OptionBuilder.withArgName("lic_file").withLongOpt("sync").withDescription("Synchronize/renew the current license file. --server parameter is mandatory.").hasArg(true).create('y'));
181
+ options.addOption(OptionBuilder.withArgName("lic_file").withLongOpt("renew").withDescription("Synchronize/renew the current license file. --server parameter is mandatory.").hasArg(true).create('r'));
124182
125183 return options;
126184 }
src/main/java/net/curisit/securis/LicenseManager.java
....@@ -38,9 +38,7 @@
3838 * </p>
3939 *
4040 * @param licFile
41
- * @param appCode
42
- * @param customerCode
43
- * @return
41
+ * @return The license bean stored in file
4442 * @throws SeCurisException
4543 */
4644 public LicenseBean validateLicense(File licFile) throws SeCurisException {
....@@ -58,7 +56,7 @@
5856 }
5957
6058 /**
61
- * Creates a new request file with current hardware in the File passed as paramter
59
+ * Creates a new request file with current hardware in the File passed as parameter
6260 *
6361 * @param outputRequestFile
6462 * File where the request data will be saved
....@@ -83,6 +81,8 @@
8381 */
8482 public LicenseBean sync(File licenseFile) throws SeCurisException {
8583 LicenseBean lic = validateLicense(licenseFile);
84
+ if (true)
85
+ throw new SeCurisException("Action not implemented yet");
8686 // TODO: Send the current LicenseBean to server to check if a new one is prepared.
8787 return lic;
8888 }
src/main/java/net/curisit/securis/ReqGenerator.java
....@@ -71,7 +71,7 @@
7171 byte[] json;
7272 try {
7373 json = JsonUtils.toJSON(req, true).getBytes("utf-8");
74
- Files.write(Paths.get(file.toURI()), json, StandardOpenOption.CREATE);
74
+ Files.write(Paths.get(file.toURI()), json, StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING);
7575 } catch (UnsupportedEncodingException e) {
7676 log.error("Error creating json doc from request: " + req, e);
7777 throw new SeCurisException("Error creating json doc from request: " + req, e);
....@@ -80,13 +80,15 @@
8080 throw new SeCurisException("Error creating request file: " + file, e);
8181 }
8282
83
- log.info("License saved in {}", file);
83
+ log.debug("License saved in {}", file);
8484
8585 }
8686
8787 private String getCrcLogo() {
8888 String logResource = "images/logo_customer.png";
8989 InputStream is = getClass().getClassLoader().getResourceAsStream(logResource);
90
+ if (is == null)
91
+ return null;
9092 try {
9193 String shaLogo = LicUtils.sha256(IOUtils.toByteArray(is), LOGO_SECRET);
9294 return shaLogo;
src/main/java/net/curisit/securis/SignatureHelper.java
....@@ -14,13 +14,8 @@
1414 import java.security.spec.InvalidKeySpecException;
1515 import java.security.spec.PKCS8EncodedKeySpec;
1616 import java.security.spec.X509EncodedKeySpec;
17
-import java.util.Date;
18
-import java.util.HashMap;
19
-import java.util.Map;
2017
2118 import net.curisit.securis.beans.LicenseBean;
22
-import net.curisit.securis.beans.RequestBean;
23
-import net.curisit.securis.beans.SignedLicenseBean;
2419 import net.curisit.securis.utils.JsonUtils;
2520 import net.curisit.securis.utils.Params;
2621
....@@ -124,24 +119,6 @@
124119
125120 KeyPair kp = new KeyPair(publicKey, privateKey);
126121 return kp;
127
- }
128
-
129
- public static void main(String[] args) throws SeCurisException {
130
- // org.apache.log4j.Logger.getRootLogger().addAppender(new Appender);
131
- // DOMConfigurator.configure("/Users/cproberto/Documents/wsCurisIT/SeCurisClient/src/main/resources/log4j.xml");
132
- RequestBean req = ReqGenerator.getInstance().createRequest("CI", "Roberto");
133
-
134
- LicenseGenerator lg = LicenseGenerator.getInstance();
135
- Map<String, Object> metadata = new HashMap<>();
136
- metadata.put("maxUsers", 14);
137
- metadata.put("timeThreshold", 5000);
138
- metadata.put("123", 5000);
139
- metadata.put("Basdads", 5000);
140
- metadata.put("aasdads", 5000);
141
- metadata.put("maxInstances", 50);
142
- LicenseBean lic = lg.generateLicense(req, metadata, new Date(new Date().getTime() + 24 * 3600 * 1000 * 10), "L01", "LIC-TEST-001");
143
- System.out.println(JsonUtils.toJSON(lic, true));
144
- System.out.println(JsonUtils.toJSON(new SignedLicenseBean(lic), true));
145122 }
146123
147124 static {
src/main/java/net/curisit/securis/beans/RequestBean.java
....@@ -2,9 +2,9 @@
22
33 import java.util.List;
44
5
-import org.codehaus.jackson.annotate.JsonAutoDetect;
5
+import org.codehaus.jackson.map.annotate.JsonSerialize;
66
7
-@JsonAutoDetect
7
+@JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL)
88 public class RequestBean {
99 private String customerCode;
1010 private String crcLogo;
src/main/java/net/curisit/securis/utils/Params.java
....@@ -44,7 +44,7 @@
4444 */
4545 public static void loadParameters(String resource) throws IOException {
4646
47
- log.info("Loading params from " + resource);
47
+ log.debug("Loading params from " + resource);
4848 InputStream fileis = Params.class.getResourceAsStream(resource);
4949
5050 params = new Properties();
src/main/resources/images/logo_customer.png
similarity index 100%rename from src/main/resources/images/logo_customer.pngrename to src/main/resources/images/logo_customer2.pngBinary files differ
src/main/resources/securis-client.properties
....@@ -1,3 +1,3 @@
1
-public.key.file = /Users/cproberto/Documents/wsPython/doky/tests/mykey.pub
2
-app.code = CurisIntegrity
3
-customer.code = ROB
1
+public.key.file = __ADD_PUBLIC_KEY_FILE__
2
+app.code = __ADD_APP_CODE__
3
+customer.code = __ADD_APP_CODE__
src/patch/java/net/curisit/securis/LicenseGenerator.java
....@@ -80,7 +80,7 @@
8080 byte[] json;
8181 try {
8282 json = JsonUtils.toJSON(signedLic, true).getBytes("utf-8");
83
- Files.write(Paths.get(file.toURI()), json, StandardOpenOption.CREATE);
83
+ Files.write(Paths.get(file.toURI()), json, StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING);
8484 } catch (UnsupportedEncodingException e) {
8585 log.error("Error creating json doc from license: " + license, e);
8686 throw new SeCurisException("Error creating json doc from license: " + license, e);