/** * 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); }
/** * 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()); }
@Override public ZonedDateTime convert(final String source) { if (StringUtils.isBlank(source)) { return null; } return DateTimeUtils.zonedDateTimeOf(source); } }
/** * 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()); }
/** * 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())); }
public ZonedDateTime getValidUntil() { return DateTimeUtils.zonedDateTimeOf(this.ssoDescriptor.getValidUntil()); }
/** * 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())); }
/** * 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())); } }
@Override public ZonedDateTime read(final Kryo kryo, final Input input, final Class<ZonedDateTime> type) { val time = kryo.readObject(input, Long.class); val zoneId = RegExUtils.removeAll(input.readString().trim(), "\\p{C}"); try { LOGGER.trace("Reading zoned date time instance with time [{}] and zone id [{}]", time, zoneId); val zone = ZoneId.of(zoneId); return DateTimeUtils.zonedDateTimeOf(time, zone); } catch (final Exception e) { LOGGER.warn("Unable to parse a zoned datetime instance with time [{}] and zone id [{}]: [{}]", time, zoneId, e.getMessage()); return DateTimeUtils.zonedDateTimeOf(time, ZoneId.systemDefault()); } } }
/** * Gets last modified date/time for the module. * * @return the date/time */ @SneakyThrows public static ZonedDateTime getDateTime() { val clazz = CasVersion.class; val resource = clazz.getResource(clazz.getSimpleName() + ".class"); if ("file".equals(resource.getProtocol())) { return DateTimeUtils.zonedDateTimeOf(new File(resource.toURI()).lastModified()); } if ("jar".equals(resource.getProtocol())) { val path = resource.getPath(); val file = new File(path.substring(JAR_PROTOCOL_STARTING_INDEX, path.indexOf('!'))); return DateTimeUtils.zonedDateTimeOf(file.lastModified()); } if ("vfs".equals(resource.getProtocol())) { val file = new VfsResource(resource.openConnection().getContent()).getFile(); return DateTimeUtils.zonedDateTimeOf(file.lastModified()); } LOGGER.warn("Unhandled url protocol: [{}] resource: [{}]", resource.getProtocol(), resource); return ZonedDateTime.now(); } }
@Override public ZonedDateTime decode(final BsonReader reader, final DecoderContext decoderContext) { val stamp = reader.readTimestamp(); val dt = new Date(stamp.getTime()); return DateTimeUtils.zonedDateTimeOf(dt); }
/** * Determines whether the given CRL is expired by comparing the nextUpdate field * with a given date. * * @param crl CRL to examine. * @param reference Reference date for comparison. * @return True if reference date is after CRL next update, false otherwise. */ public static boolean isExpired(final X509CRL crl, final ZonedDateTime reference) { return reference.isAfter(DateTimeUtils.zonedDateTimeOf(crl.getNextUpdate())); }
/** * 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; }
/** * 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; } }
/** * Instantiates a new revoked certificate exception. * * @param entry the entry */ public RevokedCertificateException(final X509CRLEntry entry) { this(DateTimeUtils.zonedDateTimeOf(entry.getRevocationDate()), entry.getSerialNumber(), getReasonFromX509Entry(entry)); }
@Override protected void prepareResponse(final Response response, final Map<String, Object> model) { val issuedAt = DateTimeUtils.zonedDateTimeOf(response.getIssueInstant()); val service = getAssertionFrom(model).getService(); LOGGER.debug("Preparing SAML response for service [{}]", service);
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())));
private static CasEvent prepareCasEvent(final AbstractCasEvent event) { val dto = new CasEvent(); dto.setType(event.getClass().getCanonicalName()); dto.putTimestamp(event.getTimestamp()); dto.setCreationTime(DateTimeUtils.zonedDateTimeOf(event.getTimestamp()).toString()); val clientInfo = ClientInfoHolder.getClientInfo(); dto.putClientIpAddress(clientInfo.getClientIpAddress()); dto.putServerIpAddress(clientInfo.getServerIpAddress()); dto.putAgent(WebUtils.getHttpServletRequestUserAgentFromRequestContext()); val location = WebUtils.getHttpServletRequestGeoLocationFromRequestContext(); if (location != null) { dto.putGeoLocation(location); } return dto; }