pom.xml
.. .. @@ -3,7 +3,7 @@ 3 3 <modelVersion>4.0.0</modelVersion> 4 4 <groupId>net.curisit</groupId> 5 5 <artifactId>securis-client</artifactId> 6 - <version>1.0.0-SNAPSHOT</version>6 + <version>1.0.1-SNAPSHOT</version>7 7 <build> 8 8 <plugins> 9 9 <plugin> src/main/java/net/curisit/securis/License.java
.. .. @@ -15,7 +15,6 @@ 15 15 import org.apache.commons.cli.PosixParser; 16 16 import org.apache.logging.log4j.LogManager; 17 17 import org.apache.logging.log4j.Logger; 18 -import org.codehaus.jackson.map.DeserializerFactory.Config;19 18 20 19 /** 21 20 * Main class when SeCuris client is used from command line. .. .. @@ -44,70 +43,70 @@ 44 43 45 44 private static final Logger LOG = LogManager.getLogger(License.class); 46 45 47 - /**48 - * Aplication entry point when it used as CLI49 - *50 - * @param args51 - * @throws URISyntaxException52 - */53 - public static void main(String[] args) throws URISyntaxException {46 + /**47 + * Aplication entry point when it used as CLI48 + *49 + * @param args50 + * @throws URISyntaxException51 + */52 + public static void main(String[] args) throws URISyntaxException {54 53 55 - LOG.debug("SeCuris client tool init ");54 + LOG.debug("SeCuris client tool init ");56 55 57 - checkConfigFile();58 - CommandLine cmd = getCommandLine(args);56 + checkConfigFile();57 + CommandLine cmd = getCommandLine(args);59 58 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 + }70 69 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 + }86 85 87 - System.exit(0);88 - }86 + System.exit(0);87 + }89 88 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");93 92 if (filename == null) 94 93 filename = "./license.lic"; 95 94 File file = new File(filename); 96 95 LicenseManager.getInstance().save(lic, file); 97 96 LOG.info("License file sucessfully saved in file: {}", file.getAbsolutePath()); 98 97 System.exit(0); 99 - }98 + }100 99 101 - if (cmd.hasOption('t')) {100 + if (cmd.hasOption('t')) {102 101 LicenseManager.getInstance().testServer(); 103 102 LOG.info("Server is OK, url: {}", Params.get(Params.KEYS.LICENSE_SERVER_URL, Params.DEFAUT_SERVER_URL)); 104 103 105 104 System.exit(0); 106 - }105 + }107 106 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");111 110 File file = new File(licFilename); 112 111 if (!file.exists()) { 113 112 throw new SeCurisException("The license file doesn't exist: " + file.getAbsolutePath()); .. .. @@ -118,77 +117,84 @@ 118 117 LOG.info("Old license file has been renamed to: {}", oldLicFile.getAbsolutePath()); 119 118 LicenseManager.getInstance().save(newLic, file); 120 119 LOG.info("New license file saved as: {}", file.getAbsolutePath()); 121 - System.exit(0);122 - }120 + System.exit(0);121 + }123 122 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 + }128 127 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 + }135 134 136 - /**137 - * Checks that config file exists and contains mandatory parameters138 - */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 parameters137 + */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 + }151 152 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 + }164 165 165 - if (cmd.hasOption('h')) {166 - printHelp(ops);167 - }166 + if (cmd.hasOption('h')) {167 + printHelp(ops);168 + }168 169 169 - return cmd;170 - }170 + return cmd;171 + }171 172 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 + }177 178 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();181 182 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'));186 189 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'));191 197 192 - return options;193 - }198 + return options;199 + }194 200 } src/main/java/net/curisit/securis/LicenseManager.java
.. .. @@ -28,38 +28,39 @@ 28 28 */ 29 29 public class LicenseManager { 30 30 31 - private static final Logger LOG = LogManager.getLogger(License.class);31 + private static final Logger LOG = LogManager.getLogger(License.class);32 32 33 - private static LicenseManager singleton = new LicenseManager();33 + private static LicenseManager singleton = new LicenseManager();34 34 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";39 36 40 - public static LicenseManager getInstance() {41 - return singleton;42 - }37 + private LicenseManager() {38 + }43 39 44 - /**45 - * Loads a license from file46 - *47 - * @param licFile48 - * @return The license bean49 - * @throws SeCurisException50 - */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 + }60 43 61 44 /** 62 - * Validates the license stored in {@code licFile} and get the corresponding LicenseBean45 + * Loads a license from file46 + *47 + * @param licFile48 + * @return The license bean49 + * @throws SeCurisException50 + */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 corresponding63 + * LicenseBean63 64 * <p> 64 65 * The validation includes: 65 66 * <ul> .. .. @@ -79,7 +80,8 @@ 79 80 } 80 81 81 82 /** 82 - * Validates the license stored in {@code licFile} and get the corresponding LicenseBean. The License date is not validated83 + * Validates the license stored in {@code licFile} and get the corresponding84 + * LicenseBean. The License date is not validated83 85 * <p> 84 86 * The validation includes: 85 87 * <ul> .. .. @@ -96,7 +98,8 @@ 96 98 public LicenseBean validateLicense(File licFile, boolean excludeDateValidation) throws SeCurisException { 97 99 LicenseBean licBean = load(licFile); 98 100 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));100 103 LicenseValidator.getInstance().validateLogo(licBean); 101 104 102 105 if (!excludeDateValidation) { .. .. @@ -108,18 +111,19 @@ 108 111 return licBean; 109 112 } 110 113 111 - /**112 - * Request to server for a valid license113 - *114 - * @return The license bean returned by the server115 - * @throws SeCurisException116 - */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 license116 + *117 + * @return The license bean returned by the server118 + * @throws SeCurisException119 + */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));119 123 120 - SignedLicenseBean lic = requestLicenseToServer(req);121 - return lic;122 - }124 + SignedLicenseBean lic = requestLicenseToServer(req);125 + return lic;126 + }123 127 124 128 /** 125 129 * Generate a license file using a {@link LicenseBean} .. .. @@ -157,43 +161,47 @@ 157 161 158 162 } 159 163 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);165 166 166 - /**167 - * Creates a new request file with current hardware in the File passed as parameter168 - *169 - * @param outputRequestFile170 - * File where the request data will be saved171 - * @return The generated request bean172 - * @throws SeCurisException173 - */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 + }176 169 177 - ReqGenerator.getInstance().save(req, outputRequestFile);170 + /**171 + * Creates a new request file with current hardware in the File passed as172 + * parameter173 + *174 + * @param outputRequestFile175 + * File where the request data will be saved176 + * @return The generated request bean177 + * @throws SeCurisException178 + */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));178 182 179 - return req;180 - }183 + ReqGenerator.getInstance().save(req, outputRequestFile);181 184 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 licenseFile186 - * Current and valid License file187 - * @return New license bean if server creates a new one, otherwise the same current License bean will be returned188 - * @throws SeCurisException189 - */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 licenseFile193 + * Current and valid License file194 + * @return New license bean if server creates a new one, otherwise the same195 + * current License bean will be returned196 + * @throws SeCurisException197 + */198 + public SignedLicenseBean renew(File licenseFile) throws SeCurisException {199 + LicenseBean lic = validateLicense(licenseFile);192 200 193 201 SignedLicenseBean newLic = ConnectionManager.getInstance().executePost(Command.RENEW_LIC, SignedLicenseBean.class, lic); 194 202 195 - return newLic;196 - }203 + return newLic;204 + }197 205 198 206 public void testServer() throws SeCurisException { 199 207 StatusBean status = ConnectionManager.getInstance().executeGet(Command.TEST, StatusBean.class); src/main/java/net/curisit/securis/LicenseValidator.java
.. .. @@ -14,55 +14,56 @@ 14 14 15 15 public class LicenseValidator { 16 16 17 - private static final Logger LOG = LogManager.getLogger(LicenseValidator.class);17 + private static final Logger LOG = LogManager.getLogger(LicenseValidator.class);18 18 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;21 21 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 + }29 29 30 - private LicenseValidator() {31 - }30 + private LicenseValidator() {31 + }32 32 33 - public static LicenseValidator getInstance() {34 - return singleton;35 - }33 + public static LicenseValidator getInstance() {34 + return singleton;35 + }36 36 37 - /**38 - * @return CRC string for customer logo39 - */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 logo39 + */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 + }50 50 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 + }60 60 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 + }67 68 68 69 } src/main/java/net/curisit/securis/ReqGenerator.java
.. .. @@ -19,76 +19,77 @@ 19 19 20 20 public class ReqGenerator { 21 21 22 - private static final Logger LOG = LogManager.getLogger(ReqGenerator.class);22 + private static final Logger LOG = LogManager.getLogger(ReqGenerator.class);23 23 24 - private static ReqGenerator singleton = new ReqGenerator();24 + private static ReqGenerator singleton = new ReqGenerator();25 25 26 - private ReqGenerator() {27 - }26 + private ReqGenerator() {27 + }28 28 29 - public static ReqGenerator getInstance() {30 - return singleton;31 - }29 + public static ReqGenerator getInstance() {30 + return singleton;31 + }32 32 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();35 35 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());42 43 43 - return req;44 - }44 + return req;45 + }45 46 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 + }56 57 57 - /**58 - * Generate a request file using a {@link RequestBean}59 - *60 - * @param req61 - * @param file62 - * @throws SeCurisException63 - */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 req62 + * @param file63 + * @throws SeCurisException64 + */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 + }76 77 77 - LOG.debug("License saved in {}", file);78 + LOG.debug("License saved in {}", file);78 79 79 - }80 + }80 81 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 + }94 95 } src/main/java/net/curisit/securis/beans/LicenseBean.java
.. .. @@ -10,94 +10,97 @@ 10 10 import org.codehaus.jackson.annotate.JsonPropertyOrder; 11 11 12 12 @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 +})15 16 public class LicenseBean extends RequestBean { 16 - private Date expirationDate;17 - /**18 - * Signature is stored in Base64 code19 - */20 - private String signature;21 - private String licenseType;22 - private String licenseCode;17 + private Date expirationDate;18 + /**19 + * Signature is stored in Base64 code20 + */21 + private String signature;22 + private String licenseCode;23 + private String appName;23 24 24 - private Map<String, Object> metadata;25 + private Map<String, Object> metadata;25 26 26 - public LicenseBean() {27 - }27 + public LicenseBean() {28 + }28 29 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 + }37 39 38 - public Map<String, Object> getMetadata() {39 - return metadata;40 - }40 + public Map<String, Object> getMetadata() {41 + return metadata;42 + }41 43 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 + }45 47 46 - @JsonIgnore47 - public String getSignature() {48 - return signature;49 - }48 + @JsonIgnore49 + public String getSignature() {50 + return signature;51 + }50 52 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 + }55 57 56 - public Date getExpirationDate() {57 - return expirationDate;58 - }58 + public Date getExpirationDate() {59 + return expirationDate;60 + }59 61 60 - public void setExpirationDate(Date expirationDate) {61 - this.expirationDate = expirationDate;62 - }62 + public void setExpirationDate(Date expirationDate) {63 + this.expirationDate = expirationDate;64 + }63 65 64 - @Override65 - 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 - @Override75 - 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 + @Override67 + 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;83 72 84 - return result && super.equals(obj);85 - }73 + return code;74 + };86 75 87 - public String getLicenseCode() {88 - return licenseCode;89 - }76 + @Override77 + public boolean equals(Object obj) {78 + if (!(obj instanceof LicenseBean))79 + return false;80 + LicenseBean rb = (LicenseBean) obj;81 + boolean result = true;82 + result = result83 + && ((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)));90 86 91 - public void setLicenseCode(String licenseCode) {92 - this.licenseCode = licenseCode;93 - }87 + return result && super.equals(obj);88 + }94 89 95 - public String getLicenseType() {96 - return licenseType;97 - }90 + public String getLicenseCode() {91 + return licenseCode;92 + }98 93 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 + }102 105 103 106 } src/main/java/net/curisit/securis/beans/RequestBean.java
.. .. @@ -8,107 +8,119 @@ 8 8 @JsonAutoDetect 9 9 @JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL) 10 10 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;17 18 18 - public String getCustomerCode() {19 - return customerCode;20 - }19 + public String getCustomerCode() {20 + return customerCode;21 + }21 22 22 - public void setCustomerCode(String customerCode) {23 - this.customerCode = customerCode;24 - }23 + public void setCustomerCode(String customerCode) {24 + this.customerCode = customerCode;25 + }25 26 26 - public String getCrcLogo() {27 - return crcLogo;28 - }27 + public String getCrcLogo() {28 + return crcLogo;29 + }29 30 30 - public void setCrcLogo(String crcLogo) {31 - this.crcLogo = crcLogo;32 - }31 + public void setCrcLogo(String crcLogo) {32 + this.crcLogo = crcLogo;33 + }33 34 34 - public String getAppCode() {35 - return appCode;36 - }35 + public List<String> getMacAddresses() {36 + return macAddresses;37 + }37 38 38 - public void setAppCode(String appCode) {39 - this.appCode = appCode;40 - }39 + public void setMacAddresses(List<String> macAddresses) {40 + this.macAddresses = macAddresses;41 + }41 42 42 - public List<String> getMacAddresses() {43 - return macAddresses;44 - }43 + public String getOsName() {44 + return osName;45 + }45 46 46 - public void setMacAddresses(List<String> macAddresses) {47 - this.macAddresses = macAddresses;48 - }47 + public void setOsName(String osName) {48 + this.osName = osName;49 + }49 50 50 - public String getOsName() {51 - return osName;52 - }51 + public String getArch() {52 + return arch;53 + }53 54 54 - public void setOsName(String osName) {55 - this.osName = osName;56 - }55 + public void setArch(String arch) {56 + this.arch = arch;57 + }57 58 58 - public String getArch() {59 - return arch;60 - }59 + public boolean match(RequestBean rb) {61 60 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 it65 + 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());65 69 66 - public boolean match(RequestBean rb) {70 + return result;71 + }67 72 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 it71 - 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 + }75 80 76 - return result;77 - }81 + @Override82 + 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;78 91 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 + };86 94 95 + @Override96 + 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 + }87 110 88 - @Override89 - 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 - @Override102 - 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 + }114 126 } src/main/java/net/curisit/securis/beans/SignedLicenseBean.java
.. .. @@ -6,21 +6,22 @@ 6 6 @JsonAutoDetect 7 7 public class SignedLicenseBean extends LicenseBean { 8 8 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 + }16 13 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 + }25 26 26 27 } src/main/java/net/curisit/securis/utils/Params.java
.. .. @@ -17,182 +17,197 @@ 17 17 */ 18 18 public class Params { 19 19 20 - private static final Logger LOG = LogManager.getLogger(Params.class);20 + private static final Logger LOG = LogManager.getLogger(Params.class);21 21 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 startup24 - */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 startup25 + */25 26 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";27 28 28 - private static Properties params = null;29 + private static Properties params = null;29 30 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 + }38 39 39 - /**40 - * Loads application global parameters from a classpath resource41 - *42 - * @param resource43 - * : Resource location in classpath, i.e: "/resource/cp-securis.conf"44 - * @throws IOException45 - */46 - public static void loadParameters(String resource) throws IOException {40 + /**41 + * Loads application global parameters from a classpath resource42 + *43 + * @param resource44 + * : Resource location in classpath, i.e:45 + * "/resource/cp-securis.conf"46 + * @throws IOException47 + */48 + public static void loadParameters(String resource) throws IOException {47 49 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);50 52 51 - params = new Properties();52 - try {53 + params = new Properties();54 + try {53 55 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 + }61 63 62 - }64 + }63 65 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 + }67 69 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 + }71 73 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 + }75 77 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 + }79 81 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 + }83 85 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 + }87 89 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.ComparePttidVsPtn93 - * securis.sort.comparator.1: net.cp.securis.comparators.CompareFrequency94 - * securis.sort.comparator.2: net.cp.securis.comparators.CompareOutgoingVsIncomming95 - * securis.sort.comparator.3: net.cp.securis.comparators.CompareDuration96 - * securis.sort.comparator.4: net.cp.securis.comparators.CompareCallVsSms97 - * </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 prefix112 - * @return113 - */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 with92 + * <code>prefix</code> It reads sequentially. For example:93 + *94 + * <pre>95 + * securis.sort.comparator.0: net.cp.securis.comparators.ComparePttidVsPtn96 + * securis.sort.comparator.1: net.cp.securis.comparators.CompareFrequency97 + * securis.sort.comparator.2: net.cp.securis.comparators.CompareOutgoingVsIncomming98 + * securis.sort.comparator.3: net.cp.securis.comparators.CompareDuration99 + * securis.sort.comparator.4: net.cp.securis.comparators.CompareCallVsSms100 + * </pre>101 + *102 + * That config (for prefix: "securis.sort.comparator" ) will return a103 + * 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, only114 + * will be returned properties found before gap.115 + *116 + * @param prefix117 + * @return118 + */119 + public static List<String> getListByPrefix(String prefix) {120 + List<String> list = new ArrayList<String>();116 121 117 - String tpl = prefix + ".{0}";122 + String tpl = prefix + ".{0}";118 123 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 + }125 130 126 - return list;127 - }131 + return list;132 + }128 133 129 - /**130 - * Gets param value in config file or environment variables131 - *132 - * @param paramname133 - * Global parameter's name134 - * @return Value of paramname or null if paramname is not found neither in config file nor in environment variables135 - */136 - public static String get(String paramname) {134 + /**135 + * Gets param value in config file or environment variables136 + *137 + * @param paramname138 + * Global parameter's name139 + * @return Value of paramname or null if paramname is not found neither in140 + * config file nor in environment variables141 + */142 + public static String get(String paramname) {137 143 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.";139 145 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 + }145 151 146 - /**147 - * Gets param value from config file or environment variables148 - *149 - * @param paramname150 - * Global parameter's name151 - * @param defaultval152 - * @return Value of paramname or defaultval if paramname is not found153 - */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 variables154 + *155 + * @param paramname156 + * Global parameter's name157 + * @param defaultval158 + * @return Value of paramname or defaultval if paramname is not found159 + */160 + public static String get(String paramname, String defaultval) {161 + String value = get(paramname);162 + return (value == null ? defaultval : value);163 + }158 164 159 - /**160 - * Gets param value in config file or environment variables161 - *162 - * @param paramname163 - * Global parameter's name164 - * @return Integer value of paramname or -1 if paramname is not found neither in config file nor in environment variables165 - */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 variables167 + *168 + * @param paramname169 + * Global parameter's name170 + * @return Integer value of paramname or -1 if paramname is not found171 + * neither in config file nor in environment variables172 + */173 + public static int getInt(String paramname) {174 + String value = get(paramname);175 + return (value == null ? -1 : Integer.parseInt(value));176 + }170 177 171 - /**172 - * Gets param value from config file or environment variables173 - *174 - * @param paramname175 - * Global parameter's name176 - * @param defaultval177 - * @return Integer value of paramname or defaultval if paramname is not found178 - */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 variables180 + *181 + * @param paramname182 + * Global parameter's name183 + * @param defaultval184 + * @return Integer value of paramname or defaultval if paramname is not185 + * found186 + */187 + public static int getInt(String paramname, int defaultval) {188 + String value = get(paramname);189 + return (value == null ? defaultval : Integer.parseInt(value));190 + }183 191 184 - public static class KEYS {192 + public static class KEYS {185 193 186 - /**187 - * Public key file, Usually in "PEM" format188 - */189 - public static final String PUBLIC_KEY_FILE = "public.key.file";194 + /**195 + * Public key file, Usually in "PEM" format196 + */197 + public static final String PUBLIC_KEY_FILE = "public.key.file";190 198 191 - public static final String APPLICATION_CODE = "app.code";199 + public static final String APPLICATION_CODE = "app.code";192 200 193 - public static final String CUSTOMER_CODE = "customer.code";201 + public static final String CUSTOMER_CODE = "customer.code";194 202 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 + }197 212 198 213 }