Skip to content

Commit ac87334

Browse files
authored
Merge pull request #27 from cryptlex/feat-entitlement-develop
Feat entitlement develop
2 parents fdfba7e + e161bcb commit ac87334

4 files changed

Lines changed: 234 additions & 30 deletions

File tree

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package com.cryptlex.lexfloatclient;
2+
3+
public class HostFeatureEntitlement {
4+
/**
5+
* The name of the feature.
6+
*/
7+
public String featureName;
8+
9+
/**
10+
* The display name of the feature.
11+
*/
12+
public String featureDisplayName;
13+
14+
/**
15+
* The value of the feature.
16+
*/
17+
public String value;
18+
}

src/main/java/com/cryptlex/lexfloatclient/LexFloatClient.java

Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import java.math.BigInteger;
1111
import com.fasterxml.jackson.databind.ObjectMapper;
1212
import com.fasterxml.jackson.core.JsonProcessingException;
13+
import com.fasterxml.jackson.core.type.TypeReference;
1314
import java.util.ArrayList;
1415
import java.util.List;
1516

@@ -237,6 +238,8 @@ public static HostConfig GetHostConfig() throws LexFloatClientException, Unsuppo
237238
/**
238239
* Gets the product version name.
239240
*
241+
* @deprecated This function is deprecated. Use GetHostLicenseEntitlementSetName() instead.
242+
*
240243
* @return name - Returns the name of the Product Version being used.
241244
* @throws LexFloatClientException
242245
* @throws UnsupportedEncodingException
@@ -262,6 +265,8 @@ public static String GetHostProductVersionName() throws LexFloatClientException,
262265
/**
263266
* Gets the product version display name.
264267
*
268+
* @deprecated This function is deprecated. Use GetHostLicenseEntitlementSetDisplayName() instead.
269+
*
265270
* @return displayName - Returns the display name of the Product Version being
266271
* used.
267272
* @throws LexFloatClientException
@@ -288,6 +293,8 @@ public static String GetHostProductVersionDisplayName() throws LexFloatClientExc
288293
/**
289294
* Gets the product version feature flag.
290295
*
296+
* @deprecated This function is deprecated. Use GetHostFeatureEntitlement() instead.
297+
*
291298
* @param name - The name of the Feature Flag.
292299
* @return The properties of the Feature Flag as an object.
293300
* @throws LexFloatClientException
@@ -315,6 +322,147 @@ public static HostProductVersionFeatureFlag GetHostProductVersionFeatureFlag(Str
315322
throw new LexFloatClientException(status);
316323
}
317324

325+
/**
326+
* Gets the name of the entitlement set associated with the LexFloatServer license.
327+
*
328+
* @return Returns the host license entitlement set name.
329+
* @throws LexFloatClientException
330+
* @throws UnsupportedEncodingException
331+
*/
332+
public static String GetHostLicenseEntitlementSetName() throws LexFloatClientException, UnsupportedEncodingException {
333+
int status;
334+
int bufferSize = 256;
335+
if (Platform.isWindows()) {
336+
CharBuffer buffer = CharBuffer.allocate(bufferSize);
337+
status = LexFloatClientNative.GetHostLicenseEntitlementSetName(buffer, bufferSize);
338+
if (LF_OK == status) {
339+
return buffer.toString().trim();
340+
}
341+
} else {
342+
ByteBuffer buffer = ByteBuffer.allocate(bufferSize);
343+
status = LexFloatClientNative.GetHostLicenseEntitlementSetName(buffer, bufferSize);
344+
if (LF_OK == status) {
345+
return new String(buffer.array(), "UTF-8").trim();
346+
}
347+
}
348+
throw new LexFloatClientException(status);
349+
}
350+
351+
/**
352+
* Gets the display name of the entitlement set associated with the LexFloatServer license.
353+
*
354+
* @return Returns the host license entitlement set display name.
355+
* @throws LexFloatClientException
356+
* @throws UnsupportedEncodingException
357+
*/
358+
public static String GetHostLicenseEntitlementSetDisplayName() throws LexFloatClientException, UnsupportedEncodingException {
359+
int status;
360+
int bufferSize = 256;
361+
if (Platform.isWindows()) {
362+
CharBuffer buffer = CharBuffer.allocate(bufferSize);
363+
status = LexFloatClientNative.GetHostLicenseEntitlementSetDisplayName(buffer, bufferSize);
364+
if (LF_OK == status) {
365+
return buffer.toString().trim();
366+
}
367+
} else {
368+
ByteBuffer buffer = ByteBuffer.allocate(bufferSize);
369+
status = LexFloatClientNative.GetHostLicenseEntitlementSetDisplayName(buffer, bufferSize);
370+
if (LF_OK == status) {
371+
return new String(buffer.array(), "UTF-8").trim();
372+
}
373+
}
374+
throw new LexFloatClientException(status);
375+
}
376+
377+
/**
378+
* Gets the feature entitlements associated with the LexFloatServer license.
379+
*
380+
* Feature entitlements can be linked directly to a license (license feature entitlements)
381+
* or via entitlement sets. If a feature entitlement is defined in both, the value from
382+
* the license feature entitlement takes precedence, overriding the entitlement set value.
383+
*
384+
* @return Returns a list of host feature entitlements.
385+
* @throws LexFloatClientException
386+
* @throws UnsupportedEncodingException
387+
*/
388+
public static List<HostFeatureEntitlement> GetHostFeatureEntitlements() throws LexFloatClientException, UnsupportedEncodingException {
389+
int status;
390+
int bufferSize = 4096;
391+
if (Platform.isWindows()) {
392+
CharBuffer buffer = CharBuffer.allocate(bufferSize);
393+
status = LexFloatClientNative.GetHostFeatureEntitlementsInternal(buffer, bufferSize);
394+
if (LF_OK == status) {
395+
String hostFeatureEntitlementsJson = buffer.toString().trim();
396+
if (!hostFeatureEntitlementsJson.isEmpty()) {
397+
ObjectMapper objectMapper = new ObjectMapper();
398+
try {
399+
List<HostFeatureEntitlement> hostFeatureEntitlements = objectMapper.readValue(hostFeatureEntitlementsJson, new TypeReference<List<HostFeatureEntitlement>>() {});
400+
return hostFeatureEntitlements;
401+
} catch (JsonProcessingException e) {}
402+
} else {
403+
return new ArrayList<>();
404+
}
405+
}
406+
} else {
407+
ByteBuffer buffer = ByteBuffer.allocate(bufferSize);
408+
status = LexFloatClientNative.GetHostFeatureEntitlementsInternal(buffer, bufferSize);
409+
if (LF_OK == status) {
410+
String hostFeatureEntitlementsJson = new String(buffer.array(), "UTF-8").trim();
411+
if (!hostFeatureEntitlementsJson.isEmpty()) {
412+
ObjectMapper objectMapper = new ObjectMapper();
413+
try {
414+
List<HostFeatureEntitlement> hostFeatureEntitlements = objectMapper.readValue(hostFeatureEntitlementsJson, new TypeReference<List<HostFeatureEntitlement>>() {});
415+
return hostFeatureEntitlements;
416+
} catch (JsonProcessingException e) {}
417+
} else {
418+
return new ArrayList<>();
419+
}
420+
}
421+
}
422+
throw new LexFloatClientException(status);
423+
}
424+
425+
/**
426+
* Gets the feature entitlement associated with the LexFloatServer license.
427+
*
428+
* Feature entitlements can be linked directly to a license (license feature entitlements)
429+
* or via entitlement sets. If a feature entitlement is defined in both, the value from
430+
* the license feature entitlement takes precedence, overriding the entitlement set value.
431+
*
432+
* @param name The name of the feature.
433+
* @return Returns the host feature entitlement object.
434+
* @throws LexFloatClientException
435+
* @throws UnsupportedEncodingException
436+
*/
437+
public static HostFeatureEntitlement GetHostFeatureEntitlement(String name) throws LexFloatClientException, UnsupportedEncodingException {
438+
int status;
439+
int bufferSize = 1024;
440+
if (Platform.isWindows()) {
441+
CharBuffer buffer = CharBuffer.allocate(bufferSize);
442+
status = LexFloatClientNative.GetHostFeatureEntitlementInternal(new WString(name), buffer, bufferSize);
443+
if (LF_OK == status) {
444+
String hostFeatureEntitlementJson = buffer.toString().trim();
445+
ObjectMapper objectMapper = new ObjectMapper();
446+
try {
447+
HostFeatureEntitlement hostFeatureEntitlement = objectMapper.readValue(hostFeatureEntitlementJson, HostFeatureEntitlement.class);
448+
return hostFeatureEntitlement;
449+
} catch (JsonProcessingException e) {}
450+
}
451+
} else {
452+
ByteBuffer buffer = ByteBuffer.allocate(bufferSize);
453+
status = LexFloatClientNative.GetHostFeatureEntitlementInternal(name, buffer, bufferSize);
454+
if (LF_OK == status) {
455+
String hostFeatureEntitlementJson = new String(buffer.array(), "UTF-8").trim();
456+
ObjectMapper objectMapper = new ObjectMapper();
457+
try {
458+
HostFeatureEntitlement hostFeatureEntitlement = objectMapper.readValue(hostFeatureEntitlementJson, HostFeatureEntitlement.class);
459+
return hostFeatureEntitlement;
460+
} catch (JsonProcessingException e) {}
461+
}
462+
}
463+
throw new LexFloatClientException(status);
464+
}
465+
318466
/**
319467
* Get the value of the license metadata field associated with the
320468
* LexFloatServer license key

src/main/java/com/cryptlex/lexfloatclient/LexFloatClientException.java

Lines changed: 52 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,12 @@ public static String getErrorMessage(int errorCode) {
101101
case LF_E_MACHINE_FINGERPRINT:
102102
message = "Machine fingerprint has changed since activation.";
103103
break;
104+
case LF_E_ENTITLEMENT_SET_NOT_LINKED:
105+
message = "No entitlement set is linked to the license.";
106+
break;
107+
case LF_E_FEATURE_ENTITLEMENT_NOT_FOUND:
108+
message = "The feature entitlement does not exist.";
109+
break;
104110
case LF_E_CLIENT:
105111
message = "Client error.";
106112
break;
@@ -280,8 +286,10 @@ public static String getErrorMessage(int errorCode) {
280286
public static final int LF_E_FEATURE_FLAG_NOT_FOUND = 58;
281287

282288
/*
283-
* Insufficient system permissions.
284-
*/
289+
* CODE: LF_E_SYSTEM_PERMISSION
290+
*
291+
* MESSAGE: Insufficient system permissions.
292+
*/
285293
public static final int LF_E_SYSTEM_PERMISSION = 59;
286294

