Skip to content

Commit 1002999

Browse files
committed
This change adds realm name of the realm used to perform authentication to the responses of _security/oidc/authenticate and _security/oidc/authenticate APIs
Resolves elastic#53161
1 parent e52f231 commit 1002999

File tree

14 files changed

+71
-70
lines changed

14 files changed

+71
-70
lines changed

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

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -350,10 +350,6 @@ public License getLicense() {
350350
return license == LicensesMetadata.LICENSE_TOMBSTONE ? null : license;
351351
}
352352

353-
public Lifecycle.State getLifecycleState() {
354-
return clusterService.lifecycleState();
355-
}
356-
357353
private LicensesMetadata getLicensesMetadata() {
358354
return this.clusterService.state().metadata().custom(LicensesMetadata.TYPE);
359355
}
@@ -479,7 +475,7 @@ private void updateLicenseState(LicensesMetadata licensesMetadata) {
479475
protected void updateLicenseState(final License license, Version mostRecentTrialVersion) {
480476
if (license == LicensesMetadata.LICENSE_TOMBSTONE) {
481477
// implies license has been explicitly deleted
482-
licenseState.update(License.OperationMode.MISSING, false, mostRecentTrialVersion);
478+
licenseState.update(License.OperationMode.MISSING, false, license.expiryDate(), mostRecentTrialVersion);
483479
return;
484480
}
485481
if (license != null) {
@@ -492,7 +488,7 @@ protected void updateLicenseState(final License license, Version mostRecentTrial
492488
// date that is near Long.MAX_VALUE
493489
active = time >= license.issueDate() && time - GRACE_PERIOD_DURATION.getMillis() < license.expiryDate();
494490
}
495-
licenseState.update(license.operationMode(), active, mostRecentTrialVersion);
491+
licenseState.update(license.operationMode(), active, license.expiryDate(), mostRecentTrialVersion);
496492

497493
if (active) {
498494
if (time < license.expiryDate()) {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
public interface LicenseStateListener {
1616

1717
/**
18-
* Callback when the license state changes. See {@link XPackLicenseState#update(License.OperationMode, boolean, Version)}.
18+
* Callback when the license state changes. See {@link XPackLicenseState#update(License.OperationMode, boolean, long, Version)}.
1919
*/
2020
void licenseStateChanged();
2121

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

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
import org.elasticsearch.Version;
99
import org.elasticsearch.common.Nullable;
1010
import org.elasticsearch.common.Strings;
11-
import org.elasticsearch.common.component.Lifecycle;
1211
import org.elasticsearch.common.logging.HeaderWarning;
1312
import org.elasticsearch.common.logging.LoggerMessageFormat;
1413
import org.elasticsearch.common.settings.Settings;
@@ -25,17 +24,15 @@
2524
import java.util.Objects;
2625
import java.util.Set;
2726
import java.util.concurrent.CopyOnWriteArrayList;
27+
import java.util.concurrent.TimeUnit;
2828
import java.util.concurrent.atomic.LongAccumulator;
2929
import java.util.function.BiFunction;
3030
import java.util.function.Function;
3131
import java.util.function.LongSupplier;
3232
import java.util.function.Predicate;
3333
import java.util.stream.Collectors;
3434

35-
import static org.elasticsearch.cluster.service.ClusterApplierService.CLUSTER_UPDATE_THREAD_NAME;
36-
import static org.elasticsearch.index.mapper.RangeFieldMapper.Defaults.DATE_FORMATTER;
3735
import static org.elasticsearch.license.LicenseService.GRACE_PERIOD_DURATION;
38-
import static org.elasticsearch.xpack.core.XPackPlugin.getSharedLicenseService;
3936

4037
/**
4138
* A holder for the current state of the license for all xpack features.
@@ -407,9 +404,13 @@ private static class Status {
407404
/** True if the license is active, or false if it is expired. */
408405
final boolean active;
409406

410-
Status(OperationMode mode, boolean active) {
407+
/** The current expiration date of the license; Long.MAX_VALUE if not avILble yet. */
408+
final long licenseExpiryDate;
409+
410+
Status(OperationMode mode, boolean active, long licenseExpiryDate) {
411411
this.mode = mode;
412412
this.active = active;
413+
this.licenseExpiryDate = licenseExpiryDate;
413414
}
414415
}
415416

@@ -423,7 +424,7 @@ private static class Status {
423424
// XPackLicenseState. However, if status is read multiple times in a method, it can change in between
424425
// reads. Methods should use `executeAgainstStatus` and `checkAgainstStatus` to ensure that the status
425426
// is only read once.
426-
private volatile Status status = new Status(OperationMode.TRIAL, true);
427+
private volatile Status status = new Status(OperationMode.TRIAL, true, Long.MAX_VALUE);
427428

428429
public XPackLicenseState(Settings settings, LongSupplier epochMillisProvider) {
429430
this.listeners = new CopyOnWriteArrayList<>();
@@ -471,12 +472,13 @@ private boolean checkAgainstStatus(Predicate<Status> statusPredicate) {
471472
*
472473
* @param mode The mode (type) of the current license.
473474
* @param active True if the current license exists and is within its allowed usage period; false if it is expired or missing.
475+
* @param expirationDate Expiration date of the current license.
474476
* @param mostRecentTrialVersion If this cluster has, at some point commenced a trial, the most recent version on which they did that.
475477
* May be {@code null} if they have never generated a trial license on this cluster, or the most recent
476478
* trial was prior to this metadata being tracked (6.1)
477479
*/
478-
void update(OperationMode mode, boolean active, @Nullable Version mostRecentTrialVersion) {
479-
status = new Status(mode, active);
480+
void update(OperationMode mode, boolean active, long expirationDate, @Nullable Version mostRecentTrialVersion) {
481+
status = new Status(mode, active, expirationDate);
480482
listeners.forEach(LicenseStateListener::licenseStateChanged);
481483
}
482484

@@ -513,21 +515,18 @@ public boolean isActive() {
513515
* Checks whether the given feature is allowed, tracking the last usage time.
514516
*/
515517
public boolean checkFeature(Feature feature) {
516-
License license;
517518
boolean allowed = isAllowed(feature);
518519
LongAccumulator maxEpochAccumulator = lastUsed.get(feature);
519520
long now = System.currentTimeMillis();
520521
if (maxEpochAccumulator != null) {
521522
maxEpochAccumulator.accumulate(epochMillisProvider.getAsLong());
522523
}
523524

524-
if(getSharedLicenseService() != null && getSharedLicenseService().getLifecycleState() == Lifecycle.State.STARTED
525-
&& (Thread.currentThread().getName().contains(CLUSTER_UPDATE_THREAD_NAME) == false)
526-
&& (license = getSharedLicenseService().getLicense()) != null
527-
&& feature.minimumOperationMode.compareTo(OperationMode.BASIC) > 0
528-
&& now > license.expiryDate() - GRACE_PERIOD_DURATION.getMillis()) {
529-
HeaderWarning.addWarning("The license [{}] is going to expire on [{}]", license.uid(),
530-
DATE_FORMATTER.formatMillis(license.expiryDate()));
525+
if(feature.minimumOperationMode.compareTo(OperationMode.BASIC) > 0
526+
&& now > status.licenseExpiryDate - GRACE_PERIOD_DURATION.getMillis()) {
527+
HeaderWarning.addWarning("Your license will expire in [{}] days. " +
528+
"Contact your administrator or update your license for continued use of features",
529+
TimeUnit.MILLISECONDS.toDays(status.licenseExpiryDate - now));
531530
}
532531

533532
return allowed;

x-pack/plugin/core/src/test/java/org/elasticsearch/license/TestUtils.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -360,21 +360,23 @@ public static class AssertingLicenseState extends XPackLicenseState {
360360
public final List<License.OperationMode> modeUpdates = new ArrayList<>();
361361
public final List<Boolean> activeUpdates = new ArrayList<>();
362362
public final List<Version> trialVersionUpdates = new ArrayList<>();
363+
public final List<Long> expirationDateUpdates = new ArrayList<>();
363364

364365
public AssertingLicenseState() {
365366
super(Settings.EMPTY, () -> 0);
366367
}
367368

368369
@Override
369-
void update(License.OperationMode mode, boolean active, Version mostRecentTrialVersion) {
370+
void update(License.OperationMode mode, boolean active, long expirationDate, Version mostRecentTrialVersion) {
370371
modeUpdates.add(mode);
371372
activeUpdates.add(active);
373+
expirationDateUpdates.add(expirationDate);
372374
trialVersionUpdates.add(mostRecentTrialVersion);
373375
}
374376
}
375377

376378
/**
377-
* A license state that makes the {@link #update(License.OperationMode, boolean, Version)}
379+
* A license state that makes the {@link #update(License.OperationMode, boolean, long, Version)}
378380
* method public for use in tests.
379381
*/
380382
public static class UpdatableLicenseState extends XPackLicenseState {
@@ -387,8 +389,8 @@ public UpdatableLicenseState(Settings settings) {
387389
}
388390

389391
@Override
390-
public void update(License.OperationMode mode, boolean active, Version mostRecentTrialVersion) {
391-
super.update(mode, active, mostRecentTrialVersion);
392+
public void update(License.OperationMode mode, boolean active, long expirationDate, Version mostRecentTrialVersion) {
393+
super.update(mode, active, expirationDate, mostRecentTrialVersion);
392394
}
393395
}
394396

0 commit comments

Comments
 (0)