Search in sources :

Example 56 with Instant

use of java.time.Instant in project aroma-data-operations by RedRoma.

the class MemoryTokenRepository method saveToken.

@Override
public void saveToken(AuthenticationToken token) throws TException {
    checkThat(token).throwing(ex -> new InvalidTokenException(ex.getMessage())).is(legalToken());
    checkThat(token.ownerId).usingMessage("token missing ownerId").throwing(InvalidTokenException.class).is(nonEmptyString());
    checkThat(token.tokenType).usingMessage("tokenType is required").throwing(InvalidTokenException.class).is(notNull());
    Instant expirationTime = Instant.ofEpochMilli(token.timeOfExpiration);
    checkThat(expirationTime).throwing(InvalidArgumentException.class).usingMessage("Token expiration time must be in the future: " + expirationTime).is(TimeAssertions.inTheFuture());
    Instant now = Instant.now();
    long timeToLiveSeconds = now.until(expirationTime, ChronoUnit.SECONDS);
    synchronized (tokens) {
        this.tokens.put(token.tokenId, token, timeToLiveSeconds, TimeUnit.SECONDS);
        addTokenForOwner(token);
    }
}
Also used : java.util(java.util) StringAssertions(tech.sirwellington.alchemy.arguments.assertions.StringAssertions) LoggerFactory(org.slf4j.LoggerFactory) TokenRepository(tech.aroma.data.TokenRepository) AuthenticationToken(tech.aroma.thrift.authentication.AuthenticationToken) ThreadSafe(tech.sirwellington.alchemy.annotations.concurrency.ThreadSafe) RequestAssertions.isNullOrEmpty(tech.aroma.data.assertions.RequestAssertions.isNullOrEmpty) InvalidTokenException(tech.aroma.thrift.exceptions.InvalidTokenException) Logger(org.slf4j.Logger) CONCRETE_BEHAVIOR(tech.sirwellington.alchemy.annotations.designs.patterns.StrategyPattern.Role.CONCRETE_BEHAVIOR) ExpirationListener(net.jodah.expiringmap.ExpirationListener) StrategyPattern(tech.sirwellington.alchemy.annotations.designs.patterns.StrategyPattern) ExpiringMap(net.jodah.expiringmap.ExpiringMap) TException(org.apache.thrift.TException) Instant(java.time.Instant) InvalidArgumentException(tech.aroma.thrift.exceptions.InvalidArgumentException) TimeUnit(java.util.concurrent.TimeUnit) Assertions.notNull(tech.sirwellington.alchemy.arguments.assertions.Assertions.notNull) Collectors.toList(java.util.stream.Collectors.toList) Arguments(tech.sirwellington.alchemy.arguments.Arguments) ChronoUnit(java.time.temporal.ChronoUnit) AromaAssertions.legalToken(tech.aroma.thrift.assertions.AromaAssertions.legalToken) CollectionAssertions.keyInMap(tech.sirwellington.alchemy.arguments.assertions.CollectionAssertions.keyInMap) TimeAssertions(tech.sirwellington.alchemy.arguments.assertions.TimeAssertions) Lists(sir.wellington.alchemy.collections.lists.Lists) InvalidTokenException(tech.aroma.thrift.exceptions.InvalidTokenException) Instant(java.time.Instant)

Example 57 with Instant

use of java.time.Instant in project rhino by PLOS.

the class CacheableResponse method serveEntity.

/**
   * Serve a view representing a timestamped entity.
   *
   * @param entity       the entity to represent in the response
   * @param viewFunction a function that converts the entity into a serializable view
   * @param <E>          the entity's type
   * @param <T>          the view's type
   * @return a response of the view
   */
public static <T, E extends Timestamped> CacheableResponse<T> serveEntity(E entity, Function<? super E, ? extends T> viewFunction) {
    Objects.requireNonNull(viewFunction);
    Supplier<T> supplier = () -> viewFunction.apply(entity);
    Instant lastModified = entity.getLastModified().toInstant();
    return new CacheableResponse<>(lastModified, supplier);
}
Also used : Instant(java.time.Instant)

Example 58 with Instant

use of java.time.Instant in project aroma-data-operations by RedRoma.

the class MemoryTokenRepositoryTest method setUp.

@Before
public void setUp() {
    repository = new MemoryTokenRepository();
    token = TokenGenerators.authenticationTokens().get();
    tokenId = token.getTokenId();
    ownerId = token.getOwnerId();
    tokens.forEach(t -> t.setOwnerId(ownerId));
    Instant timeOfExpiration = one(futureInstants()).plus(1, ChronoUnit.HOURS);
    token.setTimeOfExpiration(timeOfExpiration.toEpochMilli());
    tokens.forEach(t -> t.setTimeOfExpiration(timeOfExpiration.toEpochMilli()));
}
Also used : Instant(java.time.Instant) Before(org.junit.Before)

Example 59 with Instant

use of java.time.Instant in project graylog2-server by Graylog2.

the class MongoZonedDateTimeSerializer method serialize.

@Override
public void serialize(ZonedDateTime zonedDateTime, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException {
    final Instant instant = zonedDateTime.withZoneSameInstant(ZoneOffset.UTC).toInstant();
    final Date date = Date.from(instant);
    jsonGenerator.writeObject(date);
}
Also used : Instant(java.time.Instant) Date(java.util.Date)

Example 60 with Instant

use of java.time.Instant in project jdk8u_jdk by JetBrains.

the class TCKDuration method factory_between_TemporalTemporal_Instant.

@Test(dataProvider = "durationBetweenInstant")
public void factory_between_TemporalTemporal_Instant(long secs1, int nanos1, long secs2, int nanos2, long expectedSeconds, int expectedNanoOfSecond) {
    Instant start = Instant.ofEpochSecond(secs1, nanos1);
    Instant end = Instant.ofEpochSecond(secs2, nanos2);
    Duration t = Duration.between(start, end);
    assertEquals(t.getSeconds(), expectedSeconds);
    assertEquals(t.getNano(), expectedNanoOfSecond);
}
Also used : Instant(java.time.Instant) Duration(java.time.Duration) Test(org.testng.annotations.Test)

Aggregations

Instant (java.time.Instant)463 Test (org.testng.annotations.Test)143 Test (org.junit.Test)85 ZonedDateTime (java.time.ZonedDateTime)39 Duration (java.time.Duration)30 Clock (java.time.Clock)26 Lifetime (org.apache.cxf.sts.request.Lifetime)26 OffsetDateTime (java.time.OffsetDateTime)23 LocalDateTime (java.time.LocalDateTime)20 ArrayList (java.util.ArrayList)18 Element (org.w3c.dom.Element)18 LocalDate (java.time.LocalDate)17 IOException (java.io.IOException)14 Date (java.util.Date)14 LocalTime (java.time.LocalTime)12 DateTimeFormatter (java.time.format.DateTimeFormatter)12 STSException (org.apache.cxf.ws.security.sts.provider.STSException)12 SecurityToken (org.apache.cxf.ws.security.tokenstore.SecurityToken)12 Timestamp (java.sql.Timestamp)11 DefaultConditionsProvider (org.apache.cxf.sts.token.provider.DefaultConditionsProvider)10