Java Code Examples for net.oauth.OAuthAccessor#clone()

The following examples show how to use net.oauth.OAuthAccessor#clone() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DataApiTokenContainer.java    From swellrt with Apache License 2.0 6 votes vote down vote up
/**
 * Authorizes a request token to be exchanged for an access token.
 *
 * @param requestToken the request token used for identification.
 * @param user the user that has authorized the token.
 * @throws OAuthProblemException if the request token does not map to an
 *         accessor or if the token was already used.
 */
public OAuthAccessor authorizeRequestToken(String requestToken, ParticipantId user)
    throws OAuthProblemException {
  Preconditions.checkNotNull(user, "User must not be null");

  OAuthAccessor accessor = getRequestTokenAccessor(requestToken);

  if (accessor.getProperty(USER_PROPERTY_NAME) != null) {
    throw OAuthUtil.newOAuthProblemException(OAuth.Problems.TOKEN_USED);
  }

  accessor.setProperty(USER_PROPERTY_NAME, user);
  requestTokenAccessors.put(requestToken, accessor);

  LOG.info("Authorized request token for " + user);
  return accessor.clone();
}
 
Example 2
Source File: DataApiTokenContainer.java    From swellrt with Apache License 2.0 6 votes vote down vote up
/**
 * Authorize the {@link OAuthAccessor} by generating a new access token and
 * token secret.
 *
 * @param requestToken the requestToken used for identifying the accessor that
 *        needs to be authorized.
 * @return a new {@link OAuthAccessor} with the access token and token secret
 *         set.
 * @throws OAuthProblemException if the request token in the accessor is not
 *         known.
 */
public OAuthAccessor generateAccessToken(String requestToken) throws OAuthProblemException {
  OAuthAccessor accessor = getRequestTokenAccessor(requestToken);

  if (accessor.getProperty(USER_PROPERTY_NAME) == null) {
    // User has not given the consumer permission yet.
    throw OAuthUtil.newOAuthProblemException(OAuth.Problems.PERMISSION_UNKNOWN);
  }

  // Token secret does not need to unique so can be generated now.
  accessor.tokenSecret = generateToken();

  do {
    accessor.accessToken = generateToken();
  } while (accessTokenAccessors.putIfAbsent(accessor.accessToken, accessor) != null);
  requestTokenAccessors.remove(accessor.requestToken);

  LOG.info("Generated access token for " + accessor.getProperty(USER_PROPERTY_NAME));
  return accessor.clone();
}
 
Example 3
Source File: DataApiTokenContainer.java    From incubator-retired-wave with Apache License 2.0 6 votes vote down vote up
/**
 * Authorizes a request token to be exchanged for an access token.
 *
 * @param requestToken the request token used for identification.
 * @param user the user that has authorized the token.
 * @throws OAuthProblemException if the request token does not map to an
 *         accessor or if the token was already used.
 */
public OAuthAccessor authorizeRequestToken(String requestToken, ParticipantId user)
    throws OAuthProblemException {
  Preconditions.checkNotNull(user, "User must not be null");

  OAuthAccessor accessor = getRequestTokenAccessor(requestToken);

  if (accessor.getProperty(USER_PROPERTY_NAME) != null) {
    throw OAuthUtil.newOAuthProblemException(OAuth.Problems.TOKEN_USED);
  }

  accessor.setProperty(USER_PROPERTY_NAME, user);
  requestTokenAccessors.put(requestToken, accessor);

  LOG.info("Authorized request token for " + user);
  return accessor.clone();
}
 
Example 4
Source File: DataApiTokenContainer.java    From incubator-retired-wave with Apache License 2.0 6 votes vote down vote up
/**
 * Authorize the {@link OAuthAccessor} by generating a new access token and
 * token secret.
 *
 * @param requestToken the requestToken used for identifying the accessor that
 *        needs to be authorized.
 * @return a new {@link OAuthAccessor} with the access token and token secret
 *         set.
 * @throws OAuthProblemException if the request token in the accessor is not
 *         known.
 */
public OAuthAccessor generateAccessToken(String requestToken) throws OAuthProblemException {
  OAuthAccessor accessor = getRequestTokenAccessor(requestToken);

  if (accessor.getProperty(USER_PROPERTY_NAME) == null) {
    // User has not given the consumer permission yet.
    throw OAuthUtil.newOAuthProblemException(OAuth.Problems.PERMISSION_UNKNOWN);
  }

  // Token secret does not need to unique so can be generated now.
  accessor.tokenSecret = generateToken();

  do {
    accessor.accessToken = generateToken();
  } while (accessTokenAccessors.putIfAbsent(accessor.accessToken, accessor) != null);
  requestTokenAccessors.remove(accessor.requestToken);

  LOG.info("Generated access token for " + accessor.getProperty(USER_PROPERTY_NAME));
  return accessor.clone();
}
 
