google / identity-toolkit-java-client

Google Identity Toolkit client library for Java
Apache License 2.0
37 stars 27 forks source link

Exception handleling on RpcHelper needs improvements #15

Closed hernanliendo closed 9 years ago

hernanliendo commented 9 years ago

The initRsaSHA256Signer method on RpcHelper hides exceptions important information when doing things like

log.warning("can not initialize service account signer: " + e);

a better way to do it would be

log.warning("can not initialize service account signer: " + e, e);

Reference code:

  private RsaSHA256Signer initRsaSHA256Signer(String serviceAccountEmail, InputStream keyStream) {
    try {
      if (serviceAccountEmail != null && keyStream != null) {
        KeyStore keyStore = KeyStore.getInstance("PKCS12");
        keyStore.load(keyStream, "notasecret".toCharArray());
        return new RsaSHA256Signer(
            serviceAccountEmail,
            null,
            (RSAPrivateKey) keyStore.getKey("privatekey", "notasecret".toCharArray()));
      }
    } catch (KeyStoreException e) {
      log.warning("can not initialize service account signer: " + e);
    } catch (CertificateException e) {
      log.warning("can not initialize service account signer: " + e);
    } catch (UnrecoverableKeyException e) {
      log.warning("can not initialize service account signer: " + e);
    } catch (NoSuchAlgorithmException e) {
      log.warning("can not initialize service account signer: " + e);
    } catch (IOException e) {
      log.warning("can not initialize service account signer: " + e);
    } catch (InvalidKeyException e) {
      log.warning("can not initialize service account signer: " + e);
    }
    log.warning("service account is set to null due to: email = " + serviceAccountEmail
        + "keystream = " + keyStream);
    return null;
  }
hernanliendo commented 9 years ago

Just added a patch for it here https://github.com/hernanliendo/identity-toolkit-java-client

commit diff is https://github.com/hernanliendo/identity-toolkit-java-client/commit/aad7dc8fd099917a11e9b4d34e7e321a19a3a4f7

dereksalama commented 9 years ago

Thanks for the patch!