Merged remote-tracking branch 'origin/feature/16359'

This commit is contained in:
Luca Frosini 2019-09-27 11:50:33 +02:00
commit 6e3f89992b
3 changed files with 38 additions and 14 deletions

13
pom.xml
View File

@ -1,16 +1,17 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>maven-parent</artifactId>
<groupId>org.gcube.tools</groupId>
<version>1.1.0-SNAPSHOT</version>
<version>1.1.0</version>
</parent>
<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>
@ -80,6 +81,12 @@
<version>3.0.1</version>
</dependency>
<dependency>
<groupId>org.gcube.data-publishing</groupId>
<artifactId>gcat-client</artifactId>
<version>[1.0.0-SNAPSHOT, 2.0.0-SNAPSHOT)</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>

4
src/main/.gitignore vendored
View File

@ -1 +1,5 @@
<<<<<<< HEAD
webapp/
=======
webapp
>>>>>>> refs/remotes/origin/feature/16359

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 (Throwable tr) {
log.error("Error while contacting gCat. The old code will made the work", tr);
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());