airavata-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From machris...@apache.org
Subject [airavata-custos] 04/24: Fixing the issue in VaultManager to retrieve correct credential
Date Fri, 11 Oct 2019 20:42:11 GMT
This is an automated email from the ASF dual-hosted git repository.

machristie pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/airavata-custos.git

commit 0c1750cbaefada3d107cae7ff74faf9d37a51cb1
Author: Dimuthu Wannipurage <dimuthu.upeksha2@gmail.com>
AuthorDate: Tue Jul 9 01:48:23 2019 -0400

    Fixing the issue in VaultManager to retrieve correct credential
---
 .../java/org/apache/airavata/custos/vault/VaultManager.java | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/credential-store/credential-core/src/main/java/org/apache/airavata/custos/vault/VaultManager.java
b/credential-store/credential-core/src/main/java/org/apache/airavata/custos/vault/VaultManager.java
index 4e4baf4..4e333c0 100644
--- a/credential-store/credential-core/src/main/java/org/apache/airavata/custos/vault/VaultManager.java
+++ b/credential-store/credential-core/src/main/java/org/apache/airavata/custos/vault/VaultManager.java
@@ -10,6 +10,7 @@ import org.apache.airavata.custos.vault.annotations.VaultPath;
 import org.springframework.stereotype.Service;
 
 import javax.annotation.PostConstruct;
+import java.lang.reflect.Constructor;
 import java.lang.reflect.Field;
 import java.util.*;
 
@@ -27,25 +28,29 @@ public class VaultManager {
         vault = new Vault(config);
     }
 
-    public <T extends BaseCredentialEntity> T getCredentialEntity(Class<T> calzz,
final String token, final String gateway) throws Exception {
+    public <T extends BaseCredentialEntity> T getCredentialEntity(Class<T> clazz,
final String token, final String gateway) throws Exception {
 
         Map<String, String> params = new HashMap<String, String>() {{
             put("token", token);
             put("gateway", gateway);
         }};
 
-        for (Class<?> c = calzz; c != null; c = c.getSuperclass()) {
+        Constructor<T> ctor = clazz.getConstructor();
+        T obj = ctor.newInstance();
+
+        for (Class<?> c = clazz; c != null; c = c.getSuperclass()) {
             Field[] fields = c.getDeclaredFields();
             for (Field field : fields) {
                 VaultPath vaultPathAnnotation = field.getAnnotation(VaultPath.class);
                 if (vaultPathAnnotation != null) {
                     String path = populatePathWithParams(vaultPathAnnotation.path(), params);
                     Map<String,String> data = vault.logical().read(path).getData();
-                    System.out.println("Value for key " + vaultPathAnnotation.name() + "
" + data.get(vaultPathAnnotation.name()));
+                    field.setAccessible(true);
+                    field.set(obj, data.get(vaultPathAnnotation.name()));
                 }
             }
         }
-        return null;
+        return obj;
     }
 
     public <T extends BaseCredentialEntity> String saveCredentialEntity(final T credentialEntity,
final String gateway) throws Exception {


Mime
View raw message