287295
/*
@@ -292,53 +300,67 @@ public static String getErrorMessage(int errorCode) {
292300
public static final int LF_E_IP = 60;
293301

294302
/*
295-
* CODE: LF_E_INVALID_PERMISSION_FLAG
296-
*
297-
* MESSAGE: Invalid permission flag.
298-
*/
303+
* CODE: LF_E_INVALID_PERMISSION_FLAG
304+
*
305+
* MESSAGE: Invalid permission flag.
306+
*/
299307
public static final int LF_E_INVALID_PERMISSION_FLAG = 61;
300308

301309
/*
302-
* CODE: LF_E_OFFLINE_FLOATING_LICENSE_NOT_ALLOWED
303-
*
304-
* MESSAGE: Offline floating license is not allowed for per-instance leasing strategy.
305-
*/
310+
* CODE: LF_E_OFFLINE_FLOATING_LICENSE_NOT_ALLOWED
311+
*
312+
* MESSAGE: Offline floating license is not allowed for per-instance leasing strategy.
313+
*/
306314
public static final int LF_E_OFFLINE_FLOATING_LICENSE_NOT_ALLOWED = 62;
307315

308316
/*
309-
* CODE: LF_E_MAX_OFFLINE_LEASE_DURATION_EXCEEDED
310-
*
311-
* MESSAGE: Maximum offline lease duration exceeded.
312-
*/
317+
* CODE: LF_E_MAX_OFFLINE_LEASE_DURATION_EXCEEDED
318+
*
319+
* MESSAGE: Maximum offline lease duration exceeded.
320+
*/
313321
public static final int LF_E_MAX_OFFLINE_LEASE_DURATION_EXCEEDED = 63;
314322

