| .. | .. |
|---|
| 38 | 38 | public static final String HEADER_LICENSE_NAME_OR_REFERENCE = "X-SECURIS-LIC-NAMEREF"; |
|---|
| 39 | 39 | public static final String HEADER_LICENSE_EMAIL = "X-SECURIS-LIC-EMAIL"; |
|---|
| 40 | 40 | |
|---|
| 41 | | - private LicenseManager() {} |
|---|
| 41 | + private LicenseManager() { |
|---|
| 42 | + } |
|---|
| 42 | 43 | |
|---|
| 43 | 44 | public static LicenseManager getInstance() { |
|---|
| 44 | 45 | return singleton; |
|---|
| .. | .. |
|---|
| 62 | 63 | } |
|---|
| 63 | 64 | |
|---|
| 64 | 65 | /** |
|---|
| 65 | | - * Validates the license stored in {@code licFile} and get the corresponding LicenseBean |
|---|
| 66 | + * Validates the license stored in {@code licFile} and get the corresponding |
|---|
| 67 | + * LicenseBean |
|---|
| 66 | 68 | * <p> |
|---|
| 67 | 69 | * The validation includes: |
|---|
| 68 | 70 | * <ul> |
|---|
| .. | .. |
|---|
| 82 | 84 | } |
|---|
| 83 | 85 | |
|---|
| 84 | 86 | /** |
|---|
| 85 | | - * Validates the license stored in {@code licFile} and get the corresponding LicenseBean. The License date is not validated |
|---|
| 87 | + * Validates the license stored in {@code licFile} and get the corresponding |
|---|
| 88 | + * LicenseBean. The License date is not validated |
|---|
| 86 | 89 | * <p> |
|---|
| 87 | 90 | * The validation includes: |
|---|
| 88 | 91 | * <ul> |
|---|
| .. | .. |
|---|
| 99 | 102 | public LicenseBean validateLicense(File licFile, boolean excludeDateValidation) throws SeCurisException { |
|---|
| 100 | 103 | LicenseBean licBean = load(licFile); |
|---|
| 101 | 104 | SignatureHelper.getInstance().validateSignature(licBean); |
|---|
| 102 | | - LicenseValidator.getInstance().validateHW(licBean, Params.get(Params.KEYS.LIC_TYPE_CODE, Params.get(Params.KEYS.APPLICATION_CODE)), Params.get(Params.KEYS.CUSTOMER_CODE), Params.get(Params.KEYS.PACK_CODE)); |
|---|
| 105 | + if (licBean.getActivationCode() != null) { |
|---|
| 106 | + LicenseValidator.getInstance().validateHW(licBean, Params.get(Params.KEYS.APPLICATION_CODE), licBean.getActivationCode()); |
|---|
| 107 | + } else { |
|---|
| 108 | + LicenseValidator.getInstance().validateHW(licBean, Params.get(Params.KEYS.LIC_TYPE_CODE, Params.get(Params.KEYS.APPLICATION_CODE)), |
|---|
| 109 | + Params.get(Params.KEYS.CUSTOMER_CODE), Params.get(Params.KEYS.PACK_CODE)); |
|---|
| 110 | + } |
|---|
| 103 | 111 | LicenseValidator.getInstance().validateLogo(licBean); |
|---|
| 104 | 112 | |
|---|
| 105 | 113 | if (!excludeDateValidation) { |
|---|
| .. | .. |
|---|
| 118 | 126 | * @throws SeCurisException |
|---|
| 119 | 127 | */ |
|---|
| 120 | 128 | public SignedLicenseBean requestLicense(String nameOrReference, String email) throws SeCurisException { |
|---|
| 121 | | - RequestBean req = ReqGenerator.getInstance().createRequest(Params.get(Params.KEYS.LIC_TYPE_CODE, Params.get(Params.KEYS.APPLICATION_CODE)), Params.get(Params.KEYS.CUSTOMER_CODE), Params.get(Params.KEYS.PACK_CODE)); |
|---|
| 129 | + RequestBean req = ReqGenerator.getInstance().createRequest(Params.get(Params.KEYS.LIC_TYPE_CODE, Params.get(Params.KEYS.APPLICATION_CODE)), |
|---|
| 130 | + Params.get(Params.KEYS.CUSTOMER_CODE), Params.get(Params.KEYS.PACK_CODE)); |
|---|
| 131 | + |
|---|
| 132 | + SignedLicenseBean lic = requestLicenseToServer(req, nameOrReference, email); |
|---|
| 133 | + return lic; |
|---|
| 134 | + } |
|---|
| 135 | + |
|---|
| 136 | + /** |
|---|
| 137 | + * Request to server for a valid license |
|---|
| 138 | + * |
|---|
| 139 | + * @return The license bean returned by the server |
|---|
| 140 | + * @throws SeCurisException |
|---|
| 141 | + */ |
|---|
| 142 | + public SignedLicenseBean requestLicense(String nameOrReference, String email, String activationCode) throws SeCurisException { |
|---|
| 143 | + RequestBean req = ReqGenerator.getInstance().createRequest(Params.get(Params.KEYS.APPLICATION_CODE), activationCode); |
|---|
| 122 | 144 | |
|---|
| 123 | 145 | SignedLicenseBean lic = requestLicenseToServer(req, nameOrReference, email); |
|---|
| 124 | 146 | return lic; |
|---|
| .. | .. |
|---|
| 170 | 192 | } |
|---|
| 171 | 193 | |
|---|
| 172 | 194 | /** |
|---|
| 173 | | - * Creates a new request file with current hardware in the File passed as parameter |
|---|
| 195 | + * Creates a new request file with current hardware in the File passed as |
|---|
| 196 | + * parameter |
|---|
| 174 | 197 | * |
|---|
| 175 | 198 | * @param outputRequestFile |
|---|
| 176 | 199 | * File where the request data will be saved |
|---|
| .. | .. |
|---|
| 178 | 201 | * @throws SeCurisException |
|---|
| 179 | 202 | */ |
|---|
| 180 | 203 | public RequestBean createRequestFile(File outputRequestFile) throws SeCurisException { |
|---|
| 181 | | - RequestBean req = ReqGenerator.getInstance().createRequest(Params.get(Params.KEYS.LIC_TYPE_CODE, Params.get(Params.KEYS.APPLICATION_CODE)), Params.get(Params.KEYS.CUSTOMER_CODE), Params.get(Params.KEYS.PACK_CODE)); |
|---|
| 204 | + RequestBean req = ReqGenerator.getInstance().createRequest(Params.get(Params.KEYS.LIC_TYPE_CODE, Params.get(Params.KEYS.APPLICATION_CODE)), |
|---|
| 205 | + Params.get(Params.KEYS.CUSTOMER_CODE), Params.get(Params.KEYS.PACK_CODE)); |
|---|
| 182 | 206 | |
|---|
| 183 | 207 | ReqGenerator.getInstance().save(req, outputRequestFile); |
|---|
| 184 | 208 | |
|---|
| .. | .. |
|---|
| 186 | 210 | } |
|---|
| 187 | 211 | |
|---|
| 188 | 212 | /** |
|---|
| 189 | | - * Send the current license file to server, which is previously validated, to get a renewed one if it is prepared in server side. |
|---|
| 213 | + * Creates a new request file with current hardware in the File passed as |
|---|
| 214 | + * parameter |
|---|
| 215 | + * |
|---|
| 216 | + * @param outputRequestFile |
|---|
| 217 | + * File where the request data will be saved |
|---|
| 218 | + * @return The generated request bean |
|---|
| 219 | + * @throws SeCurisException |
|---|
| 220 | + */ |
|---|
| 221 | + public RequestBean createRequestFile(File outputRequestFile, String activationCode) throws SeCurisException { |
|---|
| 222 | + RequestBean req = ReqGenerator.getInstance().createRequest(Params.get(Params.KEYS.APPLICATION_CODE), activationCode); |
|---|
| 223 | + |
|---|
| 224 | + ReqGenerator.getInstance().save(req, outputRequestFile); |
|---|
| 225 | + |
|---|
| 226 | + return req; |
|---|
| 227 | + } |
|---|
| 228 | + |
|---|
| 229 | + /** |
|---|
| 230 | + * Send the current license file to server, which is previously validated, |
|---|
| 231 | + * to get a renewed one if it is prepared in server side. |
|---|
| 190 | 232 | * |
|---|
| 191 | 233 | * @param licenseFile |
|---|
| 192 | 234 | * Current and valid License file |
|---|
| 193 | | - * @return New license bean if server creates a new one, otherwise the same current License bean will be returned |
|---|
| 235 | + * @return New license bean if server creates a new one, otherwise the same |
|---|
| 236 | + * current License bean will be returned |
|---|
| 194 | 237 | * @throws SeCurisException |
|---|
| 195 | 238 | */ |
|---|
| 196 | 239 | public SignedLicenseBean renew(File licenseFile) throws SeCurisException { |
|---|
| .. | .. |
|---|
| 220 | 263 | } |
|---|
| 221 | 264 | } |
|---|
| 222 | 265 | |
|---|
| 223 | | - public static void main(String[] args) throws SeCurisException { |
|---|
| 224 | | - String filename = "/Users/rob/.doxr/doxr.lic"; |
|---|
| 225 | | - |
|---|
| 226 | | - if (filename == null) |
|---|
| 227 | | - filename = "./license.req"; |
|---|
| 228 | | - File file = new File(filename); |
|---|
| 229 | | - LicenseManager.getInstance().validateLicense(file); |
|---|
| 230 | | - LOG.info("Validation Ok"); |
|---|
| 231 | | - String r = "{\"licenseTypeCode\":\"DX01\",\"packCode\":\"DEVDX01\",\"arch\":\"x86_64\",\"osName\":\"darwin\",\"customerCode\":\"CIT\",\"macAddresses\":[\"60:c5:47:03:cf:c8\",\"b2:00:12:b6:88:e0\"]}"; |
|---|
| 232 | | - RequestBean rb = JsonUtils.json2object(r, RequestBean.class); |
|---|
| 233 | | - System.out.println(rb); |
|---|
| 234 | | - LOG.info("Request file {} generated OK", file.getAbsolutePath()); |
|---|
| 235 | | - |
|---|
| 236 | | - } |
|---|
| 237 | 266 | } |
|---|