Exemple #1
0
 private Optional<DateTime> getTokenExpiryDate(TokenGrantInfo tokenGrantInfo)
     throws OAuthProblemException {
   if (!tokenGrantInfo.getAccessTokenExpires()) {
     // Token does not expire
     if (tokenGrantInfo.getGrantClientTokensMustExpire()) {
       throw OAuthProblemException.error(OAuthError.ResourceResponse.INVALID_TOKEN);
     }
     return Optional.absent();
   }
   int expirySeconds;
   try {
     expirySeconds = Integer.parseInt(tokenGrantInfo.getAccessTokenExpiry());
   } catch (NumberFormatException e) {
     log.warning("NumberFormatException during token check: " + e);
     throw OAuthProblemException.error(OAuthError.ResourceResponse.INVALID_TOKEN);
   }
   return Optional.of(
       new DateTime(tokenGrantInfo.getGrantTimeStamp()).plusSeconds(Math.abs(expirySeconds)));
 }