Skip to content

Commit 7b1b8da

Browse files
committed
Adding doc for the new API introduced by elastic#64517 - /_security/saml/metadata/{realm}
Related to elastic#49018
1 parent 1002999 commit 7b1b8da

File tree

1 file changed

+19
-4
lines changed

1 file changed

+19
-4
lines changed

x-pack/plugin/core/src/main/java/org/elasticsearch/license/XPackLicenseState.java

+19-4
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,7 @@ private static boolean isBasic(OperationMode mode) {
395395
return mode == OperationMode.BASIC;
396396
}
397397

398-
/** A wrapper for the license mode and state, to allow atomically swapping. */
398+
/** A wrapper for the license mode, state, and expiration date, to allow atomically swapping. */
399399
private static class Status {
400400

401401
/** The current "mode" of the license (ie license type). */
@@ -404,7 +404,7 @@ private static class Status {
404404
/** True if the license is active, or false if it is expired. */
405405
final boolean active;
406406

407-
/** The current expiration date of the license; Long.MAX_VALUE if not avILble yet. */
407+
/** The current expiration date of the license; Long.MAX_VALUE if not available yet. */
408408
final long licenseExpiryDate;
409409

410410
Status(OperationMode mode, boolean active, long licenseExpiryDate) {
@@ -522,8 +522,7 @@ public boolean checkFeature(Feature feature) {
522522
maxEpochAccumulator.accumulate(epochMillisProvider.getAsLong());
523523
}
524524

525-
if(feature.minimumOperationMode.compareTo(OperationMode.BASIC) > 0
526-
&& now > status.licenseExpiryDate - GRACE_PERIOD_DURATION.getMillis()) {
525+
if (feature.minimumOperationMode.compareTo(OperationMode.BASIC) > 0 && isLicenseExpiring(now)) {
527526
HeaderWarning.addWarning("Your license will expire in [{}] days. " +
528527
"Contact your administrator or update your license for continued use of features",
529528
TimeUnit.MILLISECONDS.toDays(status.licenseExpiryDate - now));
@@ -645,6 +644,22 @@ public boolean isAllowedByLicense(OperationMode minimumMode, boolean needActive)
645644
});
646645
}
647646

647+
/**
648+
* Test whether current license expires in less than {@code GRACE_PERIOD_DURATION}.
649+
*
650+
* @param now Current time in milliseconds
651+
*
652+
* @return true if current license expires in less than {@code GRACE_PERIOD_DURATION}, otherwise false
653+
*/
654+
public boolean isLicenseExpiring(long now) {
655+
return checkAgainstStatus(status -> {
656+
if (now > status.licenseExpiryDate - GRACE_PERIOD_DURATION.getMillis()) {
657+
return true;
658+
}
659+
return false;
660+
});
661+
}
662+
648663
/**
649664
* A convenient method to test whether a feature is by license status.
650665
* @see #isAllowedByLicense(OperationMode, boolean)

0 commit comments

Comments
 (0)