risdenk commented on a change in pull request #72: KNOX-1820 - Cleanup 
KeystoreService implementations and add unit tests
URL: https://github.com/apache/knox/pull/72#discussion_r265647540
 
 

 ##########
 File path: 
gateway-server/src/main/java/org/apache/knox/gateway/services/security/impl/DefaultKeystoreService.java
 ##########
 @@ -473,13 +482,113 @@ private KeyStore getKeystore(Path keystorePath, String 
keystoreType, String alia
 
     readLock.lock();
     try {
-      return getKeystore(keystoreFile, keystoreType, 
getKeystorePassword(alias));
+      return loadKeyStore(keystorePath, keystoreType, 
getKeyStorePassword(alias));
     } finally {
       readLock.unlock();
     }
   }
 
-  private char[] getKeystorePassword(String alias) throws 
KeystoreServiceException {
+  private boolean isKeyStoreAvailable(final Path keyStoreFilePath, String 
storeType, char[] password) throws KeyStoreException, IOException {
+    if (keyStoreFilePath.toFile().exists()) {
+      try (InputStream input = Files.newInputStream(keyStoreFilePath)) {
+        final KeyStore keyStore = KeyStore.getInstance(storeType);
+        keyStore.load(input, password);
+        return true;
+      } catch (NoSuchAlgorithmException | CertificateException e) {
+        LOG.failedToLoadKeystore(keyStoreFilePath.toString(), storeType, e);
+      } catch (IOException | KeyStoreException e) {
+        LOG.failedToLoadKeystore(keyStoreFilePath.toString(), storeType, e);
+        throw e;
 
 Review comment:
   Hmmm not sure why there are two catches. I'd have to check where this is 
copied from. If they are two different cases, I would expect two different log 
messages. I think we should either throw an Exception or not in both cases to 
be consistent. Not sure if throwing the exception is a good idea?

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to