Examples of OAuth2RequestException


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);
    }

    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);
    }

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

    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(), error.getUri(), error.getDescription());
        }
      }
    }

    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

public class CodeGrantTypeHandler implements GrantRequestHandler {
  private static final OAuth2Error ERROR = OAuth2Error.CODE_GRANT_PROBLEM;

  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());
    final String redirectUri = accessor.getRedirectUri();
    if (redirectUri != null && redirectUri.length() > 0) {
      queryParams.put(OAuth2Message.REDIRECT_URI, redirectUri);
    }

    final OAuth2CallbackState state = accessor.getState();
    if (state != null) {
      try {
        queryParams.put(OAuth2Message.STATE, state.getEncryptedState());
      } catch (final BlobCrypterException e) {
        throw new OAuth2RequestException(OAuth2Error.CODE_GRANT_PROBLEM, "encryption problem", e);
      }
    }

    final String scope = accessor.getScope();
    if (scope != null && scope.length() > 0) {
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);
    }

    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);
    }

    final HttpRequest request = new HttpRequest(Uri.parse(completeAuthorizationUrl));
    request.setMethod("POST");
    request.setHeader("Content-Type", "application/x-www-form-urlencoded; charset=utf-8");
    request.setSecurityToken(new AnonymousSecurityToken("", 0L, accessor.getGadgetUri()));

    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(), error.getUri(), error.getDescription());
        }
      }
    }

    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
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.