315323
/*
316-
* CODE: LF_E_ALLOWED_OFFLINE_FLOATING_CLIENTS_LIMIT_REACHED
317-
*
318-
* MESSAGE: Allowed offline floating clients limit reached.
319-
*/
324+
* CODE: LF_E_ALLOWED_OFFLINE_FLOATING_CLIENTS_LIMIT_REACHED
325+
*
326+
* MESSAGE: Allowed offline floating clients limit reached.
327+
*/
320328
public static final int LF_E_ALLOWED_OFFLINE_FLOATING_CLIENTS_LIMIT_REACHED = 64;
321329

322330
/*
323-
* CODE: LF_E_WMIC
324-
*
325-
* MESSAGE: Fingerprint couldn't be generated because Windows Management Instrumentation (WMI) service has been disabled.
326-
*/
331+
* CODE: LF_E_WMIC
332+
*
333+
* MESSAGE: Fingerprint couldn't be generated because Windows Management Instrumentation (WMI) service has been disabled.
334+
*/
327335
public static final int LF_E_WMIC = 65;
328336

329337
/*
330-
* CODE: LF_E_MACHINE_FINGERPRINT
331-
*
332-
* MESSAGE: Machine fingerprint has changed since activation.
333-
*/
338+
* CODE: LF_E_MACHINE_FINGERPRINT
339+
*
340+
* MESSAGE: Machine fingerprint has changed since activation.
341+
*/
334342
public static final int LF_E_MACHINE_FINGERPRINT = 66;
335343
/*
336-
* CODE: LF_E_PROXY_NOT_TRUSTED
337-
*
338-
* MESSAGE: Request blocked due to untrusted proxy.
339-
*/
344+
* CODE: LF_E_PROXY_NOT_TRUSTED
345+
*
346+
* MESSAGE: Request blocked due to untrusted proxy.
347+
*/
340348
public static final int LF_E_PROXY_NOT_TRUSTED = 67;
341349

