You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@knox.apache.org by GitBox <gi...@apache.org> on 2019/03/14 09:59:18 UTC

[GitHub] [knox] smolnar82 commented on a change in pull request #72: KNOX-1820 - Cleanup KeystoreService implementations and add unit tests

smolnar82 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_r265490269
 
 

 ##########
 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:
   These two `catch`-es could be merged into one (just like you did it below in `createKeyStore`)

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services