Skip to content

Commit b449bc7

Browse files
committed
Update port-hash
License scheduled check for kernel DEVSIX-3475 Autoported commit. Original commit hash: [b2f0fa8cf] Manual files: kernel/src/main/java/com/itextpdf/kernel/Version.java
1 parent fc5afaf commit b449bc7

File tree

2 files changed

+47
-9
lines changed

2 files changed

+47
-9
lines changed

itext/itext.kernel/itext/kernel/Version.cs

Lines changed: 46 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,16 @@ private Version(VersionInfo info, bool expired) {
118118
public static iText.Kernel.Version GetInstance() {
119119
lock (staticLock) {
120120
if (version != null) {
121+
try {
122+
LicenseScheduledCheck();
123+
}
124+
catch (Exception e) {
125+
// If any exception occurs during scheduled check of core license,
126+
// then it means that license is not valid yet, so roll back to AGPL.
127+
// The key value is null as it is similar to case
128+
// when an exception has been thrown during initial license loading
129+
AtomicSetVersion(InitAGPLVersion(e, null));
130+
}
121131
return version;
122132
}
123133
}
@@ -195,7 +205,7 @@ public static iText.Kernel.Version GetInstance() {
195205
/// <summary>Checks if the AGPL version is used.</summary>
196206
/// <returns>returns true if the AGPL version is used.</returns>
197207
public static bool IsAGPLVersion() {
198-
return GetInstance().GetVersion().IndexOf(AGPL, StringComparison.Ordinal) > 0;
208+
return GetInstance().IsAGPL();
199209
}
200210

201211
/// <summary>Is the license expired?</summary>
@@ -250,6 +260,12 @@ public VersionInfo GetInfo() {
250260
return info;
251261
}
252262

263+
/// <summary>Checks if the current object has been initialized with AGPL license.</summary>
264+
/// <returns>returns true if the current object has been initialized with AGPL license.</returns>
265+
private bool IsAGPL() {
266+
return GetVersion().IndexOf(AGPL, StringComparison.Ordinal) > 0;
267+
}
268+
253269
private static iText.Kernel.Version InitDefaultLicensedVersion(String ownerName, String key) {
254270
String producer = producerLine + " (" + ownerName;
255271
if (!key.ToLowerInvariant().StartsWith("trial")) {
@@ -271,6 +287,11 @@ private static iText.Kernel.Version InitVersion(String producer, String key, boo
271287
return new iText.Kernel.Version(new VersionInfo(iTextProductName, release, producer, key), expired);
272288
}
273289

290+
private static Type GetLicenseKeyClass() {
291+
String licenseKeyClassFullName = "iText.License.LicenseKey, itext.licensekey";
292+
return GetClassFromLicenseKey(licenseKeyClassFullName);
293+
}
294+
274295
private static void CheckLicenseVersion(String coreVersionString, String licenseVersionString) {
275296
String[] coreVersions = ParseVersionString(coreVersionString);
276297
String[] licenseVersions = ParseVersionString(licenseVersionString);
@@ -364,31 +385,48 @@ private static iText.Kernel.Version AtomicSetVersion(iText.Kernel.Version newVer
364385
}
365386
}
366387

367-
private static Type GetLicenseKeyClass() {
368-
String licenseKeyClassPartialName = "iText.License.LicenseKey, itext.licensekey";
369-
String licenseKeyClassFullName = null;
388+
private static void LicenseScheduledCheck() {
389+
if (version.IsAGPL()) {
390+
return;
391+
}
392+
String licenseKeyProductFullName = "iText.License.LicenseKeyProduct, itext.licensekey";
393+
String checkLicenseKeyMethodName = "ScheduledCheck";
394+
try {
395+
Type licenseKeyClass = GetLicenseKeyClass();
396+
Type licenseKeyProductClass = GetClassFromLicenseKey(licenseKeyProductFullName);
397+
Type[] cArg = new Type[] { licenseKeyProductClass };
398+
MethodInfo method = licenseKeyClass.GetMethod(checkLicenseKeyMethodName, cArg);
399+
method.Invoke(null, new Object[] { null });
400+
}
401+
catch (Exception e) {
402+
throw new Exception(e.Message, e);
403+
}
404+
}
405+
406+
private static Type GetClassFromLicenseKey(String classPartialName) {
407+
String classFullName = null;
370408

371409
Assembly kernelAssembly = typeof(Version).GetAssembly();
372410
Attribute keyVersionAttr = kernelAssembly.GetCustomAttribute(typeof(KeyVersionAttribute));
373411
if (keyVersionAttr is KeyVersionAttribute) {
374412
String keyVersion = ((KeyVersionAttribute)keyVersionAttr).KeyVersion;
375413
String format = "{0}, Version={1}, Culture=neutral, PublicKeyToken=8354ae6d2174ddca";
376-
licenseKeyClassFullName = String.Format(format, licenseKeyClassPartialName, keyVersion);
414+
classFullName = String.Format(format, classPartialName, keyVersion);
377415
}
378416

379417
Type type = null;
380-
if (licenseKeyClassFullName != null) {
418+
if (classFullName != null) {
381419
String fileLoadExceptionMessage = null;
382420
try {
383-
type = System.Type.GetType(licenseKeyClassFullName);
421+
type = System.Type.GetType(classFullName);
384422
} catch (FileLoadException fileLoadException) {
385423
fileLoadExceptionMessage = fileLoadException.Message;
386424
}
387425

388426
if (type == null) {
389427
ILog logger = LogManager.GetLogger(typeof(Version));
390428
try {
391-
type = System.Type.GetType(licenseKeyClassPartialName);
429+
type = System.Type.GetType(classPartialName);
392430
} catch {
393431
// ignore
394432
}

port-hash

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
10bd1a9f392d7fa895850dc10aca0ae551c6c797
1+
b2f0fa8cf62a2b78d80d394e9323efa8be52535d

0 commit comments

Comments
 (0)