Package org.brickred.socialauth.exception

Examples of org.brickred.socialauth.exception.SocialAuthException


   */
  @Override
  public Response uploadImage(final String message, final String fileName,
      final InputStream inputStream) throws Exception {
    LOG.warn("WARNING: Not implemented for GenericOauth1Provider");
    throw new SocialAuthException(
        "Upload Image is not implemented for GenericOauth1Provider");
  }
View Full Code Here


          break;
        }
      }
      LOG.debug("ASSOCCIATION : " + assocHandle);
    } catch (Exception exc) {
      throw new SocialAuthException("Failed to read response from  ");
    }

    String realm;
    if (successUrl.indexOf("/", 9) > 0) {
      realm = successUrl.substring(0, successUrl.indexOf("/", 9));
View Full Code Here

    if (config.getProviderImplClass() != null) {
      providersImplMap.put(providerId, config.getProviderImplClass());
      domainMap.put(providerId, providerId);
    }
    if (!providersImplMap.containsKey(providerId)) {
      throw new SocialAuthException("Provider Impl class not found");
    } else if (config.getProviderImplClass() == null) {
      config.setProviderImplClass(providersImplMap.get(providerId));
    }
    configSetup = true;
  }
View Full Code Here

  }

  @Override
  public Response executeFeed(final String url) throws Exception {
    if (accessToken == null) {
      throw new SocialAuthException(
          "Please call verifyResponse function first to get Access Token");
    }
    return oauth.httpGet(url, null, accessToken);
  }
View Full Code Here

      final Map<String, String> params,
      final Map<String, String> headerParams, final String body)
      throws Exception {
    Response response = null;
    if (accessToken == null) {
      throw new SocialAuthException(
          "Please call verifyResponse function first to get Access Token");
    }
    if (MethodType.GET.toString().equals(methodType)) {
      try {
        response = oauth.httpGet(url, headerParams, accessToken);
      } catch (Exception ie) {
        throw new SocialAuthException(
            "Error while making request to URL : " + url, ie);
      }
    } else if (MethodType.PUT.toString().equals(methodType)) {
      try {
        response = oauth.httpPut(url, params, headerParams, body,
            accessToken);
      } catch (Exception e) {
        throw new SocialAuthException(
            "Error while making request to URL : " + url, e);
      }
    }
    return response;
  }
