Package org.brickred.socialauth.exception

Examples of org.brickred.socialauth.exception.SignatureException


    LOG.debug("Given URL : " + url);
    LOG.debug("Given Parameters : " + args);
    if (HMACSHA1_SIGNATURE.equals(signatureType)) {
      return getHMACSHA1(method, url, args, token);
    } else {
      throw new SignatureException("Signature type not implemented :"
          + signatureType);
    }
  }
View Full Code Here


  private String getHMACSHA1(final String method, final String url,
      final Map<String, String> args, final AccessGrant token)
      throws Exception {

    if (config.get_consumerSecret().length() == 0) {
      throw new SignatureException("Please check consumer secret");
    }
    boolean valid = MethodType.GET.toString().equals(method)
        || MethodType.PUT.toString().equals(method)
        || MethodType.POST.toString().equals(method);
    if (!valid) {
      throw new SignatureException("Invalid method type :" + method);
    }
    if (url.length() == 0) {
      throw new SignatureException("Please check URL");
    }
    String key = HttpUtil.encodeURIComponent(config.get_consumerSecret())
        + "&";
    if (token != null && token.getSecret() != null) {
      key += HttpUtil.encodeURIComponent(token.getSecret());
    }
    try {
      // get an hmac_sha1 key from the raw key bytes
      SecretKeySpec signingKey = new SecretKeySpec(key.getBytes("UTF-8"),
          "HMAC-SHA1");

      // get an hmac_sha1 Mac instance and initialize with the signing key
      Mac mac = Mac.getInstance("HmacSHA1");
      mac.init(signingKey);

      String data = HttpUtil.encodeURIComponent(method) + "&"
          + HttpUtil.encodeURIComponent(url) + "&"
          + HttpUtil.encodeURIComponent(HttpUtil.buildParams(args));
      LOG.debug("Signature data : " + data);
      // compute the hmac on input data bytes
      byte[] rawHmac = mac.doFinal(data.getBytes("UTF-8"));

      // base64-encode the hmac
      LOG.debug("Encoding raw HMAC to Base64");
      String sig = Base64.encodeBytes(rawHmac);

      return sig;
    } catch (Exception e) {
      throw new SignatureException("Unable to generate HMAC-SHA1", e);
    }
  }
View Full Code Here

TOP

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

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.