rsanchez
2014-10-22 09bb2b3b9300e332f8b743481fbb412df8cd2a89
#2021 feature - Added changes on client to use PackID and other changes
related with license file fields
9 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/beans/LicenseBean.java patch | view | blame | history
src/main/java/net/curisit/securis/beans/RequestBean.java patch | view | blame | history
src/main/java/net/curisit/securis/beans/SignedLicenseBean.java patch | view | blame | history
src/main/java/net/curisit/securis/utils/Params.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>1.0.0-SNAPSHOT</version>
6
+ <version>1.0.1-SNAPSHOT</version>
77 <build>
88 <plugins>
99 <plugin>
src/main/java/net/curisit/securis/License.java
....@@ -15,7 +15,6 @@
1515 import org.apache.commons.cli.PosixParser;
1616 import org.apache.logging.log4j.LogManager;
1717 import org.apache.logging.log4j.Logger;
18
-import org.codehaus.jackson.map.DeserializerFactory.Config;
1918
2019 /**
2120 * Main class when SeCuris client is used from command line.
....@@ -44,70 +43,70 @@
4443
4544 private static final Logger LOG = LogManager.getLogger(License.class);
4645
47
- /**
48
- * Aplication entry point when it used as CLI
49
- *
50
- * @param args
51
- * @throws URISyntaxException
52
- */
53
- public static void main(String[] args) throws URISyntaxException {
46
+ /**
47
+ * Aplication entry point when it used as CLI
48
+ *
49
+ * @param args
50
+ * @throws URISyntaxException
51
+ */
52
+ public static void main(String[] args) throws URISyntaxException {
5453
55
- LOG.debug("SeCuris client tool init ");
54
+ LOG.debug("SeCuris client tool init ");
5655
57
- checkConfigFile();
58
- CommandLine cmd = getCommandLine(args);
56
+ checkConfigFile();
57
+ CommandLine cmd = getCommandLine(args);
5958
60
- try {
61
- if (cmd.hasOption('g')) {
62
- String filename = cmd.getOptionValue("rfile");
63
- if (filename == null)
64
- filename = "./license.req";
65
- File file = new File(filename);
66
- LicenseManager.getInstance().createRequestFile(file);
67
- LOG.info("Request file {} generated OK", file.getAbsolutePath());
68
- System.exit(0);
69
- }
59
+ try {
60
+ if (cmd.hasOption('g')) {
61
+ String filename = cmd.getOptionValue("rfile");
62
+ if (filename == null)
63
+ filename = "./license.req";
64
+ File file = new File(filename);
65
+ LicenseManager.getInstance().createRequestFile(file);
66
+ LOG.info("Request file {} generated OK", file.getAbsolutePath());
67
+ System.exit(0);
68
+ }
7069
71
- if (cmd.hasOption('l')) {
72
- String filename = cmd.getOptionValue("validate");
73
- if (filename == null)
74
- filename = "./license.lic";
75
- File file = new File(filename);
76
- if (!file.exists()) {
77
- throw new SeCurisException("The license file doesn't exist: " + file.getAbsolutePath());
78
- }
79
- try {
80
- LicenseManager.getInstance().validateLicense(file);
81
- LOG.info("License file {} is valid", file.getAbsolutePath());
82
- } catch (SeCurisException e) {
83
- LOG.info("License file {} is NOT valid", file.getAbsolutePath());
84
- LOG.info("Reason: {}", e.toString());
85
- }
70
+ if (cmd.hasOption('l')) {
71
+ String filename = cmd.getOptionValue("validate");
72
+ if (filename == null)
73
+ filename = "./license.lic";
74
+ File file = new File(filename);
75
+ if (!file.exists()) {
76
+ throw new SeCurisException("The license file doesn't exist: " + file.getAbsolutePath());
77
+ }
78
+ try {
79
+ LicenseManager.getInstance().validateLicense(file);
80
+ LOG.info("License file {} is valid", file.getAbsolutePath());
81
+ } catch (SeCurisException e) {
82
+ LOG.info("License file {} is NOT valid", file.getAbsolutePath());
83
+ LOG.info("Reason: {}", e.toString());
84
+ }
8685
87
- System.exit(0);
88
- }
86
+ System.exit(0);
87
+ }
8988
90
- if (cmd.hasOption('c')) {
91
- SignedLicenseBean lic = LicenseManager.getInstance().requestLicense();
92
- String filename = cmd.getOptionValue("c");
89
+ if (cmd.hasOption('c')) {
90
+ SignedLicenseBean lic = LicenseManager.getInstance().requestLicense();
91
+ String filename = cmd.getOptionValue("c");
9392 if (filename == null)
9493 filename = "./license.lic";
9594 File file = new File(filename);
9695 LicenseManager.getInstance().save(lic, file);
9796 LOG.info("License file sucessfully saved in file: {}", file.getAbsolutePath());
9897 System.exit(0);
99
- }
98
+ }
10099
101
- if (cmd.hasOption('t')) {
100
+ if (cmd.hasOption('t')) {
102101 LicenseManager.getInstance().testServer();
103102 LOG.info("Server is OK, url: {}", Params.get(Params.KEYS.LICENSE_SERVER_URL, Params.DEFAUT_SERVER_URL));
104103
105104 System.exit(0);
106
- }
105
+ }
107106
108
- if (cmd.hasOption('r')) {
109
- String licFilename = cmd.getOptionValue("renew");
110
- checkMandatoryParameter(licFilename, "renew");
107
+ if (cmd.hasOption('r')) {
108
+ String licFilename = cmd.getOptionValue("renew");
109
+ checkMandatoryParameter(licFilename, "renew");
111110 File file = new File(licFilename);
112111 if (!file.exists()) {
113112 throw new SeCurisException("The license file doesn't exist: " + file.getAbsolutePath());
....@@ -118,77 +117,84 @@
118117 LOG.info("Old license file has been renamed to: {}", oldLicFile.getAbsolutePath());
119118 LicenseManager.getInstance().save(newLic, file);
120119 LOG.info("New license file saved as: {}", file.getAbsolutePath());
121
- System.exit(0);
122
- }
120
+ System.exit(0);
121
+ }
123122
124
- } catch (SeCurisException e) {
125
- LOG.error("The command generated an error: {}", e.toString());
126
- }
127
- }
123
+ } catch (SeCurisException e) {
124
+ LOG.error("The command generated an error: {}", e.toString());
125
+ }
126
+ }
128127
129
- private static void checkMandatoryParameter(String value, String param) {
130
- if (value == null) {
131
- LOG.error("Parameter {} is mandatory. Use --help to get information about parameters", param);
132
- System.exit(-5);
133
- }
134
- }
128
+ private static void checkMandatoryParameter(String value, String param) {
129
+ if (value == null) {
130
+ LOG.error("Parameter {} is mandatory. Use --help to get information about parameters", param);
131
+ System.exit(-5);
132
+ }
133
+ }
135134
136
- /**
137
- * Checks that config file exists and contains mandatory parameters
138
- */
139
- private static void checkConfigFile() {
140
- String appCode = Params.get(Params.KEYS.APPLICATION_CODE);
141
- if (appCode == null) {
142
- LOG.error("Manadatory parameter {} is not set in config file", Params.KEYS.APPLICATION_CODE);
143
- System.exit(-3);
144
- }
145
- String customerCode = Params.get(Params.KEYS.CUSTOMER_CODE);
146
- if (customerCode == null) {
147
- LOG.error("Manadatory parameter {} is not set in config file", Params.KEYS.CUSTOMER_CODE);
148
- System.exit(-4);
149
- }
150
- }
135
+ /**
136
+ * Checks that config file exists and contains mandatory parameters
137
+ */
138
+ private static void checkConfigFile() {
139
+ if (Params.get(Params.KEYS.APPLICATION_CODE) == null) {
140
+ LOG.error("Manadatory parameter {} is not set in config file", Params.KEYS.APPLICATION_CODE);
141
+ System.exit(-3);
142
+ }
143
+ if (Params.get(Params.KEYS.CUSTOMER_CODE) == null) {
144
+ LOG.error("Manadatory parameter {} is not set in config file", Params.KEYS.CUSTOMER_CODE);
145
+ System.exit(-4);
146
+ }
147
+ if (Params.get(Params.KEYS.PACK_CODE) == null) {
148
+ LOG.error("Manadatory parameter {} is not set in config file", Params.KEYS.PACK_CODE);
149
+ System.exit(-6);
150
+ }
151
+ }
151152
152
- private static CommandLine getCommandLine(String[] args) {
153
- Options ops = prepareOptionCLI();
154
- if (args.length == 0) {
155
- printHelp(ops);
156
- }
157
- CommandLineParser parser = new PosixParser();
158
- CommandLine cmd = null;
159
- try {
160
- cmd = parser.parse(ops, args);
161
- } catch (ParseException e) {
162
- printHelp(ops);
163
- }
153
+ private static CommandLine getCommandLine(String[] args) {
154
+ Options ops = prepareOptionCLI();
155
+ if (args.length == 0) {
156
+ printHelp(ops);
157
+ }
158
+ CommandLineParser parser = new PosixParser();
159
+ CommandLine cmd = null;
160
+ try {
161
+ cmd = parser.parse(ops, args);
162
+ } catch (ParseException e) {
163
+ printHelp(ops);
164
+ }
164165
165
- if (cmd.hasOption('h')) {
166
- printHelp(ops);
167
- }
166
+ if (cmd.hasOption('h')) {
167
+ printHelp(ops);
168
+ }
168169
169
- return cmd;
170
- }
170
+ return cmd;
171
+ }
171172
172
- private static void printHelp(Options ops) {
173
- HelpFormatter formatter = new HelpFormatter();
174
- formatter.printHelp("securis-client", ops, true);
175
- System.exit(-1);
176
- }
173
+ private static void printHelp(Options ops) {
174
+ HelpFormatter formatter = new HelpFormatter();
175
+ formatter.printHelp("securis-client", ops, true);
176
+ System.exit(-1);
177
+ }
177178
178
- @SuppressWarnings("static-access")
179
- private static Options prepareOptionCLI() {
180
- Options options = new Options();
179
+ @SuppressWarnings("static-access")
180
+ private static Options prepareOptionCLI() {
181
+ Options options = new Options();
181182
182
- options.addOption("h", "help", false, "Show help.");
183
- options.addOption(OptionBuilder.withArgName("req_file").withLongOpt("rfile").withDescription("Set request file for its generation or for license requesting.").hasArg(true).create('r'));
184
- // options.addOption(OptionBuilder.withArgName("url_license_server").withLongOpt("server").withDescription("License server url.").hasArg(true).create('s'));
185
- options.addOption(OptionBuilder.withArgName("lic_file").withLongOpt("validate").withDescription("Validate lic file.").hasArg(true).create('l'));
183
+ options.addOption("h", "help", false, "Show help.");
184
+ options.addOption(OptionBuilder.withArgName("req_file").withLongOpt("rfile")
185
+ .withDescription("Set request file for its generation or for license requesting.").hasArg(true).create('r'));
186
+ // options.addOption(OptionBuilder.withArgName("url_license_server").withLongOpt("server").withDescription("License server url.").hasArg(true).create('s'));
187
+ options.addOption(OptionBuilder.withArgName("lic_file").withLongOpt("validate").withDescription("Validate lic file.").hasArg(true)
188
+ .create('l'));
186189
187
- options.addOption("g", "gen_request", false, "Generate request file. If --rfile parameter is missing then It is generated in current directory.");
188
- options.addOption(OptionBuilder.withArgName("lic_file").withLongOpt("create").withDescription("Request a license file to server.").hasArg(true).hasOptionalArg().create('c'));
189
- options.addOption("t", "test_lc", false, "Test if License Server (LC) is available. ");
190
- options.addOption(OptionBuilder.withArgName("lic_file").withLongOpt("renew").withDescription("Synchronize/renew the current license file.").hasArg(true).create('r'));
190
+ options.addOption("g", "gen_request", false,
191
+ "Generate request file. If --rfile parameter is missing then It is generated in current directory.");
192
+ options.addOption(OptionBuilder.withArgName("lic_file").withLongOpt("create").withDescription("Request a license file to server.")
193
+ .hasArg(true).hasOptionalArg().create('c'));
194
+ options.addOption("t", "test_lc", false, "Test if License Server (LC) is available. ");
195
+ options.addOption(OptionBuilder.withArgName("lic_file").withLongOpt("renew").withDescription("Synchronize/renew the current license file.")
196
+ .hasArg(true).create('r'));
191197
192
- return options;
193
- }
198
+ return options;
199
+ }
194200 }
src/main/java/net/curisit/securis/LicenseManager.java
....@@ -28,38 +28,39 @@
2828 */
2929 public class LicenseManager {
3030
31
- private static final Logger LOG = LogManager.getLogger(License.class);
31
+ private static final Logger LOG = LogManager.getLogger(License.class);
3232
33
- private static LicenseManager singleton = new LicenseManager();
33
+ private static LicenseManager singleton = new LicenseManager();
3434
35
- public static final String PING_MESSAGE = "SeCuris API OK";
36
-
37
- private LicenseManager() {
38
- }
35
+ public static final String PING_MESSAGE = "SeCuris API OK";
3936
40
- public static LicenseManager getInstance() {
41
- return singleton;
42
- }
37
+ private LicenseManager() {
38
+ }
4339
44
- /**
45
- * Loads a license from file
46
- *
47
- * @param licFile
48
- * @return The license bean
49
- * @throws SeCurisException
50
- */
51
- public LicenseBean load(File licFile) throws SeCurisException {
52
- LicenseBean licBean;
53
- try {
54
- licBean = JsonUtils.json2object(FileUtils.readFileToString(licFile), LicenseBean.class);
55
- } catch (IOException e) {
56
- throw new SeCurisException("Error getting license data from file: " + licFile, e);
57
- }
58
- return licBean;
59
- }
40
+ public static LicenseManager getInstance() {
41
+ return singleton;
42
+ }
6043
6144 /**
62
- * Validates the license stored in {@code licFile} and get the corresponding LicenseBean
45
+ * Loads a license from file
46
+ *
47
+ * @param licFile
48
+ * @return The license bean
49
+ * @throws SeCurisException
50
+ */
51
+ public LicenseBean load(File licFile) throws SeCurisException {
52
+ LicenseBean licBean;
53
+ try {
54
+ licBean = JsonUtils.json2object(FileUtils.readFileToString(licFile), LicenseBean.class);
55
+ } catch (IOException e) {
56
+ throw new SeCurisException("Error getting license data from file: " + licFile, e);
57
+ }
58
+ return licBean;
59
+ }
60
+
61
+ /**
62
+ * Validates the license stored in {@code licFile} and get the corresponding
63
+ * LicenseBean
6364 * <p>
6465 * The validation includes:
6566 * <ul>
....@@ -79,7 +80,8 @@
7980 }
8081
8182 /**
82
- * Validates the license stored in {@code licFile} and get the corresponding LicenseBean. The License date is not validated
83
+ * Validates the license stored in {@code licFile} and get the corresponding
84
+ * LicenseBean. The License date is not validated
8385 * <p>
8486 * The validation includes:
8587 * <ul>
....@@ -96,7 +98,8 @@
9698 public LicenseBean validateLicense(File licFile, boolean excludeDateValidation) throws SeCurisException {
9799 LicenseBean licBean = load(licFile);
98100 SignatureHelper.getInstance().validateSignature(licBean);
99
- LicenseValidator.getInstance().validateHW(licBean, Params.get(Params.KEYS.APPLICATION_CODE), Params.get(Params.KEYS.CUSTOMER_CODE));
101
+ LicenseValidator.getInstance().validateHW(licBean, Params.get(Params.KEYS.APPLICATION_CODE), Params.get(Params.KEYS.CUSTOMER_CODE),
102
+ Params.get(Params.KEYS.PACK_CODE));
100103 LicenseValidator.getInstance().validateLogo(licBean);
101104
102105 if (!excludeDateValidation) {
....@@ -108,18 +111,19 @@
108111 return licBean;
109112 }
110113
111
- /**
112
- * Request to server for a valid license
113
- *
114
- * @return The license bean returned by the server
115
- * @throws SeCurisException
116
- */
117
- public SignedLicenseBean requestLicense() throws SeCurisException {
118
- RequestBean req = ReqGenerator.getInstance().createRequest(Params.get(Params.KEYS.APPLICATION_CODE), Params.get(Params.KEYS.CUSTOMER_CODE));
114
+ /**
115
+ * Request to server for a valid license
116
+ *
117
+ * @return The license bean returned by the server
118
+ * @throws SeCurisException
119
+ */
120
+ public SignedLicenseBean requestLicense() throws SeCurisException {
121
+ RequestBean req = ReqGenerator.getInstance().createRequest(Params.get(Params.KEYS.APPLICATION_CODE), Params.get(Params.KEYS.CUSTOMER_CODE),
122
+ Params.get(Params.KEYS.PACK_CODE));
119123
120
- SignedLicenseBean lic = requestLicenseToServer(req);
121
- return lic;
122
- }
124
+ SignedLicenseBean lic = requestLicenseToServer(req);
125
+ return lic;
126
+ }
123127
124128 /**
125129 * Generate a license file using a {@link LicenseBean}
....@@ -157,43 +161,47 @@
157161
158162 }
159163
160
- private SignedLicenseBean requestLicenseToServer(RequestBean req) throws SeCurisException {
161
- SignedLicenseBean lic = ConnectionManager.getInstance().executePost(Command.CREATE_LIC, SignedLicenseBean.class, req);
162
-
163
- return lic;
164
- }
164
+ private SignedLicenseBean requestLicenseToServer(RequestBean req) throws SeCurisException {
165
+ SignedLicenseBean lic = ConnectionManager.getInstance().executePost(Command.CREATE_LIC, SignedLicenseBean.class, req);
165166
166
- /**
167
- * Creates a new request file with current hardware in the File passed as parameter
168
- *
169
- * @param outputRequestFile
170
- * File where the request data will be saved
171
- * @return The generated request bean
172
- * @throws SeCurisException
173
- */
174
- public RequestBean createRequestFile(File outputRequestFile) throws SeCurisException {
175
- RequestBean req = ReqGenerator.getInstance().createRequest(Params.get(Params.KEYS.APPLICATION_CODE), Params.get(Params.KEYS.CUSTOMER_CODE));
167
+ return lic;
168
+ }
176169
177
- ReqGenerator.getInstance().save(req, outputRequestFile);
170
+ /**
171
+ * Creates a new request file with current hardware in the File passed as
172
+ * parameter
173
+ *
174
+ * @param outputRequestFile
175
+ * File where the request data will be saved
176
+ * @return The generated request bean
177
+ * @throws SeCurisException
178
+ */
179
+ public RequestBean createRequestFile(File outputRequestFile) throws SeCurisException {
180
+ RequestBean req = ReqGenerator.getInstance().createRequest(Params.get(Params.KEYS.APPLICATION_CODE), Params.get(Params.KEYS.CUSTOMER_CODE),
181
+ Params.get(Params.KEYS.PACK_CODE));
178182
179
- return req;
180
- }
183
+ ReqGenerator.getInstance().save(req, outputRequestFile);
181184
182
- /**
183
- * Send the current license file to server, which is previously validated, to get a renewed one if it is prepared in server side.
184
- *
185
- * @param licenseFile
186
- * Current and valid License file
187
- * @return New license bean if server creates a new one, otherwise the same current License bean will be returned
188
- * @throws SeCurisException
189
- */
190
- public SignedLicenseBean renew(File licenseFile) throws SeCurisException {
191
- LicenseBean lic = validateLicense(licenseFile);
185
+ return req;
186
+ }
187
+
188
+ /**
189
+ * Send the current license file to server, which is previously validated,
190
+ * to get a renewed one if it is prepared in server side.
191
+ *
192
+ * @param licenseFile
193
+ * Current and valid License file
194
+ * @return New license bean if server creates a new one, otherwise the same
195
+ * current License bean will be returned
196
+ * @throws SeCurisException
197
+ */
198
+ public SignedLicenseBean renew(File licenseFile) throws SeCurisException {
199
+ LicenseBean lic = validateLicense(licenseFile);
192200
193201 SignedLicenseBean newLic = ConnectionManager.getInstance().executePost(Command.RENEW_LIC, SignedLicenseBean.class, lic);
194202
195
- return newLic;
196
- }
203
+ return newLic;
204
+ }
197205
198206 public void testServer() throws SeCurisException {
199207 StatusBean status = ConnectionManager.getInstance().executeGet(Command.TEST, StatusBean.class);
src/main/java/net/curisit/securis/LicenseValidator.java
....@@ -14,55 +14,56 @@
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
19
- private static LicenseValidator singleton = new LicenseValidator();
20
- protected static byte[] LOGO_SECRET;
19
+ private static LicenseValidator singleton = new LicenseValidator();
20
+ protected static byte[] LOGO_SECRET;
2121
22
- static {
23
- try {
24
- LOGO_SECRET = "Logo ipsum s3cr3t test áíóú".getBytes("utf-8");
25
- } catch (UnsupportedEncodingException e) {
26
- LOG.error("Unexpected error getting LOGO secret", e);
27
- }
28
- }
22
+ static {
23
+ try {
24
+ LOGO_SECRET = "Logo ipsum s3cr3t test áíóú".getBytes("utf-8");
25
+ } catch (UnsupportedEncodingException e) {
26
+ LOG.error("Unexpected error getting LOGO secret", e);
27
+ }
28
+ }
2929
30
- private LicenseValidator() {
31
- }
30
+ private LicenseValidator() {
31
+ }
3232
33
- public static LicenseValidator getInstance() {
34
- return singleton;
35
- }
33
+ public static LicenseValidator getInstance() {
34
+ return singleton;
35
+ }
3636
37
- /**
38
- * @return CRC string for customer logo
39
- */
40
- public String getCrcLogo() {
41
- InputStream is = getClass().getClassLoader().getResourceAsStream("images/logo_customer.png");
42
- try {
43
- String shaLogo = LicUtils.sha256(IOUtils.toByteArray(is), LOGO_SECRET);
44
- return shaLogo;
45
- } catch (IOException e) {
46
- LOG.warn("Customer logo was not found in images/logo_customer.png");
47
- return null;
48
- }
49
- }
37
+ /**
38
+ * @return CRC string for customer logo
39
+ */
40
+ public String getCrcLogo() {
41
+ InputStream is = getClass().getClassLoader().getResourceAsStream("images/logo_customer.png");
42
+ try {
43
+ String shaLogo = LicUtils.sha256(IOUtils.toByteArray(is), LOGO_SECRET);
44
+ return shaLogo;
45
+ } catch (IOException e) {
46
+ LOG.warn("Customer logo was not found in images/logo_customer.png");
47
+ return null;
48
+ }
49
+ }
5050
51
- public void validateLogo(RequestBean reqBean) throws SeCurisException {
52
- if (reqBean.getCrcLogo() == null) {
53
- LOG.info("Customer logo is not included in license file and won't be validated");
54
- } else {
55
- String currentCRC = getCrcLogo();
56
- if (!currentCRC.equals(reqBean.getCrcLogo()))
57
- throw new SeCurisException("License logo validation failed for request data: " + JsonUtils.toJSON(reqBean));
58
- }
59
- }
51
+ public void validateLogo(RequestBean reqBean) throws SeCurisException {
52
+ if (reqBean.getCrcLogo() == null) {
53
+ LOG.info("Customer logo is not included in license file and won't be validated");
54
+ } else {
55
+ String currentCRC = getCrcLogo();
56
+ if (!currentCRC.equals(reqBean.getCrcLogo()))
57
+ throw new SeCurisException("License logo validation failed for request data: " + JsonUtils.toJSON(reqBean));
58
+ }
59
+ }
6060
61
- public void validateHW(RequestBean reqBean, String appCode, String customerCode) throws SeCurisException {
62
- RequestBean currentHW = ReqGenerator.getInstance().createRequest(appCode, customerCode);
63
- if (!currentHW.match(reqBean)) {
64
- throw new SeCurisException("Current System info mismatch the License System info:\n Licensed: " + JsonUtils.toJSON(reqBean, true) + "\n Expected: " + JsonUtils.toJSON(currentHW, true));
65
- }
66
- }
61
+ public void validateHW(RequestBean reqBean, String appCode, String customerCode, String packCode) throws SeCurisException {
62
+ RequestBean currentHW = ReqGenerator.getInstance().createRequest(appCode, customerCode, packCode);
63
+ if (!currentHW.match(reqBean)) {
64
+ throw new SeCurisException("Current System info mismatch the License System info:\n Licensed: " + JsonUtils.toJSON(reqBean, true)
65
+ + "\n Expected: " + JsonUtils.toJSON(currentHW, true));
66
+ }
67
+ }
6768
6869 }
src/main/java/net/curisit/securis/ReqGenerator.java
....@@ -19,76 +19,77 @@
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
24
- private static ReqGenerator singleton = new ReqGenerator();
24
+ private static ReqGenerator singleton = new ReqGenerator();
2525
26
- private ReqGenerator() {
27
- }
26
+ private ReqGenerator() {
27
+ }
2828
29
- public static ReqGenerator getInstance() {
30
- return singleton;
31
- }
29
+ public static ReqGenerator getInstance() {
30
+ return singleton;
31
+ }
3232
33
- public RequestBean createRequest(String appCode, String customerCode) throws SeCurisException {
34
- RequestBean req = new RequestBean();
33
+ public RequestBean createRequest(String licTypeCode, String customerCode, String packCode) throws SeCurisException {
34
+ RequestBean req = new RequestBean();
3535
36
- req.setAppCode(appCode);
37
- req.setCustomerCode(customerCode);
38
- req.setArch(HWInfo.getArch());
39
- req.setCrcLogo(getCrcLogo());
40
- req.setMacAddresses(HWInfo.getMACAddress());
41
- req.setOsName(HWInfo.getOsName());
36
+ req.setLicenseTypeCode(licTypeCode);
37
+ req.setCustomerCode(customerCode);
38
+ req.setPackCode(packCode);
39
+ req.setArch(HWInfo.getArch());
40
+ req.setCrcLogo(getCrcLogo());
41
+ req.setMacAddresses(HWInfo.getMACAddress());
42
+ req.setOsName(HWInfo.getOsName());
4243
43
- return req;
44
- }
44
+ return req;
45
+ }
4546
46
- public RequestBean loadRequest(File requestFile) throws SeCurisException {
47
- try {
48
- String json = new String(Files.readAllBytes(Paths.get(requestFile.toURI())), "utf-8");
49
- RequestBean req = JsonUtils.json2object(json, RequestBean.class);
50
- return req;
51
- } catch (IOException e) {
52
- LOG.error("Request file {} was not found or is not accesible");
53
- throw new SeCurisException("ERROR accesing request file: " + requestFile.getAbsolutePath(), e);
54
- }
55
- }
47
+ public RequestBean loadRequest(File requestFile) throws SeCurisException {
48
+ try {
49
+ String json = new String(Files.readAllBytes(Paths.get(requestFile.toURI())), "utf-8");
50
+ RequestBean req = JsonUtils.json2object(json, RequestBean.class);
51
+ return req;
52
+ } catch (IOException e) {
53
+ LOG.error("Request file {} was not found or is not accesible");
54
+ throw new SeCurisException("ERROR accesing request file: " + requestFile.getAbsolutePath(), e);
55
+ }
56
+ }
5657
57
- /**
58
- * Generate a request file using a {@link RequestBean}
59
- *
60
- * @param req
61
- * @param file
62
- * @throws SeCurisException
63
- */
64
- public void save(RequestBean req, File file) throws SeCurisException {
65
- byte[] json;
66
- try {
67
- json = JsonUtils.toJSON(req, true).getBytes("utf-8");
68
- Files.write(Paths.get(file.toURI()), json, StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING);
69
- } catch (UnsupportedEncodingException e) {
70
- LOG.error("Error creating json doc from request: " + req, e);
71
- throw new SeCurisException("Error creating json doc from request: " + req, e);
72
- } catch (IOException e) {
73
- LOG.error("Error creating request file: " + file, e);
74
- throw new SeCurisException("Error creating request file: " + file, e);
75
- }
58
+ /**
59
+ * Generate a request file using a {@link RequestBean}
60
+ *
61
+ * @param req
62
+ * @param file
63
+ * @throws SeCurisException
64
+ */
65
+ public void save(RequestBean req, File file) throws SeCurisException {
66
+ byte[] json;
67
+ try {
68
+ json = JsonUtils.toJSON(req, true).getBytes("utf-8");
69
+ Files.write(Paths.get(file.toURI()), json, StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING);
70
+ } catch (UnsupportedEncodingException e) {
71
+ LOG.error("Error creating json doc from request: " + req, e);
72
+ throw new SeCurisException("Error creating json doc from request: " + req, e);
73
+ } catch (IOException e) {
74
+ LOG.error("Error creating request file: " + file, e);
75
+ throw new SeCurisException("Error creating request file: " + file, e);
76
+ }
7677
77
- LOG.debug("License saved in {}", file);
78
+ LOG.debug("License saved in {}", file);
7879
79
- }
80
+ }
8081
81
- private String getCrcLogo() {
82
- String logResource = "images/logo_customer.png";
83
- InputStream is = getClass().getClassLoader().getResourceAsStream(logResource);
84
- if (is == null)
85
- return null;
86
- try {
87
- String shaLogo = LicUtils.sha256(IOUtils.toByteArray(is), LicenseValidator.LOGO_SECRET);
88
- return shaLogo;
89
- } catch (IOException e) {
90
- LOG.error("Customer logo was not found in classpath in " + logResource, e);
91
- return null;
92
- }
93
- }
82
+ private String getCrcLogo() {
83
+ String logResource = "images/logo_customer.png";
84
+ InputStream is = getClass().getClassLoader().getResourceAsStream(logResource);
85
+ if (is == null)
86
+ return null;
87
+ try {
88
+ String shaLogo = LicUtils.sha256(IOUtils.toByteArray(is), LicenseValidator.LOGO_SECRET);
89
+ return shaLogo;
90
+ } catch (IOException e) {
91
+ LOG.error("Customer logo was not found in classpath in " + logResource, e);
92
+ return null;
93
+ }
94
+ }
9495 }
src/main/java/net/curisit/securis/beans/LicenseBean.java
....@@ -10,94 +10,97 @@
1010 import org.codehaus.jackson.annotate.JsonPropertyOrder;
1111
1212 @JsonAutoDetect
13
-@JsonPropertyOrder(
14
- { "licenseCode", "licenseType", "expirationDate", "appCode", "arch", "osName", "customerCode", "macAddresses", "crcLogo", "metadata" })
13
+@JsonPropertyOrder({
14
+ "appName", "licenseCode", "licenseTypeCode", "expirationDate", "arch", "osName", "customerCode", "macAddresses", "crcLogo", "metadata"
15
+})
1516 public class LicenseBean extends RequestBean {
16
- private Date expirationDate;
17
- /**
18
- * Signature is stored in Base64 code
19
- */
20
- private String signature;
21
- private String licenseType;
22
- private String licenseCode;
17
+ private Date expirationDate;
18
+ /**
19
+ * Signature is stored in Base64 code
20
+ */
21
+ private String signature;
22
+ private String licenseCode;
23
+ private String appName;
2324
24
- private Map<String, Object> metadata;
25
+ private Map<String, Object> metadata;
2526
26
- public LicenseBean() {
27
- }
27
+ public LicenseBean() {
28
+ }
2829
29
- public LicenseBean(RequestBean req) {
30
- super.setAppCode(req.getAppCode());
31
- super.setArch(req.getArch());
32
- super.setCrcLogo(req.getCrcLogo());
33
- super.setCustomerCode(req.getCustomerCode());
34
- super.setMacAddresses(req.getMacAddresses());
35
- super.setOsName(req.getOsName());
36
- }
30
+ public LicenseBean(RequestBean req) {
31
+ super.setPackCode(req.getPackCode());
32
+ super.setLicenseTypeCode(req.getLicenseTypeCode());
33
+ super.setCustomerCode(req.getCustomerCode());
34
+ super.setArch(req.getArch());
35
+ super.setCrcLogo(req.getCrcLogo());
36
+ super.setMacAddresses(req.getMacAddresses());
37
+ super.setOsName(req.getOsName());
38
+ }
3739
38
- public Map<String, Object> getMetadata() {
39
- return metadata;
40
- }
40
+ public Map<String, Object> getMetadata() {
41
+ return metadata;
42
+ }
4143
42
- public void setMetadata(Map<String, Object> metadata) {
43
- this.metadata = new TreeMap<>(metadata);
44
- }
44
+ public void setMetadata(Map<String, Object> metadata) {
45
+ this.metadata = new TreeMap<>(metadata);
46
+ }
4547
46
- @JsonIgnore
47
- public String getSignature() {
48
- return signature;
49
- }
48
+ @JsonIgnore
49
+ public String getSignature() {
50
+ return signature;
51
+ }
5052
51
- @JsonProperty("signature")
52
- public void setSignature(String signature) {
53
- this.signature = signature;
54
- }
53
+ @JsonProperty("signature")
54
+ public void setSignature(String signature) {
55
+ this.signature = signature;
56
+ }
5557
56
- public Date getExpirationDate() {
57
- return expirationDate;
58
- }
58
+ public Date getExpirationDate() {
59
+ return expirationDate;
60
+ }
5961
60
- public void setExpirationDate(Date expirationDate) {
61
- this.expirationDate = expirationDate;
62
- }
62
+ public void setExpirationDate(Date expirationDate) {
63
+ this.expirationDate = expirationDate;
64
+ }
6365
64
- @Override
65
- public int hashCode() {
66
- int code = 0;
67
- code += expirationDate != null ? expirationDate.hashCode() : 0;
68
- code += signature != null ? signature.hashCode() : 0;
69
- code += metadata != null ? metadata.hashCode() : 0;
70
-
71
- return code;
72
- };
73
-
74
- @Override
75
- public boolean equals(Object obj) {
76
- if (!(obj instanceof LicenseBean))
77
- return false;
78
- LicenseBean rb = (LicenseBean) obj;
79
- boolean result = true;
80
- result = result && ((expirationDate == null && rb.expirationDate == null) || (expirationDate != null && expirationDate.equals(rb.expirationDate)));
81
- result = result && ((signature == null && rb.signature == null) || (signature != null && signature.equals(rb.signature)));
82
- result = result && ((metadata == null && rb.metadata == null) || (metadata != null && metadata.equals(rb.metadata)));
66
+ @Override
67
+ public int hashCode() {
68
+ int code = 0;
69
+ code += expirationDate != null ? expirationDate.hashCode() : 0;
70
+ code += signature != null ? signature.hashCode() : 0;
71
+ code += metadata != null ? metadata.hashCode() : 0;
8372
84
- return result && super.equals(obj);
85
- }
73
+ return code;
74
+ };
8675
87
- public String getLicenseCode() {
88
- return licenseCode;
89
- }
76
+ @Override
77
+ public boolean equals(Object obj) {
78
+ if (!(obj instanceof LicenseBean))
79
+ return false;
80
+ LicenseBean rb = (LicenseBean) obj;
81
+ boolean result = true;
82
+ result = result
83
+ && ((expirationDate == null && rb.expirationDate == null) || (expirationDate != null && expirationDate.equals(rb.expirationDate)));
84
+ result = result && ((signature == null && rb.signature == null) || (signature != null && signature.equals(rb.signature)));
85
+ result = result && ((metadata == null && rb.metadata == null) || (metadata != null && metadata.equals(rb.metadata)));
9086
91
- public void setLicenseCode(String licenseCode) {
92
- this.licenseCode = licenseCode;
93
- }
87
+ return result && super.equals(obj);
88
+ }
9489
95
- public String getLicenseType() {
96
- return licenseType;
97
- }
90
+ public String getLicenseCode() {
91
+ return licenseCode;
92
+ }
9893
99
- public void setLicenseType(String licenseType) {
100
- this.licenseType = licenseType;
101
- }
94
+ public void setLicenseCode(String licenseCode) {
95
+ this.licenseCode = licenseCode;
96
+ }
97
+
98
+ public String getAppName() {
99
+ return appName;
100
+ }
101
+
102
+ public void setAppName(String appName) {
103
+ this.appName = appName;
104
+ }
102105
103106 }
src/main/java/net/curisit/securis/beans/RequestBean.java
....@@ -8,107 +8,119 @@
88 @JsonAutoDetect
99 @JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL)
1010 public class RequestBean {
11
- private String customerCode;
12
- private String crcLogo;
13
- private String appCode;
14
- private List<String> macAddresses;
15
- private String osName;
16
- private String arch;
11
+ private String customerCode;
12
+ private String crcLogo;
13
+ private String licenseTypeCode;
14
+ private String packCode;
15
+ private List<String> macAddresses;
16
+ private String osName;
17
+ private String arch;
1718
18
- public String getCustomerCode() {
19
- return customerCode;
20
- }
19
+ public String getCustomerCode() {
20
+ return customerCode;
21
+ }
2122
22
- public void setCustomerCode(String customerCode) {
23
- this.customerCode = customerCode;
24
- }
23
+ public void setCustomerCode(String customerCode) {
24
+ this.customerCode = customerCode;
25
+ }
2526
26
- public String getCrcLogo() {
27
- return crcLogo;
28
- }
27
+ public String getCrcLogo() {
28
+ return crcLogo;
29
+ }
2930
30
- public void setCrcLogo(String crcLogo) {
31
- this.crcLogo = crcLogo;
32
- }
31
+ public void setCrcLogo(String crcLogo) {
32
+ this.crcLogo = crcLogo;
33
+ }
3334
34
- public String getAppCode() {
35
- return appCode;
36
- }
35
+ public List<String> getMacAddresses() {
36
+ return macAddresses;
37
+ }
3738
38
- public void setAppCode(String appCode) {
39
- this.appCode = appCode;
40
- }
39
+ public void setMacAddresses(List<String> macAddresses) {
40
+ this.macAddresses = macAddresses;
41
+ }
4142
42
- public List<String> getMacAddresses() {
43
- return macAddresses;
44
- }
43
+ public String getOsName() {
44
+ return osName;
45
+ }
4546
46
- public void setMacAddresses(List<String> macAddresses) {
47
- this.macAddresses = macAddresses;
48
- }
47
+ public void setOsName(String osName) {
48
+ this.osName = osName;
49
+ }
4950
50
- public String getOsName() {
51
- return osName;
52
- }
51
+ public String getArch() {
52
+ return arch;
53
+ }
5354
54
- public void setOsName(String osName) {
55
- this.osName = osName;
56
- }
55
+ public void setArch(String arch) {
56
+ this.arch = arch;
57
+ }
5758
58
- public String getArch() {
59
- return arch;
60
- }
59
+ public boolean match(RequestBean rb) {
6160
62
- public void setArch(String arch) {
63
- this.arch = arch;
64
- }
61
+ boolean result = licenseTypeCode != null && licenseTypeCode.equals(rb.licenseTypeCode);
62
+ result = result && (packCode != null && packCode.equals(rb.packCode));
63
+ result = result && (arch != null && arch.equals(rb.arch));
64
+ // CRC Logo validation is optional, only if request file contains it
65
+ result = result && (crcLogo == null || crcLogo.equals(rb.crcLogo));
66
+ result = result && (customerCode != null && customerCode.equals(rb.customerCode));
67
+ result = result && (osName != null && osName.equals(rb.osName));
68
+ result = result && (macAddresses != null && rb.macAddresses != null) && anyMacIsIncluded(rb.getMacAddresses());
6569
66
- public boolean match(RequestBean rb) {
70
+ return result;
71
+ }
6772
68
- boolean result = appCode != null && appCode.equals(rb.appCode);
69
- result = result && (arch != null && arch.equals(rb.arch));
70
- // CRC Logo validation is optional, only if request file contains it
71
- result = result && (crcLogo == null || crcLogo.equals(rb.crcLogo));
72
- result = result && (customerCode != null && customerCode.equals(rb.customerCode));
73
- result = result && (osName != null && osName.equals(rb.osName));
74
- result = result && (macAddresses != null && rb.macAddresses != null) && anyMacIsIncluded(rb.getMacAddresses());
73
+ private boolean anyMacIsIncluded(List<String> macList) {
74
+ for (String mac : macList) {
75
+ if (macAddresses.contains(mac))
76
+ return true;
77
+ }
78
+ return false;
79
+ }
7580
76
- return result;
77
- }
81
+ @Override
82
+ public int hashCode() {
83
+ int code = 0;
84
+ code += licenseTypeCode != null ? licenseTypeCode.hashCode() : 0;
85
+ code += arch != null ? arch.hashCode() : 0;
86
+ code += crcLogo != null ? crcLogo.hashCode() : 0;
87
+ code += packCode != null ? packCode.hashCode() : 0;
88
+ code += customerCode != null ? customerCode.hashCode() : 0;
89
+ code += osName != null ? osName.hashCode() : 0;
90
+ code += macAddresses != null ? macAddresses.hashCode() : 0;
7891
79
- private boolean anyMacIsIncluded(List<String> macList) {
80
- for (String mac : macList) {
81
- if (macAddresses.contains(mac))
82
- return true;
83
- }
84
- return false;
85
- }
92
+ return code;
93
+ };
8694
95
+ @Override
96
+ public boolean equals(Object obj) {
97
+ if (!(obj instanceof RequestBean))
98
+ return false;
99
+ RequestBean rb = (RequestBean) obj;
100
+ boolean result = (rb.licenseTypeCode == null && licenseTypeCode == null)
101
+ || (licenseTypeCode != null && licenseTypeCode.equals(rb.licenseTypeCode));
102
+ result = result && ((rb.packCode == null && packCode == null) || (packCode != null && packCode.equals(rb.arch)));
103
+ result = result && ((rb.arch == null && arch == null) || (arch != null && arch.equals(rb.arch)));
104
+ result = result && ((rb.crcLogo == null && crcLogo == null) || (crcLogo != null && crcLogo.equals(rb.crcLogo)));
105
+ result = result && ((rb.customerCode == null && customerCode == null) || (customerCode != null && customerCode.equals(rb.customerCode)));
106
+ result = result && ((rb.osName == null && osName == null) || (osName != null && osName.equals(rb.osName)));
107
+ result = result && ((rb.macAddresses == null && macAddresses == null) || (macAddresses != null && macAddresses.equals(rb.macAddresses)));
108
+ return result;
109
+ }
87110
88
- @Override
89
- public int hashCode() {
90
- int code = 0;
91
- code += appCode != null ? appCode.hashCode() : 0;
92
- code += arch != null ? arch.hashCode() : 0;
93
- code += crcLogo != null ? crcLogo.hashCode() : 0;
94
- code += customerCode != null ? customerCode.hashCode() : 0;
95
- code += osName != null ? osName.hashCode() : 0;
96
- code += macAddresses != null ? macAddresses.hashCode() : 0;
97
-
98
- return code;
99
- };
100
-
101
- @Override
102
- public boolean equals(Object obj) {
103
- if (!(obj instanceof RequestBean))
104
- return false;
105
- RequestBean rb = (RequestBean) obj;
106
- boolean result = (rb.appCode == null && appCode == null) || (appCode != null && appCode.equals(rb.appCode));
107
- result = result && ((rb.arch == null && arch == null) || (arch != null && arch.equals(rb.arch)));
108
- result = result && ((rb.crcLogo == null && crcLogo == null) || (crcLogo != null && crcLogo.equals(rb.crcLogo)));
109
- result = result && ((rb.customerCode == null && customerCode == null) || (customerCode != null && customerCode.equals(rb.customerCode)));
110
- result = result && ((rb.osName == null && osName == null) || (osName != null && osName.equals(rb.osName)));
111
- result = result && ((rb.macAddresses == null && macAddresses == null) || (macAddresses != null && macAddresses.equals(rb.macAddresses)));
112
- return result;
113
- }
111
+ public String getPackCode() {
112
+ return packCode;
113
+ }
114
+
115
+ public void setPackCode(String packCode) {
116
+ this.packCode = packCode;
117
+ }
118
+
119
+ public String getLicenseTypeCode() {
120
+ return licenseTypeCode;
121
+ }
122
+
123
+ public void setLicenseTypeCode(String licenseTypeCode) {
124
+ this.licenseTypeCode = licenseTypeCode;
125
+ }
114126 }
src/main/java/net/curisit/securis/beans/SignedLicenseBean.java
....@@ -6,21 +6,22 @@
66 @JsonAutoDetect
77 public class SignedLicenseBean extends LicenseBean {
88
9
- @JsonProperty("signature")
10
- public String getCurrentSignature() {
11
- return super.getSignature();
12
- }
13
-
14
- public SignedLicenseBean() {
15
- }
9
+ @JsonProperty("signature")
10
+ public String getCurrentSignature() {
11
+ return super.getSignature();
12
+ }
1613
17
- public SignedLicenseBean(LicenseBean lb) {
18
- super(lb);
19
- setSignature(lb.getSignature());
20
- setExpirationDate(lb.getExpirationDate());
21
- setLicenseCode(lb.getLicenseCode());
22
- setLicenseType(lb.getLicenseType());
23
- setMetadata(lb.getMetadata());
24
- }
14
+ public SignedLicenseBean() {
15
+ }
16
+
17
+ public SignedLicenseBean(LicenseBean lb) {
18
+ super(lb);
19
+ setSignature(lb.getSignature());
20
+ setExpirationDate(lb.getExpirationDate());
21
+ setPackCode(lb.getPackCode());
22
+ setLicenseCode(lb.getLicenseCode());
23
+ setAppName(lb.getAppName());
24
+ setMetadata(lb.getMetadata());
25
+ }
2526
2627 }
src/main/java/net/curisit/securis/utils/Params.java
....@@ -17,182 +17,197 @@
1717 */
1818 public class Params {
1919
20
- private static final Logger LOG = LogManager.getLogger(Params.class);
20
+ private static final Logger LOG = LogManager.getLogger(Params.class);
2121
22
- /**
23
- * Key used to store config file resource location. In a web application, can be set as initial parameter in a servlet loaded on startup
24
- */
22
+ /**
23
+ * Key used to store config file resource location. In a web application,
24
+ * can be set as initial parameter in a servlet loaded on startup
25
+ */
2526 public static final String DEFAUT_SERVER_URL = "https://securis.curistec.com/api";
26
- public static final String KEY_CONFIG_FILE = "/securis-client.properties";
27
+ public static final String KEY_CONFIG_FILE = "/securis-server.properties";
2728
28
- private static Properties params = null;
29
+ private static Properties params = null;
2930
30
- static {
31
- try {
32
- loadParameters(KEY_CONFIG_FILE);
33
- } catch (IOException e) {
34
- LOG.error("Config file {} was not found in classpath", KEY_CONFIG_FILE);
35
- System.exit(-2);
36
- }
37
- }
31
+ static {
32
+ try {
33
+ loadParameters(KEY_CONFIG_FILE);
34
+ } catch (IOException e) {
35
+ LOG.error("Config file {} was not found in classpath", KEY_CONFIG_FILE);
36
+ System.exit(-2);
37
+ }
38
+ }
3839
39
- /**
40
- * Loads application global parameters from a classpath resource
41
- *
42
- * @param resource
43
- * : Resource location in classpath, i.e: "/resource/cp-securis.conf"
44
- * @throws IOException
45
- */
46
- public static void loadParameters(String resource) throws IOException {
40
+ /**
41
+ * Loads application global parameters from a classpath resource
42
+ *
43
+ * @param resource
44
+ * : Resource location in classpath, i.e:
45
+ * "/resource/cp-securis.conf"
46
+ * @throws IOException
47
+ */
48
+ public static void loadParameters(String resource) throws IOException {
4749
48
- LOG.debug("Loading params from " + resource);
49
- InputStream fileis = Params.class.getResourceAsStream(resource);
50
+ LOG.debug("Loading params from " + resource);
51
+ InputStream fileis = Params.class.getResourceAsStream(resource);
5052
51
- params = new Properties();
52
- try {
53
+ params = new Properties();
54
+ try {
5355
54
- params.load(fileis);
55
- LOG.debug("Params loaded OK from {}", resource);
56
- } catch (IOException e) {
57
- LOG.error("Error loading config file: " + e);
58
- params = null;
59
- throw e;
60
- }
56
+ params.load(fileis);
57
+ LOG.debug("Params loaded OK from {}", resource);
58
+ } catch (IOException e) {
59
+ LOG.error("Error loading config file: " + e);
60
+ params = null;
61
+ throw e;
62
+ }
6163
62
- }
64
+ }
6365
64
- public static String getByDomain(String domain, String paramname) {
65
- return getByDomain(domain, paramname, null);
66
- }
66
+ public static String getByDomain(String domain, String paramname) {
67
+ return getByDomain(domain, paramname, null);
68
+ }
6769
68
- public static String getByPrefix(String prefix, String paramname) {
69
- return get(prefix + "." + paramname, get(paramname));
70
- }
70
+ public static String getByPrefix(String prefix, String paramname) {
71
+ return get(prefix + "." + paramname, get(paramname));
72
+ }
7173
72
- public static String getByPrefix(String prefix, String paramname, String defaultVal) {
73
- return get(prefix + "." + paramname, get(paramname, defaultVal));
74
- }
74
+ public static String getByPrefix(String prefix, String paramname, String defaultVal) {
75
+ return get(prefix + "." + paramname, get(paramname, defaultVal));
76
+ }
7577
76
- public static String getByDomain(String domain, String paramname, String defaultval) {
77
- return get(paramname + "." + domain, defaultval);
78
- }
78
+ public static String getByDomain(String domain, String paramname, String defaultval) {
79
+ return get(paramname + "." + domain, defaultval);
80
+ }
7981
80
- public static int getIntByDomain(String domain, String paramname) {
81
- return getInt(paramname + "." + domain, getInt(paramname));
82
- }
82
+ public static int getIntByDomain(String domain, String paramname) {
83
+ return getInt(paramname + "." + domain, getInt(paramname));
84
+ }
8385
84
- public static int getIntByDomain(String domain, String paramname, int defaultval) {
85
- return getInt(paramname + "." + domain, defaultval);
86
- }
86
+ public static int getIntByDomain(String domain, String paramname, int defaultval) {
87
+ return getInt(paramname + "." + domain, defaultval);
88
+ }
8789
88
- /**
89
- * Gets a List with all values of properties that begins with <code>prefix</code> It reads sequentially. For example:
90
- *
91
- * <pre>
92
- * securis.sort.comparator.0: net.cp.securis.comparators.ComparePttidVsPtn
93
- * securis.sort.comparator.1: net.cp.securis.comparators.CompareFrequency
94
- * securis.sort.comparator.2: net.cp.securis.comparators.CompareOutgoingVsIncomming
95
- * securis.sort.comparator.3: net.cp.securis.comparators.CompareDuration
96
- * securis.sort.comparator.4: net.cp.securis.comparators.CompareCallVsSms
97
- * </pre>
98
- *
99
- * That config (for prefix: "securis.sort.comparator" ) will return a List<String> with values:
100
- *
101
- * <pre>
102
- * "net.cp.securis.comparators.ComparePttidVsPtn",
103
- * "net.cp.securis.comparators.CompareFrequency",
104
- * "net.cp.securis.comparators.CompareOutgoingVsIncomming",
105
- * "net.cp.securis.comparators.CompareDuration",
106
- * "net.cp.securis.comparators.CompareCallVsSms"
107
- * </pre>
108
- *
109
- * Note: If there is a gap between suffixes process will stop, that is, only will be returned properties found before gap.
110
- *
111
- * @param prefix
112
- * @return
113
- */
114
- public static List<String> getListByPrefix(String prefix) {
115
- List<String> list = new ArrayList<String>();
90
+ /**
91
+ * Gets a List with all values of properties that begins with
92
+ * <code>prefix</code> It reads sequentially. For example:
93
+ *
94
+ * <pre>
95
+ * securis.sort.comparator.0: net.cp.securis.comparators.ComparePttidVsPtn
96
+ * securis.sort.comparator.1: net.cp.securis.comparators.CompareFrequency
97
+ * securis.sort.comparator.2: net.cp.securis.comparators.CompareOutgoingVsIncomming
98
+ * securis.sort.comparator.3: net.cp.securis.comparators.CompareDuration
99
+ * securis.sort.comparator.4: net.cp.securis.comparators.CompareCallVsSms
100
+ * </pre>
101
+ *
102
+ * That config (for prefix: "securis.sort.comparator" ) will return a
103
+ * List<String> with values:
104
+ *
105
+ * <pre>
106
+ * "net.cp.securis.comparators.ComparePttidVsPtn",
107
+ * "net.cp.securis.comparators.CompareFrequency",
108
+ * "net.cp.securis.comparators.CompareOutgoingVsIncomming",
109
+ * "net.cp.securis.comparators.CompareDuration",
110
+ * "net.cp.securis.comparators.CompareCallVsSms"
111
+ * </pre>
112
+ *
113
+ * Note: If there is a gap between suffixes process will stop, that is, only
114
+ * will be returned properties found before gap.
115
+ *
116
+ * @param prefix
117
+ * @return
118
+ */
119
+ public static List<String> getListByPrefix(String prefix) {
120
+ List<String> list = new ArrayList<String>();
116121
117
- String tpl = prefix + ".{0}";
122
+ String tpl = prefix + ".{0}";
118123
119
- int i = 0;
120
- String value = get(MessageFormat.format(tpl, i++));
121
- while (value != null) {
122
- list.add(value);
123
- value = get(MessageFormat.format(tpl, i++));
124
- }
124
+ int i = 0;
125
+ String value = get(MessageFormat.format(tpl, i++));
126
+ while (value != null) {
127
+ list.add(value);
128
+ value = get(MessageFormat.format(tpl, i++));
129
+ }
125130
126
- return list;
127
- }
131
+ return list;
132
+ }
128133
129
- /**
130
- * Gets param value in config file or environment variables
131
- *
132
- * @param paramname
133
- * Global parameter's name
134
- * @return Value of paramname or null if paramname is not found neither in config file nor in environment variables
135
- */
136
- public static String get(String paramname) {
134
+ /**
135
+ * Gets param value in config file or environment variables
136
+ *
137
+ * @param paramname
138
+ * Global parameter's name
139
+ * @return Value of paramname or null if paramname is not found neither in
140
+ * config file nor in environment variables
141
+ */
142
+ public static String get(String paramname) {
137143
138
- assert (params != null) : "Parameters have not been loaded. Call method loadParameters(resource) before use Params.";
144
+ assert (params != null) : "Parameters have not been loaded. Call method loadParameters(resource) before use Params.";
139145
140
- String value = params.getProperty(paramname);
141
- if (value == null)
142
- value = System.getenv(paramname);
143
- return value;
144
- }
146
+ String value = params.getProperty(paramname);
147
+ if (value == null)
148
+ value = System.getenv(paramname);
149
+ return value;
150
+ }
145151
146
- /**
147
- * Gets param value from config file or environment variables
148
- *
149
- * @param paramname
150
- * Global parameter's name
151
- * @param defaultval
152
- * @return Value of paramname or defaultval if paramname is not found
153
- */
154
- public static String get(String paramname, String defaultval) {
155
- String value = get(paramname);
156
- return (value == null ? defaultval : value);
157
- }
152
+ /**
153
+ * Gets param value from config file or environment variables
154
+ *
155
+ * @param paramname
156
+ * Global parameter's name
157
+ * @param defaultval
158
+ * @return Value of paramname or defaultval if paramname is not found
159
+ */
160
+ public static String get(String paramname, String defaultval) {
161
+ String value = get(paramname);
162
+ return (value == null ? defaultval : value);
163
+ }
158164
159
- /**
160
- * Gets param value in config file or environment variables
161
- *
162
- * @param paramname
163
- * Global parameter's name
164
- * @return Integer value of paramname or -1 if paramname is not found neither in config file nor in environment variables
165
- */
166
- public static int getInt(String paramname) {
167
- String value = get(paramname);
168
- return (value == null ? -1 : Integer.parseInt(value));
169
- }
165
+ /**
166
+ * Gets param value in config file or environment variables
167
+ *
168
+ * @param paramname
169
+ * Global parameter's name
170
+ * @return Integer value of paramname or -1 if paramname is not found
171
+ * neither in config file nor in environment variables
172
+ */
173
+ public static int getInt(String paramname) {
174
+ String value = get(paramname);
175
+ return (value == null ? -1 : Integer.parseInt(value));
176
+ }
170177
171
- /**
172
- * Gets param value from config file or environment variables
173
- *
174
- * @param paramname
175
- * Global parameter's name
176
- * @param defaultval
177
- * @return Integer value of paramname or defaultval if paramname is not found
178
- */
179
- public static int getInt(String paramname, int defaultval) {
180
- String value = get(paramname);
181
- return (value == null ? defaultval : Integer.parseInt(value));
182
- }
178
+ /**
179
+ * Gets param value from config file or environment variables
180
+ *
181
+ * @param paramname
182
+ * Global parameter's name
183
+ * @param defaultval
184
+ * @return Integer value of paramname or defaultval if paramname is not
185
+ * found
186
+ */
187
+ public static int getInt(String paramname, int defaultval) {
188
+ String value = get(paramname);
189
+ return (value == null ? defaultval : Integer.parseInt(value));
190
+ }
183191
184
- public static class KEYS {
192
+ public static class KEYS {
185193
186
- /**
187
- * Public key file, Usually in "PEM" format
188
- */
189
- public static final String PUBLIC_KEY_FILE = "public.key.file";
194
+ /**
195
+ * Public key file, Usually in "PEM" format
196
+ */
197
+ public static final String PUBLIC_KEY_FILE = "public.key.file";
190198
191
- public static final String APPLICATION_CODE = "app.code";
199
+ public static final String APPLICATION_CODE = "app.code";
192200
193
- public static final String CUSTOMER_CODE = "customer.code";
201
+ public static final String CUSTOMER_CODE = "customer.code";
194202
195
- public static final String LICENSE_SERVER_URL = "license.server.url";
196
- }
203
+ public static final String PACK_CODE = "pack.code";
204
+
205
+ public static final String LICENSE_SERVER_URL = "license.server.url";
206
+
207
+ public static final String MAILGUN_DOMAIN = "mailgun.domain";
208
+ public static final String MAILGUN_API_KEY = "mailgun.api.key";
209
+ public static final String EMAIL_FROM_ADDRESS = "email.from.address";
210
+ public static final String EMAIL_LIC_DEFAULT_SUBJECT = "email.lic.default.subject";
211
+ }
197212
198213 }