protected OAuthEntry getOAuthEntry(OAuthMessage message) throws OAuthProblemException {
   OAuthEntry entry = null;
   String token = getParameter(message, OAuth.OAUTH_TOKEN);
   if (!StringUtils.isEmpty(token)) {
     entry = store.getEntry(token);
     if (entry == null) {
       OAuthProblemException e = new OAuthProblemException(OAuth.Problems.TOKEN_REJECTED);
       e.setParameter(OAuth.Problems.OAUTH_PROBLEM_ADVICE, "cannot find token");
       throw e;
     } else if (entry.type != OAuthEntry.Type.ACCESS) {
       OAuthProblemException e = new OAuthProblemException(OAuth.Problems.TOKEN_REJECTED);
       e.setParameter(OAuth.Problems.OAUTH_PROBLEM_ADVICE, "token is not an access token");
       throw e;
     } else if (entry.isExpired()) {
       throw new OAuthProblemException(OAuth.Problems.TOKEN_EXPIRED);
     }
   }
   return entry;
 }
Exemplo n.º 2
0
  private OAuthEntry getValidatedEntry(OAuthMessage requestMessage)
      throws IOException, ServletException, OAuthException, URISyntaxException {

    OAuthEntry entry = dataStore.getEntry(requestMessage.getToken());
    if (entry == null) throw new OAuthProblemException(OAuth.Problems.TOKEN_REJECTED);

    if (entry.type != OAuthEntry.Type.REQUEST)
      throw new OAuthProblemException(OAuth.Problems.TOKEN_USED);

    if (entry.isExpired()) throw new OAuthProblemException(OAuth.Problems.TOKEN_EXPIRED);

    // find consumer key, compare with supplied value, if present.

    if (requestMessage.getConsumerKey() == null) {
      OAuthProblemException e = new OAuthProblemException(OAuth.Problems.PARAMETER_ABSENT);
      e.setParameter(OAuth.Problems.OAUTH_PARAMETERS_ABSENT, OAuth.OAUTH_CONSUMER_KEY);
      throw e;
    }

    String consumerKey = entry.consumerKey;
    if (!consumerKey.equals(requestMessage.getConsumerKey()))
      throw new OAuthProblemException(OAuth.Problems.CONSUMER_KEY_REFUSED);

    OAuthConsumer consumer = dataStore.getConsumer(consumerKey);

    if (consumer == null) throw new OAuthProblemException(OAuth.Problems.CONSUMER_KEY_UNKNOWN);

    OAuthAccessor accessor = new OAuthAccessor(consumer);

    accessor.requestToken = entry.token;
    accessor.tokenSecret = entry.tokenSecret;

    VALIDATOR.validateMessage(requestMessage, accessor);

    return entry;
  }