From 93917d59c84f4b0db1e00b4ccfbfaa25182bc8b1 Mon Sep 17 00:00:00 2001 From: Lucio Lelii Date: Mon, 3 Oct 2016 10:43:47 +0000 Subject: [PATCH] branch for release 4.1 git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/branches/data-analysis/RConnector/2.1@132340 82a268e6-3cf1-43bd-a215-b396298e98cf --- .classpath | 36 ++++ .project | 23 +++ .settings/org.eclipse.jdt.core.prefs | 5 + .settings/org.eclipse.m2e.core.prefs | 4 + distro/LICENSE | 4 + distro/README | 66 +++++++ distro/changelog.xml | 20 +++ distro/descriptor.xml | 32 ++++ distro/profile.xml | 26 +++ pom.xml | 170 ++++++++++++++++++ .../analysis/rconnector/ConfigFileWriter.java | 91 ++++++++++ .../rconnector/DisconnectResource.java | 48 +++++ .../gcube/data/analysis/rconnector/Info.java | 22 +++ .../analysis/rconnector/InfoRetriever.java | 98 ++++++++++ .../data/analysis/rconnector/RConnector.java | 15 ++ .../data/analysis/rconnector/Resource.java | 116 ++++++++++++ src/main/resources/META-INF/beans.xml | 5 + src/main/resources/inactivesession.html | 4 + src/main/resources/logout.html | 8 + src/main/resources/open.html | 13 ++ src/main/webapp/WEB-INF/gcube-app.xml | 12 ++ src/main/webapp/WEB-INF/web.xml | 29 +++ .../data/analysis/rconnector/TestCall.java | 22 +++ src/test/resources/logback.xml | 16 ++ 24 files changed, 885 insertions(+) create mode 100644 .classpath create mode 100644 .project create mode 100644 .settings/org.eclipse.jdt.core.prefs create mode 100644 .settings/org.eclipse.m2e.core.prefs create mode 100644 distro/LICENSE create mode 100644 distro/README create mode 100644 distro/changelog.xml create mode 100644 distro/descriptor.xml create mode 100644 distro/profile.xml create mode 100644 pom.xml create mode 100644 src/main/java/org/gcube/data/analysis/rconnector/ConfigFileWriter.java create mode 100644 src/main/java/org/gcube/data/analysis/rconnector/DisconnectResource.java create mode 100644 src/main/java/org/gcube/data/analysis/rconnector/Info.java create mode 100644 src/main/java/org/gcube/data/analysis/rconnector/InfoRetriever.java create mode 100644 src/main/java/org/gcube/data/analysis/rconnector/RConnector.java create mode 100644 src/main/java/org/gcube/data/analysis/rconnector/Resource.java create mode 100644 src/main/resources/META-INF/beans.xml create mode 100644 src/main/resources/inactivesession.html create mode 100644 src/main/resources/logout.html create mode 100644 src/main/resources/open.html create mode 100644 src/main/webapp/WEB-INF/gcube-app.xml create mode 100644 src/main/webapp/WEB-INF/web.xml create mode 100644 src/test/java/org/gcube/data/analysis/rconnector/TestCall.java create mode 100644 src/test/resources/logback.xml diff --git a/.classpath b/.classpath new file mode 100644 index 0000000..e43402f --- /dev/null +++ b/.classpath @@ -0,0 +1,36 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/.project b/.project new file mode 100644 index 0000000..446545d --- /dev/null +++ b/.project @@ -0,0 +1,23 @@ + + + r-connector + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.jdt.core.javanature + org.eclipse.m2e.core.maven2Nature + + diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..ec4300d --- /dev/null +++ b/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,5 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7 +org.eclipse.jdt.core.compiler.compliance=1.7 +org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning +org.eclipse.jdt.core.compiler.source=1.7 diff --git a/.settings/org.eclipse.m2e.core.prefs b/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/distro/LICENSE b/distro/LICENSE new file mode 100644 index 0000000..cdf50bd --- /dev/null +++ b/distro/LICENSE @@ -0,0 +1,4 @@ +gCube System - License +------------------------------------------------------------ + +${gcube.license} \ No newline at end of file diff --git a/distro/README b/distro/README new file mode 100644 index 0000000..5a6ef5c --- /dev/null +++ b/distro/README @@ -0,0 +1,66 @@ +The gCube System - ${name} +-------------------------------------------------- + +${description} + + +${gcube.description} + +${gcube.funding} + + +Version +-------------------------------------------------- + +${version} (${buildDate}) + +Please see the file named "changelog.xml" in this directory for the release notes. + + +Authors +-------------------------------------------------- + +* Lucio Lelii (lucio.lelii@isti.cnr.it), CNR, Italy + + +Maintainers +----------- + +* Lucio Lelii (lucio.lelii@isti.cnr.it), CNR, Italy + + +Download information +-------------------------------------------------- + +Source code is available from SVN: + ${scm.url} + +Binaries can be downloaded from the gCube website: + ${gcube.website} + + +Installation +-------------------------------------------------- + +Installation documentation is available on-line in the gCube Wiki: + ${gcube.wikiRoot}/RConnector + + +Documentation +-------------------------------------------------- + +Documentation is available on-line in the gCube Wiki: + ${gcube.wikiRoot}/RConnector + + +Support +-------------------------------------------------- + +Bugs and support requests can be reported in the gCube issue tracking tool: + ${gcube.issueTracking} + + +Licensing +-------------------------------------------------- + +This software is licensed under the terms you may find in the file named "LICENSE" in this directory. \ No newline at end of file diff --git a/distro/changelog.xml b/distro/changelog.xml new file mode 100644 index 0000000..fdf0c16 --- /dev/null +++ b/distro/changelog.xml @@ -0,0 +1,20 @@ + + + porting to smartgears 2.0 + + + algorithm for cookie encryption modified to support RStudio server 0.99 + + + connect method with empty parameters added + Authorization Framework integration + + + Bug fixing + + + First Release + + \ No newline at end of file diff --git a/distro/descriptor.xml b/distro/descriptor.xml new file mode 100644 index 0000000..e395580 --- /dev/null +++ b/distro/descriptor.xml @@ -0,0 +1,32 @@ + + servicearchive + + tar.gz + + / + + + ${distroDirectory} + / + true + + README + LICENSE + changelog.xml + profile.xml + + 755 + true + + + + + target/${build.finalName}.${project.packaging} + /${artifactId} + + + + \ No newline at end of file diff --git a/distro/profile.xml b/distro/profile.xml new file mode 100644 index 0000000..f387be9 --- /dev/null +++ b/distro/profile.xml @@ -0,0 +1,26 @@ + + + + Service + + ${description} + DataAnalysis + ${artifactId} + 1.0.0 + + + ${artifactId} + ${version} + + ${groupId} + ${artifactId} + ${version} + + + ${build.finalName}.jar + + + + + + diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..26b4412 --- /dev/null +++ b/pom.xml @@ -0,0 +1,170 @@ + + 4.0.0 + org.gcube.data.analysis + r-connector + 2.1.0-SNAPSHOT + RConnector + makes R available in the infrastructure + + war + + + distro + + + + + + org.gcube.distribution + maven-smartgears-bom + LATEST + pom + import + + + + + + + + org.gcube.common + database-resource + [1.0.0-SNAPSHOT,2.0.0-SNAPSHOT) + + + org.gcube.common + database-resource-api + [1.0.0-SNAPSHOT,2.0.0-SNAPSHOT) + + + + + org.gcube.core + common-smartgears + + + org.gcube.core + common-smartgears-app + + + + org.gcube.data.analysis.tabulardata + tabulardata-client-library + [1.0.0-SNAPSHOT, 2.0.0-SNAPSHOT) + + + + + javax.ws.rs + javax.ws.rs-api + 2.0 + + + org.glassfish.jersey.containers + jersey-container-servlet + 2.13 + + + org.glassfish.jersey.containers.glassfish + jersey-gf-cdi + 2.13 + + + + javax.transaction + javax.transaction-api + 1.2 + + + javax.servlet + javax.servlet-api + 3.0.1 + provided + + + + org.slf4j + slf4j-api + + + + ch.qos.logback + logback-classic + 1.0.13 + + + + + javax.enterprise + cdi-api + 1.1 + + + org.jboss.weld.servlet + weld-servlet + 2.2.4.Final + + + org.jboss + jandex + 1.2.2.Final + + + + + org.projectlombok + lombok + 0.11.6 + + + + org.glassfish.jersey.test-framework.providers + jersey-test-framework-provider-simple + 2.13 + test + + + + + ${artifactId} + + + maven-compiler-plugin + 2.3.2 + + 1.7 + 1.7 + + + + org.apache.maven.plugins + maven-war-plugin + 2.4 + + r-connector + false + + + + org.apache.maven.plugins + maven-assembly-plugin + 2.2 + + + ${distroDirectory}/descriptor.xml + + + + + servicearchive + install + + single + + + + + + + \ No newline at end of file diff --git a/src/main/java/org/gcube/data/analysis/rconnector/ConfigFileWriter.java b/src/main/java/org/gcube/data/analysis/rconnector/ConfigFileWriter.java new file mode 100644 index 0000000..18c4c98 --- /dev/null +++ b/src/main/java/org/gcube/data/analysis/rconnector/ConfigFileWriter.java @@ -0,0 +1,91 @@ +package org.gcube.data.analysis.rconnector; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.io.InputStreamReader; + +import javax.inject.Singleton; + +import lombok.extern.slf4j.Slf4j; + + +@Singleton +@Slf4j +public class ConfigFileWriter { + + + public boolean write(Info info, String login, String usersHome, String fileName, String scriptToExecute){ + + if (!usersHome.endsWith("/")) + usersHome=usersHome+"/"; + File userDir = new File(usersHome+login); + File configFile= new File(userDir, fileName); + checkDirectory(userDir, login, scriptToExecute); + return writeFile(info, configFile); + } + + private void checkDirectory(File userDir, String login, String scriptToExecute){ + if ((!userDir.isDirectory() || !userDir.exists())) + executeCommandLine(scriptToExecute,login); + + } + + private String executeCommandLine(String cmd, String login){ + log.debug("executing command "+cmd+" "+login); + Process process = null; + String lastline = ""; + try { + + ProcessBuilder pb = new ProcessBuilder(cmd, login); + process = pb.start(); + + try { + process.waitFor(); + } catch (InterruptedException e) { + log.warn("interrupt Exception on process",e); + } + + BufferedReader br = new BufferedReader(new InputStreamReader(process.getErrorStream())); + String line = br.readLine(); + while (line!=null){ + lastline += line; + line = br.readLine(); + } + } catch (IOException e) { + log.error("error executing command line",e); + } + log.debug("command result line is "+lastline); + return lastline; + } + + private boolean writeFile(Info info, File pathToFile){ + log.debug("writing config file"); + StringBuffer sb = new StringBuffer(); + sb.append(info.getTableName()+";"); + sb.append(info.getUserTableName()+";"); + + sb.append(info.getFields()); + if (!info.getFields().endsWith(";")) + sb.append(";"); + sb.append(info.getQueryColumns()); + if (!info.getQueryColumns().endsWith(";")) + sb.append(";"); + sb.append(info.getDatabase().getDatabaseAddress()+";"); + sb.append(info.getDatabase().getDatabaseName()+";"); + sb.append(info.getDatabase().getDatabaseUsername()+";"); + sb.append(info.getDatabase().getDatabasePassword()+"\n"); + + try{ + FileWriter fw = new FileWriter(pathToFile,false); + fw.write(sb.toString()); + fw.close(); + log.debug("file written"); + }catch(Exception e){ + log.error("error writing config file",e); + return false; + } + return true; + } +} diff --git a/src/main/java/org/gcube/data/analysis/rconnector/DisconnectResource.java b/src/main/java/org/gcube/data/analysis/rconnector/DisconnectResource.java new file mode 100644 index 0000000..d3af7e8 --- /dev/null +++ b/src/main/java/org/gcube/data/analysis/rconnector/DisconnectResource.java @@ -0,0 +1,48 @@ +package org.gcube.data.analysis.rconnector; + +import javax.servlet.ServletContext; +import javax.servlet.http.Cookie; +import javax.servlet.http.HttpServletRequest; +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import javax.ws.rs.core.Context; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; + +import lombok.extern.slf4j.Slf4j; + +@Path("disconnect") +@Slf4j +public class DisconnectResource { + + @Context ServletContext context; + + @GET + @Produces(MediaType.TEXT_HTML) + public Response disconnect(@Context HttpServletRequest req) { + log.info("disconnect called "); + new Throwable().printStackTrace(); + String rStudioServerAddress = context==null?"":context.getInitParameter("rStudioAddress"); + log.info(rStudioServerAddress); + try{ + boolean found = false; + for (Cookie cookie : req.getCookies()) + if (cookie.getName().equals("user-id")){ + found=true; + break; + } + if (found) + return Response.ok(context.getClassLoader().getResourceAsStream("logout.html")) + .header( + "Set-Cookie", + String.format("user-id=deleted;Domain=.%s;Path=/;Expires=Thu, 01-Jan-1970 00:00:01 GMT",rStudioServerAddress) + ).build(); + else return Response.ok(context.getClassLoader().getResourceAsStream("inactivesession.html")).build(); + }catch(Exception e){ + e.printStackTrace(); + return null; + } + } + +} diff --git a/src/main/java/org/gcube/data/analysis/rconnector/Info.java b/src/main/java/org/gcube/data/analysis/rconnector/Info.java new file mode 100644 index 0000000..59b1fe2 --- /dev/null +++ b/src/main/java/org/gcube/data/analysis/rconnector/Info.java @@ -0,0 +1,22 @@ +package org.gcube.data.analysis.rconnector; + +import lombok.Data; + +@Data +public class Info { + + private String username =""; + private String tableName ="" ; + private String userTableName ="" ; + private String fields =""; + private DataBaseInfo database = new DataBaseInfo(); + private String queryColumns= ""; + + @Data + public static class DataBaseInfo{ + private String databaseAddress="" ; + private String databaseName="" ; + private String databaseUsername ="" ; + private String databasePassword ="" ; + } +} diff --git a/src/main/java/org/gcube/data/analysis/rconnector/InfoRetriever.java b/src/main/java/org/gcube/data/analysis/rconnector/InfoRetriever.java new file mode 100644 index 0000000..315a905 --- /dev/null +++ b/src/main/java/org/gcube/data/analysis/rconnector/InfoRetriever.java @@ -0,0 +1,98 @@ +package org.gcube.data.analysis.rconnector; + +import static org.gcube.data.analysis.tabulardata.clientlibrary.plugin.AbstractPlugin.history; +import static org.gcube.data.analysis.tabulardata.clientlibrary.plugin.AbstractPlugin.query; +import static org.gcube.data.analysis.tabulardata.clientlibrary.plugin.AbstractPlugin.tabularResource; + +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import javax.inject.Inject; +import javax.inject.Singleton; + +import lombok.extern.slf4j.Slf4j; + +import org.gcube.common.database.DatabaseEndpointIdentifier; +import org.gcube.common.database.DatabaseProvider; +import org.gcube.common.database.endpoint.DatabaseEndpoint; +import org.gcube.common.scope.api.ScopeProvider; +import org.gcube.data.analysis.rconnector.Info.DataBaseInfo; +import org.gcube.data.analysis.tabulardata.commons.utils.AuthorizationProvider; +import org.gcube.data.analysis.tabulardata.commons.utils.AuthorizationToken; +import org.gcube.data.analysis.tabulardata.commons.webservice.types.TabularResource; +import org.gcube.data.analysis.tabulardata.model.column.Column; +import org.gcube.data.analysis.tabulardata.model.column.type.IdColumnType; +import org.gcube.data.analysis.tabulardata.model.datatype.GeometryType; +import org.gcube.data.analysis.tabulardata.model.metadata.common.NamesMetadata; +import org.gcube.data.analysis.tabulardata.model.metadata.table.DatasetViewTableMetadata; +import org.gcube.data.analysis.tabulardata.model.table.Table; + +@Slf4j +@Singleton +public class InfoRetriever { + + @Inject + DatabaseProvider databaseProvider; + + + @SuppressWarnings("unchecked") + public Info retrieve(String userName, Long tabularResourceId){ + try { + AuthorizationProvider.instance.set(new AuthorizationToken(userName, ScopeProvider.instance.get())); + TabularResource tr = tabularResource().build().getTabularResource(tabularResourceId); + Table table = history().build().getLastTable(tabularResourceId); + if (table.contains(DatasetViewTableMetadata.class)) + table= query().build().getTable(table.getMetadata(DatasetViewTableMetadata.class).getTargetDatasetViewTableId().getValue()); + + Info info =new Info(); + info.setTableName(table.getName()); + StringBuilder queryOrder = new StringBuilder();; + StringBuilder fields = new StringBuilder(); + for (Column col:table.getColumnsExceptTypes(IdColumnType.class)){ + fields.append(col.getMetadata(NamesMetadata.class).getTextWithLocale("en").getValue()).append(","); + if (col.getDataType().getClass().equals(GeometryType.class)) + queryOrder.append("ST_AsText(").append(col.getName()).append(")").append(","); + else queryOrder.append(col.getName()).append(","); + } + fields.deleteCharAt(fields.lastIndexOf(",")); + queryOrder.deleteCharAt(queryOrder.lastIndexOf(",")); + + info.setFields(fields.toString()); + info.setQueryColumns(queryOrder.toString()); + info.setUsername(userName); + info.setUserTableName(tr.getName()); + + info.setDatabase(retrievedatabaseInfo()); + + log.info("retrieved info are "+info); + + return info; + } catch (Exception e) { + log.error("error retrieving info ",e); + throw new RuntimeException(e.getMessage()); + } + + + } + + + DataBaseInfo retrievedatabaseInfo(){ + DatabaseEndpointIdentifier endpointId = new DatabaseEndpointIdentifier("TabularData Database", + "Data-ReadOnly"); + DatabaseEndpoint endpoint = databaseProvider.get(endpointId); + DataBaseInfo databaseInfo = new DataBaseInfo(); + databaseInfo.setDatabaseUsername(endpoint.getCredentials().getUsername()); + databaseInfo.setDatabasePassword(endpoint.getCredentials().getPassword()); + + Pattern pattern = Pattern.compile("[^/]*//([^:]*)[^/]*/(.*)"); + Matcher m = pattern.matcher(endpoint.getConnectionString()); + m.find(); + String databaseAddress = m.group(1); + String databaseName = m.group(2); + + databaseInfo.setDatabaseAddress(databaseAddress); + databaseInfo.setDatabaseName(databaseName); + return databaseInfo; + } + +} diff --git a/src/main/java/org/gcube/data/analysis/rconnector/RConnector.java b/src/main/java/org/gcube/data/analysis/rconnector/RConnector.java new file mode 100644 index 0000000..be4807c --- /dev/null +++ b/src/main/java/org/gcube/data/analysis/rconnector/RConnector.java @@ -0,0 +1,15 @@ +package org.gcube.data.analysis.rconnector; + +import javax.ws.rs.ApplicationPath; + +import org.glassfish.jersey.server.ResourceConfig; + +@ApplicationPath("/gcube/service/") +public class RConnector extends ResourceConfig { + + public RConnector(){ + packages("org.gcube.data.analysis.rconnector"); + } + + +} diff --git a/src/main/java/org/gcube/data/analysis/rconnector/Resource.java b/src/main/java/org/gcube/data/analysis/rconnector/Resource.java new file mode 100644 index 0000000..006c420 --- /dev/null +++ b/src/main/java/org/gcube/data/analysis/rconnector/Resource.java @@ -0,0 +1,116 @@ +package org.gcube.data.analysis.rconnector; + +import java.io.File; +import java.net.URI; +import java.net.URLEncoder; +import java.nio.file.Files; +import java.text.SimpleDateFormat; +import java.util.Calendar; +import java.util.Locale; + +import javax.crypto.Mac; +import javax.crypto.spec.SecretKeySpec; +import javax.inject.Inject; +import javax.servlet.ServletContext; +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.core.Context; +import javax.ws.rs.core.NewCookie; +import javax.ws.rs.core.Response; +import javax.xml.bind.DatatypeConverter; + +import lombok.extern.slf4j.Slf4j; + +import org.gcube.common.authorization.library.provider.AuthorizationProvider; +import org.gcube.common.scope.api.ScopeProvider; + +@Path("connect/") +@Slf4j +public class Resource { + + @Inject + ConfigFileWriter writer; + + @Inject + InfoRetriever infoRetriever; + + @Context ServletContext context; + + + @Path("/{trId}") + @GET + public Response connect(@PathParam("trId") Long tabularResourceId) { + log.info("connect called with user {} and trID {} in scope {}",AuthorizationProvider.instance.get().getClient().getId(), tabularResourceId, ScopeProvider.instance.get()); + String usersHome = context.getInitParameter("usersHome"); + String filename = context.getInitParameter("filename"); + String scriptToExecute = context.getInitParameter("addUserScript"); + if (ScopeProvider.instance.get()==null || AuthorizationProvider.instance.get().getClient().getId() == null || tabularResourceId ==null ) return Response.serverError().build(); + Info info; + try{ + info = infoRetriever.retrieve(AuthorizationProvider.instance.get().getClient().getId(), tabularResourceId); + log.debug("retrieved info: "+info); + }catch(Exception e){ + log.error("error connecting to r",e); + return Response.serverError().build(); + } + if (!writer.write(info, AuthorizationProvider.instance.get().getClient().getId(), usersHome, filename, scriptToExecute)) return Response.serverError().build(); + + return createResponse(AuthorizationProvider.instance.get().getClient().getId()); + } + + + @GET + public Response connect() { + log.info("connect called with user {} in scope {}",AuthorizationProvider.instance.get().getClient().getId(), ScopeProvider.instance.get()); + String usersHome = context.getInitParameter("usersHome"); + String filename = context.getInitParameter("filename"); + String scriptToExecute = context.getInitParameter("addUserScript"); + if (AuthorizationProvider.instance.get().getClient().getId() == null ) return Response.serverError().build(); + Info info = new Info(); + if (!writer.write(info, AuthorizationProvider.instance.get().getClient().getId(), usersHome, filename, scriptToExecute)) return Response.serverError().build(); + return createResponse(AuthorizationProvider.instance.get().getClient().getId()); + } + + private Response createResponse(String userName){ + try{ + String keyFilePath = context.getInitParameter("storedKeyPath"); + String rStudioServerAddress = context.getInitParameter("rStudioAddress"); + + log.debug("key file path: "+keyFilePath); + log.debug("rstudio server address: "+rStudioServerAddress); + + Calendar now = Calendar.getInstance(); + now.add(Calendar.YEAR, 10); + now.add(Calendar.DAY_OF_YEAR, -1); + SimpleDateFormat sdf = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss z", Locale.ENGLISH); + String format = sdf.format(now.getTime()); + + File keyFile = new File(keyFilePath); + if (!keyFile.exists()) + return Response.serverError().build(); + + byte[] keyByte = Files.readAllBytes(keyFile.toPath()); + + SecretKeySpec keySpec = new SecretKeySpec(keyByte, + "HmacSHA256"); + Mac mac = Mac.getInstance("HmacSHA256"); + mac.init(keySpec); + byte[] result = mac.doFinal((userName+format).getBytes()); + + String encoded = URLEncoder.encode(DatatypeConverter.printBase64Binary(result)); + + String cookieValue = userName+"|"+URLEncoder.encode(format).replaceAll("\\+", "%20")+"|"+encoded; + NewCookie cookie = new NewCookie("user-id", + cookieValue, + "/", rStudioServerAddress, "", -1, false, true ); + + + return Response.seeOther(new URI("http://"+rStudioServerAddress)) + .cookie(cookie).build(); + }catch(Exception e){ + log.error("error creating response", e); + return Response.serverError().build();} + } + +} diff --git a/src/main/resources/META-INF/beans.xml b/src/main/resources/META-INF/beans.xml new file mode 100644 index 0000000..7c7e8db --- /dev/null +++ b/src/main/resources/META-INF/beans.xml @@ -0,0 +1,5 @@ + + \ No newline at end of file diff --git a/src/main/resources/inactivesession.html b/src/main/resources/inactivesession.html new file mode 100644 index 0000000..f714a83 --- /dev/null +++ b/src/main/resources/inactivesession.html @@ -0,0 +1,4 @@ + +

Rsutdio session inactive

+

log in using TabularData portlet from the i-marine portal

+ \ No newline at end of file diff --git a/src/main/resources/logout.html b/src/main/resources/logout.html new file mode 100644 index 0000000..c63c27d --- /dev/null +++ b/src/main/resources/logout.html @@ -0,0 +1,8 @@ + + +

Successfully logged out from RStudio

+

this tab will close in 2 seconds

+ + \ No newline at end of file diff --git a/src/main/resources/open.html b/src/main/resources/open.html new file mode 100644 index 0000000..8b0a1c8 --- /dev/null +++ b/src/main/resources/open.html @@ -0,0 +1,13 @@ + + + + + +

Opening

+ + \ No newline at end of file diff --git a/src/main/webapp/WEB-INF/gcube-app.xml b/src/main/webapp/WEB-INF/gcube-app.xml new file mode 100644 index 0000000..ee1812c --- /dev/null +++ b/src/main/webapp/WEB-INF/gcube-app.xml @@ -0,0 +1,12 @@ + + RConnector + DataAnalysis + 1.0.0-SNAPSHOT + r connector webapp + + + /disconnect/* + + diff --git a/src/main/webapp/WEB-INF/web.xml b/src/main/webapp/WEB-INF/web.xml new file mode 100644 index 0000000..1df8e5a --- /dev/null +++ b/src/main/webapp/WEB-INF/web.xml @@ -0,0 +1,29 @@ + + + usersHome + /home/ + + + filename + userconfig.csv + + + addUserScript + /root/Ruseradd.sh + + + storedKeyPath + /var/lib/rstudio-server/secure-cookie-key + + + rStudioAddress + rstudio-dev.d4science.org + + + org.gcube.data.analysis.rconnector.RConnector + + + org.gcube.data.analysis.rconnector.RConnector + /gcube/service/* + + \ No newline at end of file diff --git a/src/test/java/org/gcube/data/analysis/rconnector/TestCall.java b/src/test/java/org/gcube/data/analysis/rconnector/TestCall.java new file mode 100644 index 0000000..de90a70 --- /dev/null +++ b/src/test/java/org/gcube/data/analysis/rconnector/TestCall.java @@ -0,0 +1,22 @@ +package org.gcube.data.analysis.rconnector; + +import javax.ws.rs.core.Application; + +import org.glassfish.jersey.server.ResourceConfig; +import org.glassfish.jersey.test.JerseyTest; +import org.junit.Test; + +public class TestCall extends JerseyTest{ + + @Override + protected Application configure() { + return new ResourceConfig(Resource.class, DisconnectResource.class); + } + + @Test + public void disconnect() { + final String ret = target("disconnect").request().get(String.class); + System.out.println("return is "+ret); + } + +} diff --git a/src/test/resources/logback.xml b/src/test/resources/logback.xml new file mode 100644 index 0000000..4f36cc8 --- /dev/null +++ b/src/test/resources/logback.xml @@ -0,0 +1,16 @@ + + + + + %d{HH:mm:ss.SSS} [%thread] %-5level %logger{0}: %msg%n + + + + + + + + + + + \ No newline at end of file