diff --git a/plugin/core/src/main/java/org/elasticsearch/xpack/common/time/HaltedClock.java b/plugin/core/src/main/java/org/elasticsearch/xpack/common/time/HaltedClock.java deleted file mode 100644 index 809a737abb6..00000000000 --- a/plugin/core/src/main/java/org/elasticsearch/xpack/common/time/HaltedClock.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License; - * you may not use this file except in compliance with the Elastic License. - */ -package org.elasticsearch.xpack.common.time; - -import org.joda.time.DateTime; -import org.joda.time.DateTimeZone; - -import java.time.Clock; -import java.time.Instant; -import java.time.ZoneId; -import java.time.ZoneOffset; - -public class HaltedClock extends Clock { - - private final DateTime now; - - public HaltedClock(DateTime now) { - this.now = now.toDateTime(DateTimeZone.UTC); - } - - @Override - public ZoneId getZone() { - return ZoneOffset.UTC; - } - - @Override - public Clock withZone(ZoneId zoneId) { - if (zoneId.equals(ZoneOffset.UTC)) { - return this; - } - - throw new IllegalArgumentException("Halted clock time zone cannot be changed"); - } - - @Override - public long millis() { - return now.getMillis(); - } - - @Override - public Instant instant() { - return Instant.ofEpochMilli(now.getMillis()); - } -} diff --git a/plugin/security/src/test/java/org/elasticsearch/xpack/security/authc/saml/SamlLogoutRequestMessageBuilderTests.java b/plugin/security/src/test/java/org/elasticsearch/xpack/security/authc/saml/SamlLogoutRequestMessageBuilderTests.java index 88d574de489..252cf2f0d1c 100644 --- a/plugin/security/src/test/java/org/elasticsearch/xpack/security/authc/saml/SamlLogoutRequestMessageBuilderTests.java +++ b/plugin/security/src/test/java/org/elasticsearch/xpack/security/authc/saml/SamlLogoutRequestMessageBuilderTests.java @@ -6,11 +6,10 @@ package org.elasticsearch.xpack.security.authc.saml; import java.time.Clock; +import java.time.Instant; +import java.time.ZoneOffset; -import org.elasticsearch.xpack.common.time.HaltedClock; import org.hamcrest.Matchers; -import org.joda.time.DateTime; -import org.joda.time.DateTimeZone; import org.junit.Before; import org.opensaml.saml.common.xml.SAMLConstants; import org.opensaml.saml.saml2.core.LogoutRequest; @@ -67,8 +66,8 @@ public class SamlLogoutRequestMessageBuilderTests extends SamlTestCase { "http://idp.example.com/saml/logout/artifact"); idpRole.getSingleLogoutServices().add(sloArtifact); - final DateTime now = DateTime.now(DateTimeZone.UTC); - final SamlLogoutRequestMessageBuilder builder = new SamlLogoutRequestMessageBuilder(new HaltedClock(now), sp, idp, nameId, session); + Clock fixedClock = Clock.fixed(Instant.now(), ZoneOffset.UTC); + final SamlLogoutRequestMessageBuilder builder = new SamlLogoutRequestMessageBuilder(fixedClock, sp, idp, nameId, session); final LogoutRequest logoutRequest = builder.build(); assertThat(logoutRequest, notNullValue()); assertThat(logoutRequest.getReason(), nullValue()); @@ -82,7 +81,7 @@ public class SamlLogoutRequestMessageBuilderTests extends SamlTestCase { assertThat(logoutRequest.getConsent(), nullValue()); assertThat(logoutRequest.getNotOnOrAfter(), nullValue()); assertThat(logoutRequest.getIssueInstant(), notNullValue()); - assertThat(logoutRequest.getIssueInstant(), equalTo(now)); + assertThat(logoutRequest.getIssueInstant().getMillis(), equalTo(fixedClock.millis())); assertThat(logoutRequest.getSessionIndexes(), iterableWithSize(1)); assertThat(logoutRequest.getSessionIndexes().get(0).getSessionIndex(), equalTo(session)); assertThat(logoutRequest.getDestination(), equalTo("http://idp.example.com/saml/logout/redirect")); diff --git a/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/watch/WatchParser.java b/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/watch/WatchParser.java index 7a8dda3fc86..bb68d1217ae 100644 --- a/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/watch/WatchParser.java +++ b/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/watch/WatchParser.java @@ -29,11 +29,12 @@ import org.elasticsearch.xpack.watcher.support.xcontent.WatcherXContentParser; import org.elasticsearch.xpack.watcher.transform.ExecutableTransform; import org.elasticsearch.xpack.watcher.trigger.Trigger; import org.elasticsearch.xpack.watcher.trigger.TriggerService; -import org.elasticsearch.xpack.common.time.HaltedClock; import org.joda.time.DateTime; import java.io.IOException; import java.time.Clock; +import java.time.Instant; +import java.time.ZoneOffset; import java.util.Collections; import java.util.HashMap; import java.util.List; @@ -102,8 +103,9 @@ public class WatchParser extends AbstractComponent { XContentParser parser = null; try { // EMPTY is safe here because we never use namedObject - parser = new WatcherXContentParser(xContentType.xContent().createParser(NamedXContentRegistry.EMPTY, source), - new HaltedClock(now), withSecrets ? cryptoService : null); + Clock fixedClock = Clock.fixed(Instant.now(), ZoneOffset.UTC); + parser = new WatcherXContentParser(xContentType.xContent().createParser(NamedXContentRegistry.EMPTY, source), fixedClock, + withSecrets ? cryptoService : null); parser.nextToken(); return parse(id, includeStatus, parser); } catch (IOException ioe) {