Example usage for com.amazonaws.util DateUtils parseISO8601Date

List of usage examples for com.amazonaws.util DateUtils parseISO8601Date

Introduction

In this page you can find the example usage for com.amazonaws.util DateUtils parseISO8601Date.

Prototype

public static Date parseISO8601Date(String dateString) 

Source Link

Document

Parses the specified date string as an ISO 8601 date and returns the Date object.

Usage

From source file:grails.plugin.awssdk.cognito.AuthUtilities.java

License:Open Source License

/**
 * Checks to see if the request has valid timestamp. If given timestamp
 * falls in 30 mins window from current server timestamp
 * @param timestamp timestamp//from  w  ww  .jav  a 2s .c o m
 * @return true if the timestamp is valid
 */
public static boolean isTimestampValid(String timestamp) {
    long timestampLong = 0L;
    final long window = 15 * 60 * 1000L;

    if (null == timestamp) {
        return false;
    }

    timestampLong = DateUtils.parseISO8601Date(timestamp).getTime();

    Long now = new Date().getTime();

    long before15Mins = new Date(now - window).getTime();
    long after15Mins = new Date(now + window).getTime();

    return (timestampLong >= before15Mins && timestampLong <= after15Mins);
}

From source file:jp.xet.uncommons.spring.DynamoPersistentTokenRepository.java

License:Apache License

@Override
public PersistentRememberMeToken getTokenForSeries(String seriesId) {
    if (logger.isTraceEnabled()) {
        logger.trace("Retrieve token: seriesId={}", seriesId);
    }/*from  w w w  . j av  a2  s.co  m*/

    try {
        GetItemRequest getRequest = new GetItemRequest().withTableName(persistentLoginTable)
                .withKey(Collections.singletonMap(SERIES, new AttributeValue(seriesId)));
        GetItemResult result = dynamoDb.getItem(getRequest);
        if (logger.isDebugEnabled()) {
            logger.debug("Token retrieved: {}", result);
        }

        Map<String, AttributeValue> item = result.getItem();
        if (item == null) {
            if (logger.isInfoEnabled()) {
                logger.info("Querying token for series '{}' returned no results.", seriesId);
            }
            return null;
        }

        String username = item.get(USERNAME).getS();
        String series = item.get(SERIES).getS();
        String tokenValue = item.get(TOKEN).getS();
        Date lastUsed = DateUtils.parseISO8601Date(item.get(LAST_USED).getS());
        return new PersistentRememberMeToken(username, series, tokenValue, lastUsed);
    } catch (AmazonServiceException e) {
        logger.error("Failed to load token for series " + seriesId, e);
    } catch (AmazonClientException e) {
        logger.error("Failed to load token for series " + seriesId, e);
    } catch (Exception e) {
        logger.error("unknown exception", e);
    }
    return null;
}