Enhanced version

This commit is contained in:
Luca Frosini 2019-09-19 15:31:58 +02:00
parent 65c2fa264a
commit 3db0d61283
2 changed files with 25 additions and 12 deletions

View File

@ -11,7 +11,7 @@
<groupId>org.gcube.data.access</groupId>
<artifactId>ckan-connector</artifactId>
<version>1.1.2-SNAPSHOT</version>
<version>1.2.0-SNAPSHOT</version>
<packaging>war</packaging>
<name>ckan connector</name>
<description>a ckan connector for automatic login</description>

View File

@ -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());