| .. | .. |
|---|
| 11 | 11 | import net.curisit.securis.beans.LicenseBean; |
|---|
| 12 | 12 | import net.curisit.securis.beans.RequestBean; |
|---|
| 13 | 13 | import net.curisit.securis.beans.SignedLicenseBean; |
|---|
| 14 | +import net.curisit.securis.beans.StatusBean; |
|---|
| 14 | 15 | import net.curisit.securis.utils.JsonUtils; |
|---|
| 15 | 16 | import net.curisit.securis.utils.Params; |
|---|
| 16 | 17 | import net.curisit.securis.utils.SignatureHelper; |
|---|
| .. | .. |
|---|
| 86 | 87 | * @return The license bean returned by the server |
|---|
| 87 | 88 | * @throws SeCurisException |
|---|
| 88 | 89 | */ |
|---|
| 89 | | - public LicenseBean requestLicense() throws SeCurisException { |
|---|
| 90 | + public SignedLicenseBean requestLicense() throws SeCurisException { |
|---|
| 90 | 91 | RequestBean req = ReqGenerator.getInstance().createRequest(Params.get(Params.KEYS.APPLICATION_CODE), Params.get(Params.KEYS.CUSTOMER_CODE)); |
|---|
| 91 | 92 | |
|---|
| 92 | | - LicenseBean lic = requestLicenseToServer(req); |
|---|
| 93 | + SignedLicenseBean lic = requestLicenseToServer(req); |
|---|
| 93 | 94 | return lic; |
|---|
| 94 | 95 | } |
|---|
| 95 | 96 | |
|---|
| 96 | | - /** |
|---|
| 97 | | - * Generate a license file using a {@link LicenseBean} |
|---|
| 98 | | - * |
|---|
| 99 | | - * @param license |
|---|
| 100 | | - * @param file |
|---|
| 101 | | - * @throws SeCurisException |
|---|
| 102 | | - */ |
|---|
| 103 | | - public void save(LicenseBean license, File file) throws SeCurisException { |
|---|
| 104 | | - SignedLicenseBean signedLic = new SignedLicenseBean(license); |
|---|
| 105 | | - byte[] json; |
|---|
| 106 | | - try { |
|---|
| 107 | | - json = JsonUtils.toJSON(signedLic, true).getBytes("utf-8"); |
|---|
| 108 | | - Files.write(Paths.get(file.toURI()), json, StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING); |
|---|
| 109 | | - } catch (UnsupportedEncodingException e) { |
|---|
| 110 | | - LOG.error("Error creating json doc from license: " + license, e); |
|---|
| 111 | | - throw new SeCurisException("Error creating json doc from license: " + license, e); |
|---|
| 112 | | - } catch (IOException e) { |
|---|
| 113 | | - LOG.error("Error creating license file: " + file, e); |
|---|
| 114 | | - throw new SeCurisException("Error creating json doc from license: " + license, e); |
|---|
| 115 | | - } |
|---|
| 97 | + /** |
|---|
| 98 | + * Generate a license file using a {@link LicenseBean} |
|---|
| 99 | + * |
|---|
| 100 | + * @param license |
|---|
| 101 | + * @param file |
|---|
| 102 | + * @throws SeCurisException |
|---|
| 103 | + */ |
|---|
| 104 | + public void save(LicenseBean license, File file) throws SeCurisException { |
|---|
| 105 | + SignedLicenseBean signedLic = new SignedLicenseBean(license); |
|---|
| 106 | + save(signedLic, file); |
|---|
| 107 | + } |
|---|
| 116 | 108 | |
|---|
| 117 | | - LOG.debug("License saved in {}", file); |
|---|
| 109 | + /** |
|---|
| 110 | + * Generate a license file using a {@link LicenseBean} |
|---|
| 111 | + * |
|---|
| 112 | + * @param license |
|---|
| 113 | + * @param file |
|---|
| 114 | + * @throws SeCurisException |
|---|
| 115 | + */ |
|---|
| 116 | + public void save(SignedLicenseBean signedLic, File file) throws SeCurisException { |
|---|
| 117 | + byte[] json; |
|---|
| 118 | + try { |
|---|
| 119 | + json = JsonUtils.toJSON(signedLic, true).getBytes("utf-8"); |
|---|
| 120 | + Files.write(Paths.get(file.toURI()), json, StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING); |
|---|
| 121 | + } catch (UnsupportedEncodingException e) { |
|---|
| 122 | + LOG.error("Error creating json doc from license: " + signedLic, e); |
|---|
| 123 | + throw new SeCurisException("Error creating json doc from license: " + signedLic, e); |
|---|
| 124 | + } catch (IOException e) { |
|---|
| 125 | + LOG.error("Error creating license file: " + file, e); |
|---|
| 126 | + throw new SeCurisException("Error creating json doc from license: " + signedLic, e); |
|---|
| 127 | + } |
|---|
| 118 | 128 | |
|---|
| 119 | | - } |
|---|
| 129 | + LOG.debug("License saved in {}", file); |
|---|
| 130 | + |
|---|
| 131 | + } |
|---|
| 120 | 132 | |
|---|
| 121 | 133 | private SignedLicenseBean requestLicenseToServer(RequestBean req) throws SeCurisException { |
|---|
| 122 | 134 | SignedLicenseBean lic = ConnectionManager.getInstance().executePost(Command.CREATE_LIC, SignedLicenseBean.class, req); |
|---|
| .. | .. |
|---|
| 157 | 169 | } |
|---|
| 158 | 170 | |
|---|
| 159 | 171 | public void testServer() throws SeCurisException { |
|---|
| 160 | | - String pingMsg = ConnectionManager.getInstance().executeGet(Command.RENEW_LIC, String.class); |
|---|
| 161 | | - if (!PING_MESSAGE.equals(pingMsg)) { |
|---|
| 172 | + StatusBean status = ConnectionManager.getInstance().executeGet(Command.TEST, StatusBean.class); |
|---|
| 173 | + if (!PING_MESSAGE.equals(status.getMessage())) { |
|---|
| 162 | 174 | throw new SeCurisException("SeCuris Server is not running in given URL"); |
|---|
| 163 | 175 | } |
|---|
| 164 | 176 | } |
|---|