Examples of OAuth2RequestException


Examples of org.apache.shindig.gadgets.oauth2.OAuth2RequestException

  public void setMacSecret(byte[] secret) throws OAuth2RequestException {
    this.macSecret = secret;
    try {
      this.encryptedMacSecret = this.encrypter.encrypt(secret);
    } catch (final OAuth2EncryptionException e) {
      throw new OAuth2RequestException(OAuth2Error.SECRET_ENCRYPTION_PROBLEM,
          "OAuth2TokenPersistence could not encrypt the mac secret", e);
    }
  }
View Full Code Here

Examples of org.apache.shindig.gadgets.oauth2.OAuth2RequestException

  public void setSecret(final byte[] secret) throws OAuth2RequestException {
    this.secret = secret;
    try {
      this.encryptedSecret = this.encrypter.encrypt(secret);
    } catch (final OAuth2EncryptionException e) {
      throw new OAuth2RequestException(OAuth2Error.SECRET_ENCRYPTION_PROBLEM,
          "OAuth2TokenPersistence could not encrypt the token secret", e);
    }
  }
View Full Code Here

Examples of org.apache.shindig.gadgets.oauth2.OAuth2RequestException

  @Inject
  public CodeGrantTypeHandler() {}

  public HttpRequest getAuthorizationRequest(final OAuth2Accessor accessor,
          final String completeAuthorizationUrl) throws OAuth2RequestException {
    throw new OAuth2RequestException(CodeGrantTypeHandler.ERROR,
            "inappropriate call to CodeGrantTypeHandler.getAuthorizationRequest()", null);
  }
View Full Code Here

