Ejemplo n.º 1
0
  @Override
  public DeviceCode readDeviceCode(String userCode, OAuth2Request request)
      throws ServerException, NotFoundException, InvalidGrantException {
    try {
      JsonValue token = tokenStore.query(equalTo(CoreTokenField.STRING_FOURTEEN, userCode));

      if (token.size() != 1) {
        throw new InvalidGrantException();
      }

      DeviceCode deviceCode = new DeviceCode(json(token.asSet().iterator().next()));
      request.setToken(DeviceCode.class, deviceCode);
      return deviceCode;
    } catch (CoreTokenException e) {
      logger.error("Unable to read device code corresponding to id: " + userCode, e);
      throw new ServerException("Could not read token in CTS: " + e.getMessage());
    }
  }
  /** {@inheritDoc} */
  public ConfirmationCallback convertFromJson(ConfirmationCallback callback, JsonValue jsonCallback)
      throws RestAuthException {

    validateCallbackType(CALLBACK_NAME, jsonCallback);

    JsonValue input = jsonCallback.get("input");

    if (input.size() != 1) {
      throw new JsonException("JSON Callback does not include a input field");
    }

    JsonValue inputFieldValue = input.get(0).get("value").required();
    int value;
    if (inputFieldValue.isString()) {
      value = Integer.parseInt(inputFieldValue.asString());
    } else {
      value = inputFieldValue.asInteger();
    }
    callback.setSelectedIndex(value);

    return callback;
  }