| .. | .. |
|---|
| 6 | 6 | import net.curisit.securis.beans.LicenseBean; |
|---|
| 7 | 7 | import net.curisit.securis.beans.RequestBean; |
|---|
| 8 | 8 | import net.curisit.securis.utils.JsonUtils; |
|---|
| 9 | +import net.curisit.securis.utils.Params; |
|---|
| 9 | 10 | |
|---|
| 10 | 11 | import org.apache.commons.io.FileUtils; |
|---|
| 11 | 12 | |
|---|
| .. | .. |
|---|
| 25 | 26 | return singleton; |
|---|
| 26 | 27 | } |
|---|
| 27 | 28 | |
|---|
| 28 | | - public LicenseBean validateLicense(File licFile, String appCode, String customerCode) throws SeCurisException { |
|---|
| 29 | + /** |
|---|
| 30 | + * Validates the license stored in {@code licFile} and get the corresponding LicenseBean |
|---|
| 31 | + * <p> |
|---|
| 32 | + * The validation includes: |
|---|
| 33 | + * <ul> |
|---|
| 34 | + * <li>Signature</li> |
|---|
| 35 | + * <li>HW data</li> |
|---|
| 36 | + * <li>Logo CRC</li> |
|---|
| 37 | + * </ul> |
|---|
| 38 | + * </p> |
|---|
| 39 | + * |
|---|
| 40 | + * @param licFile |
|---|
| 41 | + * @param appCode |
|---|
| 42 | + * @param customerCode |
|---|
| 43 | + * @return |
|---|
| 44 | + * @throws SeCurisException |
|---|
| 45 | + */ |
|---|
| 46 | + public LicenseBean validateLicense(File licFile) throws SeCurisException { |
|---|
| 29 | 47 | LicenseBean licBean; |
|---|
| 30 | 48 | try { |
|---|
| 31 | 49 | licBean = JsonUtils.json2object(FileUtils.readFileToString(licFile), LicenseBean.class); |
|---|
| 32 | 50 | } catch (IOException e) { |
|---|
| 33 | | - throw new SeCurisException("Error validating license", e); |
|---|
| 51 | + throw new SeCurisException("Error getting license data from file: " + licFile, e); |
|---|
| 34 | 52 | } |
|---|
| 35 | 53 | SignatureHelper.getInstance().validateSignature(licBean); |
|---|
| 36 | | - validateHW(licBean, appCode, customerCode); |
|---|
| 54 | + LicenseValidator.getInstance().validateHW(licBean, Params.get(Params.KEYS.APPLICATION_CODE), Params.get(Params.KEYS.CUSTOMER_CODE)); |
|---|
| 55 | + LicenseValidator.getInstance().validateLogo(licBean); |
|---|
| 37 | 56 | |
|---|
| 38 | 57 | return licBean; |
|---|
| 39 | 58 | } |
|---|
| 40 | 59 | |
|---|
| 41 | | - private void validateHW(RequestBean reqBean, String appCode, String customerCode) throws SeCurisException { |
|---|
| 42 | | - RequestBean currentHW = ReqGenerator.getInstance().createRequest(appCode, customerCode); |
|---|
| 43 | | - if (!currentHW.match(reqBean)) |
|---|
| 44 | | - throw new SeCurisException("Current System info mismatch the License System info: " + JsonUtils.toJSON(reqBean)); |
|---|
| 60 | + /** |
|---|
| 61 | + * Creates a new request file with current hardware in the File passed as paramter |
|---|
| 62 | + * |
|---|
| 63 | + * @param outputRequestFile |
|---|
| 64 | + * File where the request data will be saved |
|---|
| 65 | + * @return The generated request bean |
|---|
| 66 | + * @throws SeCurisException |
|---|
| 67 | + */ |
|---|
| 68 | + public RequestBean createRequestFile(File outputRequestFile) throws SeCurisException { |
|---|
| 69 | + RequestBean req = ReqGenerator.getInstance().createRequest(Params.get(Params.KEYS.APPLICATION_CODE), Params.get(Params.KEYS.CUSTOMER_CODE)); |
|---|
| 70 | + |
|---|
| 71 | + ReqGenerator.getInstance().save(req, outputRequestFile); |
|---|
| 72 | + |
|---|
| 73 | + return req; |
|---|
| 74 | + } |
|---|
| 75 | + |
|---|
| 76 | + /** |
|---|
| 77 | + * Send the current license file to server, which is previously validated, to get a renewed one if it is prepared in server side. |
|---|
| 78 | + * |
|---|
| 79 | + * @param licenseFile |
|---|
| 80 | + * Current and valid License file |
|---|
| 81 | + * @return New license bean if server creates a new one, otherwise the same current License bean will be returned |
|---|
| 82 | + * @throws SeCurisException |
|---|
| 83 | + */ |
|---|
| 84 | + public LicenseBean sync(File licenseFile) throws SeCurisException { |
|---|
| 85 | + LicenseBean lic = validateLicense(licenseFile); |
|---|
| 86 | + // TODO: Send the current LicenseBean to server to check if a new one is prepared. |
|---|
| 87 | + return lic; |
|---|
| 45 | 88 | } |
|---|
| 46 | 89 | |
|---|
| 47 | 90 | } |
|---|