Example 5
Source File: DataApiTokenContainer.java    From swellrt with Apache License 2.0 5 votes vote down vote up
/**
 * Gets the {@link OAuthAccessor} that is identified by the given request
 * token. Any changes made to the accessor's fields, except the consumer, will
 * not be reflected in this container.
 *
 * @param requestToken the request token used for identification.
 * @throws OAuthProblemException if the token does not map to an accessor.
 */
public OAuthAccessor getRequestTokenAccessor(String requestToken) throws OAuthProblemException {
  OAuthAccessor accessor = requestTokenAccessors.get(requestToken);
  if (accessor == null) {
    OAuthProblemException exception =
        OAuthUtil.newOAuthProblemException(OAuth.Problems.TOKEN_REJECTED);
    exception.setParameter(OAuth.OAUTH_TOKEN, requestToken);
    throw exception;
  }
  return accessor.clone();
}
 
Example 6
Source File: DataApiTokenContainer.java    From swellrt with Apache License 2.0 5 votes vote down vote up
/**
 * Gets the authorized {@link OAuthAccessor} that is identified by the given
 * access token. Any changes made to the accessor's fields, except the
 * consumer, will not be reflected in this container.
 *
 * @param accessToken the access token used for identification.
 * @throws OAuthProblemException if the token does not map to an accessor.
 */
public OAuthAccessor getAccessTokenAccessor(String accessToken) throws OAuthProblemException {
  OAuthAccessor accessor = accessTokenAccessors.get(accessToken);
  if (accessor == null) {
    OAuthProblemException exception =
        OAuthUtil.newOAuthProblemException(OAuth.Problems.TOKEN_REJECTED);
    exception.setParameter(OAuth.OAUTH_TOKEN, accessToken);
    throw exception;
  }
  return accessor.clone();
}
 
Example 7
Source File: DataApiTokenContainer.java    From swellrt with Apache License 2.0 5 votes vote down vote up
/**
 * Generates a new request token for the given {@link OAuthConsumer}.
 *
 * @param consumer the consumer to generate the token for.
 */
public OAuthAccessor generateRequestToken(OAuthConsumer consumer) {
  Preconditions.checkNotNull(consumer, "Consumer must not be null");

  // Accessor can be generated up front with a token secret that does not need
  // to be unique.
  OAuthAccessor accessor = new OAuthAccessor(consumer);
  accessor.tokenSecret = generateToken();

  do {
    accessor.requestToken = generateToken();
  } while (requestTokenAccessors.putIfAbsent(accessor.requestToken, accessor) != null);

  return accessor.clone();
}
 
Example 8
Source File: DataApiTokenContainer.java    From incubator-retired-wave with Apache License 2.0 5 votes vote down vote up
/**
 * Gets the {@link OAuthAccessor} that is identified by the given request
 * token. Any changes made to the accessor's fields, except the consumer, will
 * not be reflected in this container.
 *
 * @param requestToken the request token used for identification.
 * @throws OAuthProblemException if the token does not map to an accessor.
 */
public OAuthAccessor getRequestTokenAccessor(String requestToken) throws OAuthProblemException {
  OAuthAccessor accessor = requestTokenAccessors.get(requestToken);
  if (accessor == null) {
    OAuthProblemException exception =
        OAuthUtil.newOAuthProblemException(OAuth.Problems.TOKEN_REJECTED);
    exception.setParameter(OAuth.OAUTH_TOKEN, requestToken);
    throw exception;
  }
  return accessor.clone();
}
 
Example 9
Source File: DataApiTokenContainer.java    From incubator-retired-wave with Apache License 2.0 5 votes vote down vote up
/**
 * Gets the authorized {@link OAuthAccessor} that is identified by the given
 * access token. Any changes made to the accessor's fields, except the
 * consumer, will not be reflected in this container.
 *
 * @param accessToken the access token used for identification.
 * @throws OAuthProblemException if the token does not map to an accessor.
 */
public OAuthAccessor getAccessTokenAccessor(String accessToken) throws OAuthProblemException {
  OAuthAccessor accessor = accessTokenAccessors.get(accessToken);
  if (accessor == null) {
    OAuthProblemException exception =
        OAuthUtil.newOAuthProblemException(OAuth.Problems.TOKEN_REJECTED);
    exception.setParameter(OAuth.OAUTH_TOKEN, accessToken);
    throw exception;
  }
  return accessor.clone();
}
 
Example 10
Source File: DataApiTokenContainer.java    From incubator-retired-wave with Apache License 2.0 5 votes vote down vote up
/**
 * Generates a new request token for the given {@link OAuthConsumer}.
 *
 * @param consumer the consumer to generate the token for.
 */
public OAuthAccessor generateRequestToken(OAuthConsumer consumer) {
  Preconditions.checkNotNull(consumer, "Consumer must not be null");

  // Accessor can be generated up front with a token secret that does not need
  // to be unique.
  OAuthAccessor accessor = new OAuthAccessor(consumer);
  accessor.tokenSecret = generateToken();

  do {
    accessor.requestToken = generateToken();
  } while (requestTokenAccessors.putIfAbsent(accessor.requestToken, accessor) != null);

  return accessor.clone();
}