View Full Code Here

        config = getProviderConfig(Constants.OPENID);
        if (config != null) {
          config.setId(id);
        }
      } catch (MalformedURLException me) {
        throw new SocialAuthException(id
            + " is not a provider or valid OpenId URL");
      }
    }
    if (config == null) {
      throw new SocialAuthConfigurationException("Configuration of " + id
View Full Code Here

    LOG.info("Verifying the authentication response from provider");
    if (!providerState) {
      throw new ProviderStateException();
    }
    if (requestToken == null) {
      throw new SocialAuthException("Request token is null");
    }
    String verifier = requestParams.get(Constants.OAUTH_VERIFIER);
    if (verifier != null) {
      requestToken.setAttribute(Constants.OAUTH_VERIFIER, verifier);
    }
View Full Code Here

      final Map<String, String> params,
      final Map<String, String> headerParams, final String body)
      throws Exception {
    Response response = null;
    if (accessToken == null) {
      throw new SocialAuthException(
          "Please call verifyResponse function first to get Access Token");
    }
    if (MethodType.GET.toString().equals(methodType)) {
      try {
        response = oauth.httpGet(urlStr, headerParams, accessToken);
      } catch (Exception ie) {
        throw new SocialAuthException(
            "Error while making request to URL : " + urlStr, ie);
      }
    } else if (MethodType.PUT.toString().equals(methodType)) {
      try {
        response = oauth.httpPut(urlStr, params, headerParams, body,
            accessToken);
      } catch (Exception e) {
        throw new SocialAuthException(
            "Error while making request to URL : " + urlStr, e);
      }
    } else if (MethodType.POST.toString().equals(methodType)) {
      try {
        response = oauth.httpPost(urlStr, params, headerParams, body,
            accessToken);
      } catch (Exception e) {
        throw new SocialAuthException(
            "Error while making request to URL : " + urlStr, e);
      }
    }
    return response;
  }
View Full Code Here

      throw new ProviderStateException();
    }

    String code = requestParams.get("code");
    if (code == null || code.length() == 0) {
      throw new SocialAuthException("Verification code is null");
    }
    LOG.debug("Verification Code : " + code);
    String acode;
    String accessToken = null;
    try {
      acode = URLEncoder.encode(code, "UTF-8");
    } catch (Exception e) {
      acode = code;
    }
    StringBuffer sb = new StringBuffer();
    if (MethodType.GET.toString().equals(methodType)) {
      sb.append(endpoints.get(Constants.OAUTH_ACCESS_TOKEN_URL));
      char separator = endpoints.get(Constants.OAUTH_ACCESS_TOKEN_URL)
          .indexOf('?') == -1 ? '?' : '&';
      sb.append(separator);
    }
    sb.append("client_id=").append(oauth.getConfig().get_consumerKey());
    sb.append("&redirect_uri=").append(this.successUrl);
    sb.append("&client_secret=").append(
        oauth.getConfig().get_consumerSecret());
    sb.append("&code=").append(acode);
    sb.append("&grant_type=authorization_code");

    Response response;
    String authURL = null;
    try {
      if (MethodType.GET.toString().equals(methodType)) {
        authURL = sb.toString();
        LOG.debug("URL for Access Token request : " + authURL);
        response = HttpUtil.doHttpRequest(authURL, methodType, null,
            null);
      } else {
        authURL = endpoints.get(Constants.OAUTH_ACCESS_TOKEN_URL);
        LOG.debug("URL for Access Token request : " + authURL);
        response = HttpUtil.doHttpRequest(authURL, methodType,
            sb.toString(), null);
      }
    } catch (Exception e) {
      throw new SocialAuthException("Error in url : " + authURL, e);
    }
    String result;
    try {
      result = response.getResponseBodyAsString(Constants.ENCODING);
    } catch (IOException io) {
      throw new SocialAuthException(io);
    }
    Map<String, Object> attributes = new HashMap<String, Object>();
    Integer expires = null;
    if (result.indexOf("{") < 0) {
      String[] pairs = result.split("&");
      for (String pair : pairs) {
        String[] kv = pair.split("=");
        if (kv.length != 2) {
          throw new SocialAuthException(
              "Unexpected auth response from " + authURL);
        } else {
          if (kv[0].equals("access_token")) {
            accessToken = kv[1];
          } else if (kv[0].equals("expires")) {
            expires = Integer.valueOf(kv[1]);
          } else if (kv[0].equals("expires_in")) {
            expires = Integer.valueOf(kv[1]);
          } else {
            attributes.put(kv[0], kv[1]);
          }
        }
      }
    } else {
      try {
        JSONObject jObj = new JSONObject(result);
        if (jObj.has("access_token")) {
          accessToken = jObj.getString("access_token");
        }
        if (jObj.has("expires_in")) {
          String str = jObj.getString("expires_in");
          if (str != null && str.length() > 0) {
            expires = Integer.valueOf(str);
          }
        }
        if (accessToken != null) {
          Iterator<String> keyItr = jObj.keys();
          while (keyItr.hasNext()) {
            String key = keyItr.next();
            if (!"access_token".equals(key)
                && !"expires_in".equals(key)) {
              attributes.put(key, jObj.optString(key));
            }
          }
        }
      } catch (JSONException je) {
        throw new SocialAuthException("Unexpected auth response from "
            + authURL);
      }
    }
    LOG.debug("Access Token : " + accessToken);
    LOG.debug("Expires : " + expires);
    if (accessToken != null) {
      accessGrant = new AccessGrant();
      accessGrant.setKey(accessToken);
      accessGrant.setAttribute(Constants.EXPIRES, expires);
      if (attributes.size() > 0) {
        accessGrant.setAttributes(attributes);
      }
      if (permission != null) {
        accessGrant.setPermission(permission);
      } else {
        accessGrant.setPermission(Permission.ALL);
      }
      accessGrant.setProviderId(providerId);
    } else {
      throw new SocialAuthException(
          "Access token and expires not found from " + authURL);
    }
    return accessGrant;
  }
View Full Code Here

  }

  @Override
  public Response executeFeed(final String url) throws Exception {
    if (accessGrant == null) {
      throw new SocialAuthException(
          "Please call verifyResponse function first to get Access Token");
    }
    char separator = url.indexOf('?') == -1 ? '?' : '&';
    String urlStr = url + separator + accessTokenParameterName + "="
        + accessGrant.getKey();
View Full Code Here

TOP

Related Classes of org.brickred.socialauth.exception.SocialAuthException

Copyright © 2018 www.massapicom. 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.