The HaltedClock was a leftover from moving over from our own Clock
implementation to a java.time one. java.time already has a fixed clock,
this one is not needed.

Original commit: elastic/x-pack-elasticsearch@f91c401a60
This commit is contained in:
Alexander Reelsen 2018-01-23 14:13:22 +01:00 committed by GitHub
parent c70c1c7e98
commit e3da8fa4ae
3 changed files with 10 additions and 56 deletions

View File

@ -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());
}
}

View File

@ -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"));

View File

@ -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) {