Examples of org.apache.shindig.gadgets.oauth2.OAuth2RequestException

            "inappropriate call to CodeGrantTypeHandler.getAuthorizationRequest()", null);
  }

  public String getCompleteUrl(final OAuth2Accessor accessor) throws OAuth2RequestException {
    if (accessor == null) {
      throw new OAuth2RequestException(CodeGrantTypeHandler.ERROR, "accessor is null", null);
    }

    if (!accessor.isValid() || accessor.isErrorResponse() || accessor.isRedirecting()) {
      throw new OAuth2RequestException(CodeGrantTypeHandler.ERROR, "accessor is invalid", null);
    }

    if (!accessor.getGrantType().equalsIgnoreCase(OAuth2Message.AUTHORIZATION)) {
      throw new OAuth2RequestException(CodeGrantTypeHandler.ERROR, "grant type is not code", null);
    }

    final Map<String, String> queryParams = Maps.newHashMapWithExpectedSize(4);
    queryParams.put(OAuth2Message.RESPONSE_TYPE, this.getGrantType());
    queryParams.put(OAuth2Message.CLIENT_ID, accessor.getClientId());
View Full Code Here

Examples of org.apache.shindig.gadgets.oauth2.OAuth2RequestException

    final byte[] secretBytes = accessor.getClientSecret();
    String secret;
    try {
      secret = new String(secretBytes, "UTF-8");
    } catch (final UnsupportedEncodingException e) {
      throw new OAuth2RequestException(OAuth2Error.CLIENT_CREDENTIALS_PROBLEM,
              "error getting authorization body", e);
    }
    queryParams.put(OAuth2Message.CLIENT_ID, clientId);
    queryParams.put(OAuth2Message.CLIENT_SECRET, secret);
View Full Code Here

Examples of org.apache.shindig.gadgets.oauth2.OAuth2RequestException

  public HttpRequest getAuthorizationRequest(final OAuth2Accessor accessor,
          final String completeAuthorizationUrl) throws OAuth2RequestException {

    if ((completeAuthorizationUrl == null) || (completeAuthorizationUrl.length() == 0)) {
      throw new OAuth2RequestException(ClientCredentialsGrantTypeHandler.ERROR,
              "completeAuthorizationUrl is null", null);
    }

    final HttpRequest request = new HttpRequest(Uri.parse(completeAuthorizationUrl));
    request.setMethod("GET");
    request.setHeader("Content-Type", "application/x-www-form-urlencoded; charset=utf-8");

    if (accessor == null) {
      throw new OAuth2RequestException(ClientCredentialsGrantTypeHandler.ERROR, "accessor is null",
              null);
    }

    if (!accessor.isValid() || accessor.isErrorResponse() || accessor.isRedirecting()) {
      throw new OAuth2RequestException(ClientCredentialsGrantTypeHandler.ERROR,
              "accessor is invalid", null);
    }

    if (!accessor.getGrantType().equalsIgnoreCase(OAuth2Message.CLIENT_CREDENTIALS)) {
      throw new OAuth2RequestException(ClientCredentialsGrantTypeHandler.ERROR,
              "grant type is not client_credentials", null);
    }

    for (final ClientAuthenticationHandler clientAuthenticationHandler : this.clientAuthenticationHandlers) {
      if (clientAuthenticationHandler.geClientAuthenticationType().equalsIgnoreCase(
              accessor.getClientAuthenticationType())) {
        final OAuth2HandlerError error = clientAuthenticationHandler.addOAuth2Authentication(
                request, accessor);
        if (error != null) {
          throw new OAuth2RequestException(error.getError(), error.getContextMessage(),
                  error.getCause());
        }
      }
    }

    try {
      request.setPostBody(this.getAuthorizationBody(accessor).getBytes("UTF-8"));
    } catch (final UnsupportedEncodingException e) {
      throw new OAuth2RequestException(OAuth2Error.CLIENT_CREDENTIALS_PROBLEM,
              "ClientCredentialsGrantTypeHandler - exception setting post body", e);
    }

    return request;
  }
View Full Code Here

Examples of org.apache.shindig.gadgets.oauth2.OAuth2RequestException

  }

  public String getCompleteUrl(final OAuth2Accessor accessor) throws OAuth2RequestException {

    if (accessor == null) {
      throw new OAuth2RequestException(ClientCredentialsGrantTypeHandler.ERROR, "accessor is null",
              null);
    }

    if (!accessor.isValid() || accessor.isErrorResponse() || accessor.isRedirecting()) {
      throw new OAuth2RequestException(ClientCredentialsGrantTypeHandler.ERROR,
              "accessor is invalid", null);
    }

    if (!accessor.getGrantType().equalsIgnoreCase(OAuth2Message.CLIENT_CREDENTIALS)) {
      throw new OAuth2RequestException(ClientCredentialsGrantTypeHandler.ERROR,
              "grant type is not client_credentials", null);
    }

    String ret;
    try {
      final Map<String, String> queryParams = Maps.newHashMapWithExpectedSize(4);
      queryParams.put(OAuth2Message.GRANT_TYPE, this.getGrantType());

      final String clientId = accessor.getClientId();
      final byte[] secretBytes = accessor.getClientSecret();
      final String secret = new String(secretBytes, "UTF-8");
      queryParams.put(OAuth2Message.CLIENT_ID, clientId);
      queryParams.put(OAuth2Message.CLIENT_SECRET, secret);

      final String scope = accessor.getScope();
      if ((scope != null) && (scope.length() > 0)) {
        queryParams.put(OAuth2Message.SCOPE, scope);
      }

      ret = OAuth2Utils.buildUrl(accessor.getTokenUrl(), queryParams, null);
    } catch (final UnsupportedEncodingException e) {
      throw new OAuth2RequestException(OAuth2Error.CLIENT_CREDENTIALS_PROBLEM,
              "problem getting complete url", e);
    }

    return ret;
  }
View Full Code Here

