From 2d59319508a0b2f326d9907fcd2d911a7b5536ae Mon Sep 17 00:00:00 2001
From: rsanchez <rsanchez@curisit.net>
Date: Thu, 24 Sep 2015 17:19:19 +0000
Subject: [PATCH] #2756 feature - Fixed LicenseBean creation and extended the current API
---
src/main/java/net/curisit/securis/beans/LicenseBean.java | 2
etc/build/files/config/securis-client.properties | 3
src/main/java/net/curisit/securis/ConnectionManager.java | 222 ++++++++++---------
src/main/java/net/curisit/securis/LicenseManager.java | 422 ++++++++++++++++++++------------------
4 files changed, 337 insertions(+), 312 deletions(-)
diff --git a/etc/build/files/config/securis-client.properties b/etc/build/files/config/securis-client.properties
index 6d15545..1b5d2e6 100644
--- a/etc/build/files/config/securis-client.properties
+++ b/etc/build/files/config/securis-client.properties
@@ -5,5 +5,4 @@
#########################################################################
license.server.url = https://securis.curistec.com/securis/api
-app.code = AP01
-customer.code = XX
+app.code = _AP_
diff --git a/src/main/java/net/curisit/securis/ConnectionManager.java b/src/main/java/net/curisit/securis/ConnectionManager.java
index 5b9b3c1..881ff69 100644
--- a/src/main/java/net/curisit/securis/ConnectionManager.java
+++ b/src/main/java/net/curisit/securis/ConnectionManager.java
@@ -33,134 +33,138 @@
*/
public class ConnectionManager {
- private static final Logger LOG = LogManager.getLogger(ConnectionManager.class);
- private static final int HTTP_STATUS_APP_ERRROR = 418;
- private static final String JSON_MEDIA_TYPE = "application/json";
- private static final String ERROR_MESSAGE_HEADER = "X-SECURIS-ERROR-MSG";
- private static final String ERROR_CODE_MESSAGE_HEADER = "X-SECURIS-ERROR-CODE";
+ private static final Logger LOG = LogManager.getLogger(ConnectionManager.class);
+ private static final int HTTP_STATUS_APP_ERRROR = 418;
+ private static final String JSON_MEDIA_TYPE = "application/json";
+ private static final String ERROR_MESSAGE_HEADER = "X-SECURIS-ERROR-MSG";
+ private static final String ERROR_CODE_MESSAGE_HEADER = "X-SECURIS-ERROR-CODE";
+ private static final String TOKEN_HEADER = "X-SECURIS-TOKEN";
- private static ConnectionManager singleton;
+ private static final String API_CLIENT_TOKEN = "OTk3ODRiMzY5NzQ5MWI5NmYyZGQyODRiYjY2ZTU2YzdmMTZjYzM3YTY3N2ExM2M3ODI2MjU5ZTMzOTIyYjUzNSBfY2xpZW50IDE5NzAtMDEtMDFUMDA6NTk6NTkuOTk5KzAxMDA=";
+ private static ConnectionManager singleton;
- private final String serverUrl;
- private final HttpClientBuilder httpClientBuilder;
+ private final String serverUrl;
+ private final HttpClientBuilder httpClientBuilder;
- private ConnectionManager() throws SeCurisException {
- String aux = Params.get(Params.KEYS.LICENSE_SERVER_URL, Params.DEFAUT_SERVER_URL);
- if (aux.endsWith("/")) {
- serverUrl = aux.substring(0, aux.length() - 2);
- } else {
- serverUrl = aux;
- }
- httpClientBuilder = createHttpClientBuilder();
- }
+ private ConnectionManager() throws SeCurisException {
+ String aux = Params.get(Params.KEYS.LICENSE_SERVER_URL, Params.DEFAUT_SERVER_URL);
+ if (aux.endsWith("/")) {
+ serverUrl = aux.substring(0, aux.length() - 2);
+ } else {
+ serverUrl = aux;
+ }
+ httpClientBuilder = createHttpClientBuilder();
+ }
- private HttpClientBuilder createHttpClientBuilder() throws SeCurisException {
- SSLContextBuilder builder = new SSLContextBuilder();
- SSLConnectionSocketFactory sslsf = null;
- try {
- builder.loadTrustMaterial((KeyStore) null, new TrustStrategy() {
- @Override
- public boolean isTrusted(X509Certificate[] chain, String authType) throws CertificateException {
- return true;
- }
- });
- sslsf = new SSLConnectionSocketFactory(builder.build());
- } catch (NoSuchAlgorithmException | KeyStoreException | KeyManagementException e1) {
- LOG.error(e1);
- throw new SeCurisException("Error creating SSL socket factory");
- }
- return HttpClientBuilder.create().setSSLSocketFactory(sslsf);
- }
+ private HttpClientBuilder createHttpClientBuilder() throws SeCurisException {
+ SSLContextBuilder builder = new SSLContextBuilder();
+ SSLConnectionSocketFactory sslsf = null;
+ try {
+ builder.loadTrustMaterial((KeyStore) null, new TrustStrategy() {
+ @Override
+ public boolean isTrusted(X509Certificate[] chain, String authType) throws CertificateException {
+ return true;
+ }
+ });
+ sslsf = new SSLConnectionSocketFactory(builder.build());
+ } catch (NoSuchAlgorithmException | KeyStoreException | KeyManagementException e1) {
+ LOG.error(e1);
+ throw new SeCurisException("Error creating SSL socket factory");
+ }
+ return HttpClientBuilder.create().setSSLSocketFactory(sslsf);
+ }
- public synchronized static ConnectionManager getInstance() throws SeCurisException {
- if (singleton == null) {
- singleton = new ConnectionManager();
- }
- return singleton;
- }
+ public synchronized static ConnectionManager getInstance() throws SeCurisException {
+ if (singleton == null) {
+ singleton = new ConnectionManager();
+ }
+ return singleton;
+ }
- public <T> T executePost(String command, Class<T> returnType, RequestBean req) throws SeCurisException {
- return executePost(command, returnType, req, null);
- }
+ public <T> T executePost(String command, Class<T> returnType, RequestBean req) throws SeCurisException {
+ return executePost(command, returnType, req, null);
+ }
- public <T> T executePost(String command, Class<T> returnType, RequestBean req, Map<String, String> headers) throws SeCurisException {
- HttpPost postRequest = new HttpPost(String.format("%s/%s", serverUrl, command));
- postRequest.addHeader("accept", JSON_MEDIA_TYPE);
- postRequest.addHeader("content-type", JSON_MEDIA_TYPE);
+ public <T> T executePost(String command, Class<T> returnType, RequestBean req, Map<String, String> headers) throws SeCurisException {
+ HttpPost postRequest = new HttpPost(String.format("%s/%s", serverUrl, command));
+ postRequest.addHeader(TOKEN_HEADER, API_CLIENT_TOKEN);
+ postRequest.addHeader("accept", JSON_MEDIA_TYPE);
+ postRequest.addHeader("content-type", JSON_MEDIA_TYPE);
- if (headers != null) {
- for (String header : headers.keySet()) {
- String headerValue = headers.get(header);
- postRequest.addHeader(header, headerValue);
- }
- }
+ if (headers != null) {
+ for (String header : headers.keySet()) {
+ String headerValue = headers.get(header);
+ postRequest.addHeader(header, headerValue);
+ }
+ }
- try {
- postRequest.setEntity(new StringEntity(JsonUtils.toJSON(req)));
- } catch (UnsupportedEncodingException | SeCurisException e1) {
- throw new SeCurisException("Error preparing POST command", e1);
- }
- HttpResponse response;
- try {
- response = httpClientBuilder.build().execute(postRequest);
+ try {
+ postRequest.setEntity(new StringEntity(JsonUtils.toJSON(req)));
+ } catch (UnsupportedEncodingException | SeCurisException e1) {
+ throw new SeCurisException("Error preparing POST command", e1);
+ }
+ HttpResponse response;
+ try {
+ response = httpClientBuilder.build().execute(postRequest);
- checkErrors(command, response);
+ checkErrors(command, response);
- String jsonLic = IOUtils.toString(response.getEntity().getContent());
- LOG.debug("Response content read OK: {}", jsonLic);
- T responseBean = JsonUtils.json2object(jsonLic, returnType);
+ String jsonLic = IOUtils.toString(response.getEntity().getContent());
+ LOG.debug("Response content read OK: {}", jsonLic);
+ T responseBean = JsonUtils.json2object(jsonLic, returnType);
- LOG.debug("Response bean read OK: {}", responseBean);
+ LOG.debug("Response bean read OK: {}", responseBean);
- return responseBean;
- } catch (IOException e) {
- LOG.error("Error accessing SeCuris server with command: " + command, e);
- throw new SeCurisException("Error accessing SeCuris server with command: " + command, e);
- }
- }
+ return responseBean;
+ } catch (IOException e) {
+ LOG.error("Error accessing SeCuris server with command: " + command, e);
+ throw new SeCurisException("Error accessing SeCuris server with command: " + command, e);
+ }
+ }
- private void checkErrors(String command, HttpResponse response) throws SeCurisException {
- if (response.getStatusLine().getStatusCode() != 200) {
- if (response.getStatusLine().getStatusCode() == HTTP_STATUS_APP_ERRROR) {
- String errorCode = response.getFirstHeader(ERROR_CODE_MESSAGE_HEADER).getValue();
- String errorMsg = response.getFirstHeader(ERROR_MESSAGE_HEADER).getValue();
- throw new SeCurisException(String.format("[%s] - %s", errorCode, errorMsg));
- }
- LOG.error("Unexpected error executing {}, Reason: {}", command, response.getStatusLine().getReasonPhrase());
- throw new SeCurisException("Error executing command " + command + ", status: " + response.getStatusLine().getStatusCode(),
- new IOException("Unexpected server error"));
- }
+ private void checkErrors(String command, HttpResponse response) throws SeCurisException {
+ if (response.getStatusLine().getStatusCode() != 200) {
+ if (response.getStatusLine().getStatusCode() == HTTP_STATUS_APP_ERRROR) {
+ String errorCode = response.getFirstHeader(ERROR_CODE_MESSAGE_HEADER).getValue();
+ String errorMsg = response.getFirstHeader(ERROR_MESSAGE_HEADER).getValue();
+ throw new SeCurisException(String.format("[%s] - %s", errorCode, errorMsg));
+ }
+ LOG.error("Unexpected error executing {}, Reason: {}", command, response.getStatusLine().getReasonPhrase());
+ throw new SeCurisException("Error executing command " + command + ", status: " + response.getStatusLine().getStatusCode(),
+ new IOException("Unexpected server error"));
+ }
- }
+ }
- public <T> T executeGet(String command, Class<T> returnType) throws SeCurisException {
- HttpGet getRequest = new HttpGet(String.format("%s/%s", serverUrl, command));
- getRequest.addHeader("accept", JSON_MEDIA_TYPE);
+ public <T> T executeGet(String command, Class<T> returnType) throws SeCurisException {
+ HttpGet getRequest = new HttpGet(String.format("%s/%s", serverUrl, command));
+ getRequest.addHeader(TOKEN_HEADER, API_CLIENT_TOKEN);
+ getRequest.addHeader("accept", JSON_MEDIA_TYPE);
- HttpResponse response;
- try {
- response = httpClientBuilder.build().execute(getRequest);
- if (response.getStatusLine().getStatusCode() != 200) {
- throw new SeCurisException("Error executing command " + command + ", status: " + response.getStatusLine().getStatusCode());
- }
- String jsonLic = IOUtils.toString(response.getEntity().getContent());
- LOG.debug("Response content read OK: {}", jsonLic);
- T responseBean = JsonUtils.json2object(jsonLic, returnType);
+ HttpResponse response;
+ try {
+ response = httpClientBuilder.build().execute(getRequest);
+ if (response.getStatusLine().getStatusCode() != 200) {
+ throw new SeCurisException("Error executing command " + command + ", status: " + response.getStatusLine().getStatusCode());
+ }
+ String jsonLic = IOUtils.toString(response.getEntity().getContent());
+ LOG.debug("Response content read OK: {}", jsonLic);
+ T responseBean = JsonUtils.json2object(jsonLic, returnType);
- LOG.debug("Response bean read OK: {}", responseBean);
+ LOG.debug("Response bean read OK: {}", responseBean);
- return responseBean;
- } catch (IOException e) {
- LOG.error("Error acessing SeCuris server", e);
- throw new SeCurisException("Error accessing SeCuris server");
- }
- }
+ return responseBean;
+ } catch (IOException e) {
+ LOG.error("Error acessing SeCuris server", e);
+ throw new SeCurisException("Error accessing SeCuris server");
+ }
+ }
- public static class Command {
- public static final String TEST = "ping";
- public static final String CREATE_LIC = "request";
- public static final String RENEW_LIC = "renew";
- public static final String VALIDATE = "validate";
- }
+ public static class Command {
+ public static final String TEST = "ping";
+ public static final String CREATE_LIC = "request";
+ public static final String RENEW_LIC = "renew";
+ public static final String VALIDATE = "validate";
+ }
}
diff --git a/src/main/java/net/curisit/securis/LicenseManager.java b/src/main/java/net/curisit/securis/LicenseManager.java
index 01625fc..29f79dd 100644
--- a/src/main/java/net/curisit/securis/LicenseManager.java
+++ b/src/main/java/net/curisit/securis/LicenseManager.java
@@ -30,237 +30,257 @@
*/
public class LicenseManager {
- private static final Logger LOG = LogManager.getLogger(LicenseManager.class);
+ private static final Logger LOG = LogManager.getLogger(LicenseManager.class);
- private static LicenseManager singleton = new LicenseManager();
+ private static LicenseManager singleton = new LicenseManager();
- public static final String PING_MESSAGE = "SeCuris API OK";
- public static final String HEADER_LICENSE_NAME_OR_REFERENCE = "X-SECURIS-LIC-NAMEREF";
- public static final String HEADER_LICENSE_EMAIL = "X-SECURIS-LIC-EMAIL";
+ public static final String PING_MESSAGE = "SeCuris API OK";
+ public static final String HEADER_LICENSE_NAME_OR_REFERENCE = "X-SECURIS-LIC-NAMEREF";
+ public static final String HEADER_LICENSE_EMAIL = "X-SECURIS-LIC-EMAIL";
- private LicenseManager() {
- }
+ private LicenseManager() {
+ }
- public static LicenseManager getInstance() {
- return singleton;
- }
+ public static LicenseManager getInstance() {
+ return singleton;
+ }
- /**
- * Loads a license from file
- *
- * @param licFile
- * @return The license bean
- * @throws SeCurisException
- */
- public LicenseBean load(File licFile) throws SeCurisException {
- LicenseBean licBean;
- try {
- licBean = JsonUtils.json2object(FileUtils.readFileToString(licFile), LicenseBean.class);
- } catch (IOException e) {
- throw new SeCurisException("Error getting license data from file: " + licFile, e);
- }
- return licBean;
- }
+ /**
+ * Loads a license from file
+ *
+ * @param licFile
+ * @return The license bean
+ * @throws SeCurisException
+ */
+ public LicenseBean load(File licFile) throws SeCurisException {
+ LicenseBean licBean;
+ try {
+ licBean = JsonUtils.json2object(FileUtils.readFileToString(licFile), LicenseBean.class);
+ } catch (IOException e) {
+ throw new SeCurisException("Error getting license data from file: " + licFile, e);
+ }
+ return licBean;
+ }
- /**
- * Validates the license stored in {@code licFile} and get the corresponding
- * LicenseBean
- * <p>
- * The validation includes:
- * <ul>
- * <li>Signature</li>
- * <li>HW data</li>
- * <li>Logo CRC</li>
- * </ul>
- * </p>
- *
- * @param licFile
- * @return The license bean stored in file
- * @throws SeCurisException
- */
- public LicenseBean validateLicense(File licFile) throws SeCurisException {
+ /**
+ * Validates the license stored in {@code licFile} and get the corresponding
+ * LicenseBean
+ * <p>
+ * The validation includes:
+ * <ul>
+ * <li>Signature</li>
+ * <li>HW data</li>
+ * <li>Logo CRC</li>
+ * </ul>
+ * </p>
+ *
+ * @param licFile
+ * @return The license bean stored in file
+ * @throws SeCurisException
+ */
+ public LicenseBean validateLicense(File licFile) throws SeCurisException {
- return validateLicense(licFile, false);
- }
+ return validateLicense(licFile, false);
+ }
- /**
- * Validates the license stored in {@code licFile} and get the corresponding
- * LicenseBean. The License date is not validated
- * <p>
- * The validation includes:
- * <ul>
- * <li>Signature</li>
- * <li>HW data</li>
- * <li>Logo CRC</li>
- * </ul>
- * </p>
- *
- * @param licFile
- * @return The license bean stored in file
- * @throws SeCurisException
- */
- public LicenseBean validateLicense(File licFile, boolean excludeDateValidation) throws SeCurisException {
- LicenseBean licBean = load(licFile);
- SignatureHelper.getInstance().validateSignature(licBean);
- if (licBean.getActivationCode() != null) {
- LicenseValidator.getInstance().validateHW(licBean, Params.get(Params.KEYS.APPLICATION_CODE), licBean.getActivationCode());
- } else {
- 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));
- }
- LicenseValidator.getInstance().validateLogo(licBean);
+ /**
+ * Validates the license stored in {@code licFile} and get the corresponding
+ * LicenseBean. The License date is not validated
+ * <p>
+ * The validation includes:
+ * <ul>
+ * <li>Signature</li>
+ * <li>HW data</li>
+ * <li>Logo CRC</li>
+ * </ul>
+ * </p>
+ *
+ * @param licFile
+ * @return The license bean stored in file
+ * @throws SeCurisException
+ */
+ public LicenseBean validateLicense(File licFile, boolean excludeDateValidation) throws SeCurisException {
+ LicenseBean licBean = load(licFile);
+ SignatureHelper.getInstance().validateSignature(licBean);
+ if (licBean.getActivationCode() != null) {
+ LicenseValidator.getInstance().validateHW(licBean, Params.get(Params.KEYS.APPLICATION_CODE), licBean.getActivationCode());
+ } else {
+ 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));
+ }
+ LicenseValidator.getInstance().validateLogo(licBean);
- if (!excludeDateValidation) {
- if (new Date().after(licBean.getExpirationDate())) {
- throw new ExpiredLicenseException();
- }
- }
+ if (!excludeDateValidation) {
+ if (new Date().after(licBean.getExpirationDate())) {
+ throw new ExpiredLicenseException();
+ }
+ }
- return licBean;
- }
+ return licBean;
+ }
- /**
- * Request to server for a valid license
- *
- * @return The license bean returned by the server
- * @throws SeCurisException
- */
- public SignedLicenseBean requestLicense(String nameOrReference, String email) throws SeCurisException {
- 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));
+ /**
+ * Request to server for a valid license
+ *
+ * @return The license bean returned by the server
+ * @throws SeCurisException
+ */
+ public SignedLicenseBean requestLicense(String nameOrReference, String email) throws SeCurisException {
+ 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));
- SignedLicenseBean lic = requestLicenseToServer(req, nameOrReference, email);
- return lic;
- }
+ SignedLicenseBean lic = requestLicenseToServer(req, nameOrReference, email);
+ return lic;
+ }
- /**
- * Request to server for a valid license
- *
- * @return The license bean returned by the server
- * @throws SeCurisException
- */
- public SignedLicenseBean requestLicense(String nameOrReference, String email, String activationCode) throws SeCurisException {
- RequestBean req = ReqGenerator.getInstance().createRequest(Params.get(Params.KEYS.APPLICATION_CODE), activationCode);
+ /**
+ * Request to server for a valid license
+ *
+ * @return The license bean returned by the server
+ * @throws SeCurisException
+ */
+ public SignedLicenseBean requestLicense(String nameOrReference, String email, String activationCode) throws SeCurisException {
+ RequestBean req = ReqGenerator.getInstance().createRequest(Params.get(Params.KEYS.APPLICATION_CODE), activationCode);
- SignedLicenseBean lic = requestLicenseToServer(req, nameOrReference, email);
- return lic;
- }
+ SignedLicenseBean lic = requestLicenseToServer(req, nameOrReference, email);
+ return lic;
+ }
- /**
- * Generate a license file using a {@link LicenseBean}
- *
- * @param license
- * @param file
- * @throws SeCurisException
- */
- public void save(LicenseBean license, File file) throws SeCurisException {
- SignedLicenseBean signedLic = new SignedLicenseBean(license);
- save(signedLic, file);
- }
+ /**
+ * Request to server for a valid license
+ *
+ * @return The license bean returned by the server
+ * @throws SeCurisException
+ */
+ public SignedLicenseBean requestLicense(String activationCode) throws SeCurisException {
+ return requestLicense(null, null, activationCode);
+ }
- /**
- * Generate a license file using a {@link LicenseBean}
- *
- * @param license
- * @param file
- * @throws SeCurisException
- */
- public void save(SignedLicenseBean signedLic, File file) throws SeCurisException {
- byte[] json;
- try {
- json = JsonUtils.toPrettyJSON(signedLic).getBytes("utf-8");
- Files.write(Paths.get(file.toURI()), json, StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING);
- } catch (UnsupportedEncodingException e) {
- LOG.error("Error creating json doc from license: " + signedLic, e);
- throw new SeCurisException("Error creating json doc from license: " + signedLic, e);
- } catch (IOException e) {
- LOG.error("Error creating license file: " + file, e);
- throw new SeCurisException("Error creating json doc from license: " + signedLic, e);
- }
+ /**
+ * Generate a license file using a {@link LicenseBean}
+ *
+ * @param license
+ * @param file
+ * @throws SeCurisException
+ */
+ public void save(LicenseBean license, File file) throws SeCurisException {
+ SignedLicenseBean signedLic = new SignedLicenseBean(license);
+ save(signedLic, file);
+ }
- LOG.debug("License saved in {}", file);
+ /**
+ * Generate a license file using a {@link LicenseBean}
+ *
+ * @param license
+ * @param file
+ * @throws SeCurisException
+ */
+ public void save(SignedLicenseBean signedLic, File file) throws SeCurisException {
+ byte[] json;
+ try {
+ json = JsonUtils.toPrettyJSON(signedLic).getBytes("utf-8");
+ Files.write(Paths.get(file.toURI()), json, StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING);
+ } catch (UnsupportedEncodingException e) {
+ LOG.error("Error creating json doc from license: " + signedLic, e);
+ throw new SeCurisException("Error creating json doc from license: " + signedLic, e);
+ } catch (IOException e) {
+ LOG.error("Error creating license file: " + file, e);
+ throw new SeCurisException("Error creating json doc from license: " + signedLic, e);
+ }
- }
+ LOG.debug("License saved in {}", file);
- private SignedLicenseBean requestLicenseToServer(RequestBean req, String nameOrReference, String email) throws SeCurisException {
- Map<String, String> headers = new HashMap<String, String>();
- headers.put(HEADER_LICENSE_NAME_OR_REFERENCE, nameOrReference);
- headers.put(HEADER_LICENSE_EMAIL, email);
- SignedLicenseBean lic = ConnectionManager.getInstance().executePost(Command.CREATE_LIC, SignedLicenseBean.class, req, headers);
+ }
- return lic;
- }
+ private SignedLicenseBean requestLicenseToServer(RequestBean req, String nameOrReference, String email) throws SeCurisException {
+ Map<String, String> headers = new HashMap<String, String>();
+ headers.put(HEADER_LICENSE_NAME_OR_REFERENCE, nameOrReference);
+ headers.put(HEADER_LICENSE_EMAIL, email);
+ SignedLicenseBean lic = ConnectionManager.getInstance().executePost(Command.CREATE_LIC, SignedLicenseBean.class, req, headers);
- /**
- * Creates a new request file with current hardware in the File passed as
- * parameter
- *
- * @param outputRequestFile
- * File where the request data will be saved
- * @return The generated request bean
- * @throws SeCurisException
- */
- public RequestBean createRequestFile(File outputRequestFile) throws SeCurisException {
- 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));
+ return lic;
+ }
- ReqGenerator.getInstance().save(req, outputRequestFile);
+ /**
+ * Creates a new request file with current hardware in the File passed as
+ * parameter
+ *
+ * @param outputRequestFile
+ * File where the request data will be saved
+ * @return The generated request bean
+ * @throws SeCurisException
+ */
+ public RequestBean createRequestFile(File outputRequestFile) throws SeCurisException {
+ 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));
- return req;
- }
+ ReqGenerator.getInstance().save(req, outputRequestFile);
- /**
- * Creates a new request file with current hardware in the File passed as
- * parameter
- *
- * @param outputRequestFile
- * File where the request data will be saved
- * @return The generated request bean
- * @throws SeCurisException
- */
- public RequestBean createRequestFile(File outputRequestFile, String activationCode) throws SeCurisException {
- RequestBean req = ReqGenerator.getInstance().createRequest(Params.get(Params.KEYS.APPLICATION_CODE), activationCode);
+ return req;
+ }
- ReqGenerator.getInstance().save(req, outputRequestFile);
+ /**
+ * Creates a new request file with current hardware in the File passed as
+ * parameter
+ *
+ * @param outputRequestFile
+ * File where the request data will be saved
+ * @return The generated request bean
+ * @throws SeCurisException
+ */
+ public RequestBean createRequestFile(File outputRequestFile, String activationCode) throws SeCurisException {
+ RequestBean req = ReqGenerator.getInstance().createRequest(Params.get(Params.KEYS.APPLICATION_CODE), activationCode);
- return req;
- }
+ ReqGenerator.getInstance().save(req, outputRequestFile);
- /**
- * Send the current license file to server, which is previously validated,
- * to get a renewed one if it is prepared in server side.
- *
- * @param licenseFile
- * Current and valid License file
- * @return New license bean if server creates a new one, otherwise the same
- * current License bean will be returned
- * @throws SeCurisException
- */
- public SignedLicenseBean renew(File licenseFile) throws SeCurisException {
- LicenseBean lic = validateLicense(licenseFile, true);
+ return req;
+ }
- SignedLicenseBean newLic = ConnectionManager.getInstance().executePost(Command.RENEW_LIC, SignedLicenseBean.class, lic);
+ /**
+ * Send the current license file to server, which is previously validated,
+ * to get a renewed one if it is prepared in server side.
+ *
+ * @param licenseFile
+ * Current and valid License file
+ * @return New license bean if server creates a new one, otherwise the same
+ * current License bean will be returned
+ * @throws SeCurisException
+ */
+ public SignedLicenseBean renew(File licenseFile) throws SeCurisException {
+ LicenseBean lic = validateLicense(licenseFile, true);
- return newLic;
- }
+ SignedLicenseBean newLic = ConnectionManager.getInstance().executePost(Command.RENEW_LIC, SignedLicenseBean.class, lic);
- /**
- * Check on SeCuris server if current license is still valid in server DB.
- *
- * @param licenseFile
- * @throws SeCurisException
- */
- public void assertLicenseIsValid(File licenseFile) throws SeCurisException, IOException {
- LicenseBean lic = validateLicense(licenseFile);
- // We need to snd the signed version to validate signature on server
- ConnectionManager.getInstance().executePost(Command.VALIDATE, LicenseBean.class, new SignedLicenseBean(lic));
- }
+ return newLic;
+ }
- public void testServer() throws SeCurisException {
- StatusBean status = ConnectionManager.getInstance().executeGet(Command.TEST, StatusBean.class);
- if (!PING_MESSAGE.equals(status.getMessage())) {
- throw new SeCurisException("SeCuris Server is not running in given URL");
- }
- }
+ /**
+ * Check on SeCuris server if current license is still valid in server DB.
+ *
+ * @param licenseFile
+ * @throws SeCurisException
+ */
+ public void assertLicenseIsValid(File licenseFile) throws SeCurisException, IOException {
+ LicenseBean lic = validateLicense(licenseFile);
+ // We need to snd the signed version to validate signature on server
+ ConnectionManager.getInstance().executePost(Command.VALIDATE, LicenseBean.class, new SignedLicenseBean(lic));
+ }
+ public void testServer() throws SeCurisException {
+ StatusBean status = ConnectionManager.getInstance().executeGet(Command.TEST, StatusBean.class);
+ if (!PING_MESSAGE.equals(status.getMessage())) {
+ throw new SeCurisException("SeCuris Server is not running in given URL");
+ }
+ }
+
+ public static void main(String[] args) throws SeCurisException {
+ System.out.println("APPLICATION_CODE: " + Params.get(Params.KEYS.APPLICATION_CODE));
+ System.out.println("LICENSE_SERVER_URL: " + Params.get(Params.KEYS.LICENSE_SERVER_URL));
+ LicenseManager lm = LicenseManager.getInstance();
+ // LicenseBean lic =
+ // lm.requestLicense("aaf88d6c-6622-492a-93ec-10f3d1dc7120");
+ LicenseBean lic = lm.requestLicense("Rob", "rsanchez@curisit.net");
+ System.out.println(lic.getLicenseCode() + " " + lic.getExpirationDate());
+ // LicenseBean lic = lm.
+ }
}
diff --git a/src/main/java/net/curisit/securis/beans/LicenseBean.java b/src/main/java/net/curisit/securis/beans/LicenseBean.java
index 406e7aa..4e7d122 100644
--- a/src/main/java/net/curisit/securis/beans/LicenseBean.java
+++ b/src/main/java/net/curisit/securis/beans/LicenseBean.java
@@ -29,6 +29,8 @@
}
public LicenseBean(RequestBean req) {
+ super.setAppCode(req.getAppCode());
+ super.setActivationCode(req.getActivationCode());
super.setPackCode(req.getPackCode());
super.setLicenseTypeCode(req.getLicenseTypeCode());
super.setCustomerCode(req.getCustomerCode());
--
Gitblit v1.3.2