risdenk commented on a change in pull request #205: KNOX-2134 - Add caching to 
ZookeeperRemoteAliasService
URL: https://github.com/apache/knox/pull/205#discussion_r349760890
 
 

 ##########
 File path: 
gateway-server/src/main/java/org/apache/knox/gateway/services/security/impl/ZookeeperRemoteAliasService.java
 ##########
 @@ -228,35 +239,46 @@ public void removeAliasForCluster(final String 
clusterName, final String alias)
   }
 
   @Override
-  public char[] getPasswordFromAliasForCluster(String clusterName,
-      String alias, boolean generate) throws AliasServiceException {
+  public char[] getPasswordFromAliasForCluster(String clusterName, String 
alias, boolean generate)
+      throws AliasServiceException {
 
     char[] password = null;
 
-    /* try to get it from remote registry */
-    if (remoteClient != null) {
-      checkPathsExist(remoteClient);
-      String encrypted = null;
-
-      if(remoteClient.entryExists(buildAliasEntryName(clusterName, alias))) {
-        encrypted = remoteClient
-            .getEntryData(buildAliasEntryName(clusterName, alias));
+    // Try the local cache first
+    if (aliasCache.containsKey(clusterName)) {
+      String value = aliasCache.get(clusterName).get(alias);
+      if (value != null) {
+        password = value.toCharArray();
       }
+    }
 
-      /* Generate a new password */
-      if (encrypted == null) {
+    // If it wasn't found in the local cache, check the remote registry
+    if (password == null) {
+      /* try to get it from remote registry */
+      if (remoteClient != null) {
+        checkPathsExist(remoteClient);
+        String encrypted = null;
 
-        /* Generate a new password  */
-        if (generate) {
-          generateAliasForCluster(clusterName, alias);
-          password = getPasswordFromAliasForCluster(clusterName, alias);
+        if (remoteClient.entryExists(buildAliasEntryName(clusterName, alias))) 
{
+          encrypted = remoteClient
+              .getEntryData(buildAliasEntryName(clusterName, alias));
         }
 
-      } else {
-        try {
-          password = decrypt(encrypted).toCharArray();
-        } catch (final Exception e) {
-          throw new AliasServiceException(e);
+        /* Generate a new password */
+        if (encrypted == null) {
+
+          /* Generate a new password  */
+          if (generate) {
+            generateAliasForCluster(clusterName, alias);
+            password = getPasswordFromAliasForCluster(clusterName, alias);
+          }
+
+        } else {
+          try {
+            password = decrypt(encrypted).toCharArray();
+          } catch (final Exception e) {
+            throw new AliasServiceException(e);
+          }
 
 Review comment:
   I need to look at this in more detail - probably in an IDE. Just noting to 
myself to look closer.

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