350+
/*
351+
* CODE: LF_E_ENTITLEMENT_SET_NOT_LINKED
352+
*
353+
* MESSAGE: No entitlement set is linked to the license.
354+
*/
355+
public static final int LF_E_ENTITLEMENT_SET_NOT_LINKED = 68;
356+
357+
/*
358+
* CODE: LF_E_FEATURE_ENTITLEMENT_NOT_FOUND
359+
*
360+
* MESSAGE: The feature entitlement does not exist.
361+
*/
362+
public static final int LF_E_FEATURE_ENTITLEMENT_NOT_FOUND = 69;
363+
342364
/*
343365
* CODE: LF_E_CLIENT
344366
*

src/main/java/com/cryptlex/lexfloatclient/LexFloatClientNative.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,22 @@ public interface CallbackType extends Callback {
6363

6464
public static native int GetHostProductVersionFeatureFlag(WString name, IntByReference enabled, CharBuffer data, int length);
6565

66+
public static native int GetHostLicenseEntitlementSetName(ByteBuffer name, int length);
67+
68+
public static native int GetHostLicenseEntitlementSetName(CharBuffer name, int length);
69+
70+
public static native int GetHostLicenseEntitlementSetDisplayName(ByteBuffer displayName, int length);
71+
72+
public static native int GetHostLicenseEntitlementSetDisplayName(CharBuffer displayName, int length);
73+
74+
public static native int GetHostFeatureEntitlementsInternal(ByteBuffer featureEntitlementsJson, int length);
75+
76+
public static native int GetHostFeatureEntitlementsInternal(CharBuffer featureEntitlementsJson, int length);
77+
78+
public static native int GetHostFeatureEntitlementInternal(String featureName, ByteBuffer featureEntitlementJson, int length);
79+
80+
public static native int GetHostFeatureEntitlementInternal(WString featureName, CharBuffer featureEntitlementJson, int length);
81+
6682
public static native int GetHostLicenseMetadata(String key, ByteBuffer value, int length);
6783

6884
public static native int GetHostLicenseMetadata(WString key, CharBuffer value, int length);

0 commit comments

Comments
 (0)