diff --git a/pom.xml b/pom.xml
index 2052fa0..0229545 100644
--- a/pom.xml
+++ b/pom.xml
@@ -11,7 +11,7 @@
org.gcube.data.access
ckan-connector
- 1.1.2-SNAPSHOT
+ 1.2.0-SNAPSHOT
war
ckan connector
a ckan connector for automatic login
diff --git a/src/main/java/org/gcube/data/access/ckanconnector/ConnectorManager.java b/src/main/java/org/gcube/data/access/ckanconnector/ConnectorManager.java
index 00bedbf..e580eeb 100644
--- a/src/main/java/org/gcube/data/access/ckanconnector/ConnectorManager.java
+++ b/src/main/java/org/gcube/data/access/ckanconnector/ConnectorManager.java
@@ -20,6 +20,7 @@ import lombok.extern.slf4j.Slf4j;
import org.gcube.common.authorization.library.provider.AuthorizationProvider;
import org.gcube.common.scope.api.ScopeProvider;
+import org.gcube.gcat.client.User;
import org.python.core.PyLong;
import org.python.core.PyObject;
import org.python.core.PyString;
@@ -82,22 +83,34 @@ public class ConnectorManager {
String ckanKey = context.getInitParameter("ckanKey");
String originalUserName = AuthorizationProvider.instance.get().getClient().getId();
String changedUserName = originalUserName.replace(".", "_");
+
+
+
int internalPort = Integer.parseInt(context.getInitParameter("internalPort"));
String localhostName = "http://127.0.0.1:"+internalPort;
long startCheckUser = System.currentTimeMillis();
CkanClient ckanClient = new CkanClient(localhostName, ckanKey);
- CkanUser user = null;
- try{
- user = ckanClient.getUser(changedUserName);
- }catch(Exception e){
- log.warn("user {} doesn't exist, the system will create it",originalUserName, e);
- }
- log.info("checking user took {}",(System.currentTimeMillis()-startCheckUser));
- if (user==null){
- long startCreateUser = System.currentTimeMillis();
- user = ckanClient.createUser(new CkanUser(changedUserName, originalUserName+"@gcube.ckan.org" , randomString.nextString() ));
- log.info("create user took {}",(System.currentTimeMillis()-startCreateUser));
+
+
+ try {
+ User user = new User();
+ user.read(changedUserName);
+ }catch (Exception ex) {
+ log.error("Error while contacting gCat. The old code will made the work", ex);
+ CkanUser user = null;
+ try{
+ user = ckanClient.getUser(changedUserName);
+ }catch(Exception e){
+ log.warn("user {} doesn't exist, the system will create it",originalUserName, e);
+ }
+ log.info("checking user took {}",(System.currentTimeMillis()-startCheckUser));
+ if (user==null){
+ long startCreateUser = System.currentTimeMillis();
+ user = ckanClient.createUser(new CkanUser(changedUserName, originalUserName+"@gcube.ckan.org" , randomString.nextString() ));
+ log.info("create user took {}",(System.currentTimeMillis()-startCreateUser));
+ }
}
+
addUserToVres(vres, changedUserName, ckanClient, ckanKey, localhostName);
log.info("logging {} in scope {}",originalUserName, ScopeProvider.instance.get());