Example usage for com.amazonaws.auth.internal SignerConstants X_AMZ_EXPIRES

List of usage examples for com.amazonaws.auth.internal SignerConstants X_AMZ_EXPIRES

Introduction

In this page you can find the example usage for com.amazonaws.auth.internal SignerConstants X_AMZ_EXPIRES.

Prototype

String X_AMZ_EXPIRES

To view the source code for com.amazonaws.auth.internal SignerConstants X_AMZ_EXPIRES.

Click Source Link

Usage

From source file:org.icgc.dcc.storage.client.util.S3PresignedUrlValidator.java

License:Open Source License

/**
 * Return expiry date of presigned URL in the local time zone (system default). Distinguished between V2 and V4 AWS
 * signatures/*from  w w  w  . ja  v  a2 s  . co  m*/
 * @param args - URL query arguments
 * @return expiry date translated to specified time zone
 */
@Override
LocalDateTime extractExpiryDate(Map<String, String> args, ZoneId effectiveTimeZone) {
    LocalDateTime expiry = null;
    if (args.containsKey(HttpHeaders.EXPIRES.toLowerCase())) {
        expiry = extractV2ExpiryDate(args, effectiveTimeZone);
    } else if (args.containsKey(SignerConstants.X_AMZ_EXPIRES.toLowerCase())
            && (args.containsKey(SignerConstants.X_AMZ_DATE.toLowerCase()))) {
        expiry = extractV4ExpiryDate(args, effectiveTimeZone);
    } else {
        // Missing expected query arguments
        log.error("Could not identify expected date parameters in request: {}", flattenMap(args));
        throw new IllegalArgumentException(
                "Could not parse presigned URL - missing expected expiry date parameters");
    }
    log.debug("Expiry DateTime (Local): {}\n", expiry);
    return expiry;
}

From source file:org.icgc.dcc.storage.client.util.S3PresignedUrlValidator.java

License:Open Source License

/**
 * V4 Signature uses 'X-Amz-Expires' and 'X-Amz-Date' headers
 * @param args// w w w.  ja va  2  s  .co  m
 * @param effectiveTimeZone
 * @return timestamp from header
 */
LocalDateTime extractV4ExpiryDate(Map<String, String> args, ZoneId effectiveTimeZone) {
    String ts = "";
    try {
        ts = args.get(SignerConstants.X_AMZ_DATE.toLowerCase()); // Basic format ISO 8601 string in UTC
        val reqDate = ZonedDateTime.parse(ts, formatter);
        log.trace("Request DateTime (Zoned): {}", reqDate);

        val expSeconds = Integer.parseInt(args.get(SignerConstants.X_AMZ_EXPIRES.toLowerCase()));

        // Translate to effective timezone (and increment with expiry period)
        return reqDate.withZoneSameInstant(effectiveTimeZone).toLocalDateTime().plusSeconds(expSeconds);
    } catch (DateTimeParseException pe) {
        log.error("{} is not parsable!", ts);
        throw pe; // Rethrow the exception.
    }
}