/** * Utility for creating a ZonedDateTime object from a millisecond timestamp. * * @param time Milliseconds since Epoch UTC * @return ZonedDateTime representing time */ public static ZonedDateTime zonedDateTimeOf(final long time) { return zonedDateTimeOf(time, ZoneOffset.UTC); }
/** * Format the datetime given. * * @param dt the datetime * @return the date and time */ public String format(final Instant dt) { return format(DateTimeUtils.dateOf(dt)); } }
/** * Gets creation time. Attempts to parse the value * as a {@link ZonedDateTime}. Otherwise, assumes a * {@link LocalDateTime} and converts it based on system's * default zone. * * @return the creation time */ @JsonIgnore public ZonedDateTime getCreationZonedDateTime() { val dt = DateTimeUtils.zonedDateTimeOf(this.creationTime); if (dt != null) { return dt; } val lt = DateTimeUtils.localDateTimeOf(this.creationTime); return DateTimeUtils.zonedDateTimeOf(lt.atZone(ZoneId.systemDefault())); }
id = '_' + String.valueOf(RandomUtils.getNativeInstance().nextLong()); val statement = newAuthnStatement(authenticationMethod, DateTimeUtils.zonedDateTimeOf(assertion.getAuthenticationDate()), id); if (assertion.getValidUntilDate() != null) { val dt = DateTimeUtils.zonedDateTimeOf(assertion.getValidUntilDate()); statement.setSessionNotOnOrAfter( DateTimeUtils.dateTimeOf(dt.plusSeconds(casProperties.getAuthn().getSamlIdp().getResponse().getSkewAllowance())));
/** * Local date time of local date time. * * @param time the time * @return the local date time */ public static LocalDateTime localDateTimeOf(final Date time) { return localDateTimeOf(time.getTime()); }
/** * Gets Timestamp for ZonedDateTime. * * @param time Time object to be converted. * @return Timestamp representing time */ public static Timestamp timestampOf(final ChronoZonedDateTime time) { return timestampOf(time.toInstant()); }
/** * Gets DateTime for ZonedDateTime. * * @param time Time object to be converted. * @return DateTime representing time */ public static DateTime dateTimeOf(final ChronoZonedDateTime time) { return dateTimeOf(time.toInstant()); }
/** * Returns a predicate that determined whether a service has expired. * * @return true if the service is still valid. false if service has expired. */ public static Predicate<RegisteredService> getRegisteredServiceExpirationPolicyPredicate() { return service -> { try { if (service == null) { return false; } val policy = service.getExpirationPolicy(); if (policy == null || StringUtils.isBlank(policy.getExpirationDate())) { return true; } val now = getCurrentSystemTime(); val expirationDate = DateTimeUtils.localDateTimeOf(policy.getExpirationDate()); LOGGER.debug("Service expiration date is [{}] while now is [{}]", expirationDate, now); return !now.isAfter(expirationDate); } catch (final Exception e) { LOGGER.warn(e.getMessage(), e); } return false; }; }
/** * Gets failure in range cut off date. * * @return the failure in range cut off date */ protected Date getFailureInRangeCutOffDate() { val cutoff = ZonedDateTime.now(ZoneOffset.UTC).minusSeconds(getFailureRangeInSeconds()); return DateTimeUtils.timestampOf(cutoff); }
/** * Gets ZonedDateTime for Date. * * @param time Time object to be converted. * @return ZonedDateTime representing time */ public static ZonedDateTime zonedDateTimeOf(final Date time) { return zonedDateTimeOf(time.getTime()); }
/** * Gets Date for ZonedDateTime. * * @param time Time object to be converted. * @return Date representing time */ public static Date dateOf(final ChronoZonedDateTime time) { return dateOf(time.toInstant()); }
/** * Does ending time allow service access boolean. * * @return true/false */ protected boolean doesEndingTimeAllowServiceAccess() { if (this.endingDateTime != null) { val et = DateTimeUtils.zonedDateTimeOf(this.endingDateTime); if (et != null) { if (ZonedDateTime.now().isAfter(et)) { LOGGER.warn("Service access not allowed because it ended at [{}]. Now is [{}]", this.endingDateTime, ZonedDateTime.now()); return false; } } else { val etLocal = DateTimeUtils.localDateTimeOf(this.endingDateTime); if (etLocal != null) { if (LocalDateTime.now().isAfter(etLocal)) { LOGGER.warn("Service access not allowed because it ended at [{}]. Now is [{}]", this.endingDateTime, LocalDateTime.now()); return false; } } } } return true; }
@Override public ZonedDateTime convert(final String source) { if (StringUtils.isBlank(source)) { return null; } return DateTimeUtils.zonedDateTimeOf(source); } }
/** * Format the datetime given. * * @param dt the datetime * @return the date and time */ public String format(final ZonedDateTime dt) { return format(DateTimeUtils.dateOf(dt)); }
/** * Does starting time allow service access boolean. * * @return true/false */ protected boolean doesStartingTimeAllowServiceAccess() { if (this.startingDateTime != null) { val st = DateTimeUtils.zonedDateTimeOf(this.startingDateTime); if (st != null) { if (ZonedDateTime.now().isBefore(st)) { LOGGER.warn("Service access not allowed because it starts at [{}]. Zoned now is [{}]", this.startingDateTime, ZonedDateTime.now()); return false; } } else { val stLocal = DateTimeUtils.localDateTimeOf(this.startingDateTime); if (stLocal != null) { if (LocalDateTime.now().isBefore(stLocal)) { LOGGER.warn("Service access not allowed because it starts at [{}]. Local now is [{}]", this.startingDateTime, ZonedDateTime.now()); return false; } } } } return true; } }
/** * Gets ZonedDateTime for ReadableInstant. * * @param time Time object to be converted. * @return ZonedDateTime representing time */ public static ZonedDateTime zonedDateTimeOf(final ReadableInstant time) { return zonedDateTimeOf(time.getMillis()); }
/** * Build cas assertion. * * @param principal the principal * @param registeredService the registered service * @param attributes the attributes * @return the assertion */ protected Assertion buildCasAssertion(final String principal, final RegisteredService registeredService, final Map<String, Object> attributes) { val p = new AttributePrincipalImpl(principal, attributes); return new AssertionImpl(p, DateTimeUtils.dateOf(ZonedDateTime.now()), null, DateTimeUtils.dateOf(ZonedDateTime.now()), attributes); }
public ZonedDateTime getValidUntil() { return DateTimeUtils.zonedDateTimeOf(this.ssoDescriptor.getValidUntil()); }
@Override public void encode(final BsonWriter writer, final ZonedDateTime zonedDateTime, final EncoderContext encoderContext) { writer.writeTimestamp(new BsonTimestamp(DateTimeUtils.dateOf(zonedDateTime).getTime())); }
/** * Handle application ready event. * * @param event the event */ @EventListener public void handleApplicationReadyEvent(final ApplicationReadyEvent event) { AsciiArtUtils.printAsciiArtInfo(LOGGER, "READY", StringUtils.EMPTY); LOGGER.info("Ready to process requests @ [{}]", DateTimeUtils.zonedDateTimeOf(event.getTimestamp())); }