Examples of org.apache.shindig.gadgets.oauth2.OAuth2RequestException

            log.logp(Level.FINEST, CLASS, method, "accessToken has expired at {0}", new Object[]{expiresAt});
          }
          try {
            this.tokenStore.removeAccessToken(accessor);
          } catch (final GadgetException e) {
            throw new OAuth2RequestException(OAuth2Error.MISSING_SERVER_RESPONSE,
                "error removing access_token", null);
          }
          accessToken = null;
          accessor.setAccessToken(null);
          if (!lastAttempt) {
            return null;
          }
        }
      }
    }

    OAuth2Token refreshToken = accessor.getRefreshToken();
    if (refreshToken != null) {
      final long expiresAt = refreshToken.getExpiresAt();
      if (expiresAt != 0) {
        if (currentTime >= expiresAt) {
          if (log.isLoggable(Level.FINEST)) {
            log.logp(Level.FINEST, CLASS, method, "refreshToken has expired at {0}", new Object[]{expiresAt});
          }
          try {
            this.tokenStore.removeRefreshToken(accessor);
          } catch (final GadgetException e) {
            throw new OAuth2RequestException(OAuth2Error.MISSING_SERVER_RESPONSE,
                "error removing refresh_token", null);
          }
          refreshToken = null;
          accessor.setRefreshToken(null);
          if (!lastAttempt) {
            return null;
          }
        }
      }
    }

    if (accessToken != null) {
      final boolean isAllowed = isUriAllowed(request.getUri(), accessor.getAllowedDomains());
      if (isAllowed) {
        String tokenType = accessToken.getTokenType();
        if (tokenType == null || tokenType.length() == 0) {
          tokenType = OAuth2Message.BEARER_TOKEN_TYPE;
        }

        for (final ResourceRequestHandler resourceRequestHandler : this.resourceRequestHandlers) {
          if (tokenType.equalsIgnoreCase(resourceRequestHandler.getTokenType())) {
            resourceRequestHandler.addOAuth2Params(accessor, request);
          }
        }
      } else {
        log.logp(Level.WARNING, CLASS, method,
            "Gadget {0} attempted to send OAuth2 Token to an unauthorized domain: {1}.",
            new Object[] { accessor.getGadgetUri(), request.getUri() });
        throw new OAuth2RequestException(OAuth2Error.SERVER_REJECTED_REQUEST,
            "The accessor is not allowed to be sent to the domain of the request.", null);
      }
    }

    try {
      ret = this.fetcher.fetch(request);
    } catch (final GadgetException e) {
      throw new OAuth2RequestException(OAuth2Error.MISSING_SERVER_RESPONSE,
          "GadgetException fetchFromServer", e);
    }

    final int responseCode = ret.getHttpStatusCode();

    if (log.isLoggable(Level.FINEST)) {
      log.logp(Level.FINEST, CLASS, method, "responseCode = {0}", new Object[]{responseCode});
    }

    if (responseCode == HttpResponse.SC_UNAUTHORIZED) {
      if (accessToken != null) {
        try {
          this.tokenStore.removeAccessToken(accessor);
        } catch (final GadgetException e) {
          throw new OAuth2RequestException(OAuth2Error.MISSING_SERVER_RESPONSE,
              "error removing access_token", null);
        }
        accessor.setAccessToken(null);
      }
View Full Code Here

Examples of org.apache.shindig.gadgets.oauth2.OAuth2RequestException

    log.entering(CLASS, "lookupSpecInfo", new Object[] { securityToken, arguments, gadgetUri });

    final GadgetSpec spec = this.findSpec(securityToken, arguments, gadgetUri);
    final OAuth2Spec oauthSpec = spec.getModulePrefs().getOAuth2Spec();
    if (oauthSpec == null) {
      throw new OAuth2RequestException(OAuth2Error.LOOKUP_SPEC_PROBLEM,
          "Failed to retrieve OAuth URLs, spec for gadget " + securityToken.getAppUrl()
          + " does not contain OAuth element.", null);
    }
    final OAuth2Service service = oauthSpec.getServices().get(arguments.getServiceName());
    if (service == null) {
      throw new OAuth2RequestException(OAuth2Error.LOOKUP_SPEC_PROBLEM,
          "Failed to retrieve OAuth URLs, spec for gadget does not contain OAuth service "
              + arguments.getServiceName() + ".  Known services: "
              + Joiner.on(',').join(oauthSpec.getServices().keySet()) + '.', null);
    }
View Full Code Here

Examples of org.apache.shindig.gadgets.oauth2.OAuth2RequestException

    try {
      final GadgetContext context = new OAuth2GadgetContext(securityToken, arguments, gadgetUri);
      ret = this.specFactory.getGadgetSpec(context);
    } catch (final GadgetException e) {
      log.logp(Level.WARNING, CLASS, method, "Error finding GadgetContext " + gadgetUri.toString(), e);
      throw new OAuth2RequestException(OAuth2Error.GADGET_SPEC_PROBLEM, gadgetUri.toString(), e);
    }

    // this is cumbersome in the logs, just return whether or not it's null
    if (ret == null) {
      log.exiting(CLASS, method, null);
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.