From bd082de4f28d01ab01ecce142b65abfafff7663d Mon Sep 17 00:00:00 2001 From: roberto cirillo Date: Thu, 19 Nov 2020 15:12:56 +0100 Subject: [PATCH] added feature for retrieving a generic credential from a backend that is not mongodb --- .../storageclient/wrapper/Configuration.java | 11 ------- .../wrapper/ISClientConnector.java | 32 +++++++++++++------ 2 files changed, 22 insertions(+), 21 deletions(-) diff --git a/src/main/java/org/gcube/contentmanager/storageclient/wrapper/Configuration.java b/src/main/java/org/gcube/contentmanager/storageclient/wrapper/Configuration.java index 26e40aa..123e4c9 100644 --- a/src/main/java/org/gcube/contentmanager/storageclient/wrapper/Configuration.java +++ b/src/main/java/org/gcube/contentmanager/storageclient/wrapper/Configuration.java @@ -101,22 +101,11 @@ public class Configuration { */ public void getConfiguration(){ String[] newServer=null; -// ISClientConnector isclient=getISClient(); String currentScope=ScopeProvider.instance.get(); logger.debug("Scope found on ScopeProvider instance is "+currentScope); - -/*COMMENTED THE FOLLOWING LINES 20181214*/ - if(RRScope == null){ -// if(new ScopeBean(currentScope).is(Type.VRE)){ -// logger.debug("If ScopeProvider scope is VRE scope RR scope became VO scope"); -// RRScope=new ScopeBean(currentScope).enclosingScope().toString(); -// }else{ -// logger.debug("If ScopeProvider scope is not a VRE scope RR scope is ScopeProvider scope"); RRScope=currentScope; -// } } -/*END*/ logger.debug("RuntimeResource scope "+RRScope); ServiceEndpoint resource=getISClient().getStorageEndpoint(RRScope); if(resource ==null ) diff --git a/src/main/java/org/gcube/contentmanager/storageclient/wrapper/ISClientConnector.java b/src/main/java/org/gcube/contentmanager/storageclient/wrapper/ISClientConnector.java index 1625ce2..30e1831 100644 --- a/src/main/java/org/gcube/contentmanager/storageclient/wrapper/ISClientConnector.java +++ b/src/main/java/org/gcube/contentmanager/storageclient/wrapper/ISClientConnector.java @@ -10,6 +10,7 @@ import java.util.List; import java.util.Map; import org.gcube.common.encryption.StringEncrypter; import org.gcube.common.resources.gcore.ServiceEndpoint.AccessPoint; +import org.gcube.contentmanager.storageclient.wrapper.BackendType; import org.gcube.common.resources.gcore.ServiceEndpoint; import org.gcube.common.resources.gcore.ServiceEndpoint.Property; import org.gcube.common.scope.api.ScopeProvider; @@ -92,17 +93,15 @@ public class ISClientConnector { server[i] = ap.address(); // if presents, try to get user and password setUsername(ap.username()); - // set password default value to empty string - setPassword(""); - if(getUsername() != null && getUsername().length() > 0){ - try { - setPassword(StringEncrypter.getEncrypter().decrypt(ap.password())); - } catch (Exception e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } + decryptPwd(ap); i++; + }else if((!getBackendType().equals(BackendType.MongoDB) && (ap.name().equals(getBackendType())))){ + // in this case, the backend type has been set in the constructor hence we want to use this one + // if presents, try to get user and password + setUsername(ap.username()); + decryptPwd(ap); + //in v1.6.0 we are considering only one accessPoint for a backend except for mongodb. + break; } } setBackendType(retrievePropertyValue(resource, "type")); @@ -117,6 +116,19 @@ public class ISClientConnector { } } + private void decryptPwd(AccessPoint ap) { + // set password default value to empty string + setPassword(""); + if(getUsername() != null && getUsername().length() > 0){ + try { + setPassword(StringEncrypter.getEncrypter().decrypt(ap.password())); + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + } + private ServiceEndpoint getPriorityResource(List resources) { ServiceEndpoint defaultResource=null; logger.info("search RR with priority ");