| .. | .. |
|---|
| 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 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 | + } |
|---|
| 60 | 43 | |
|---|
| 61 | 44 | /** |
|---|
| 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 |
|---|
| 63 | 64 | * <p> |
|---|
| 64 | 65 | * The validation includes: |
|---|
| 65 | 66 | * <ul> |
|---|
| .. | .. |
|---|
| 79 | 80 | } |
|---|
| 80 | 81 | |
|---|
| 81 | 82 | /** |
|---|
| 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 |
|---|
| 83 | 85 | * <p> |
|---|
| 84 | 86 | * The validation includes: |
|---|
| 85 | 87 | * <ul> |
|---|
| .. | .. |
|---|
| 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 | 111 | return licBean; |
|---|
| 109 | 112 | } |
|---|
| 110 | 113 | |
|---|
| 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)); |
|---|
| 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 | 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 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 | + } |
|---|
| 176 | 169 | |
|---|
| 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)); |
|---|
| 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 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); |
|---|
| 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); |
|---|