Compare commits

...

36 Commits

Author SHA1 Message Date
Massimiliano Assante b6463ff598 ready to release 2 years ago
Massimiliano Assante c7c962414d Feature #22109 load VRE Folder without using JCR indices 2 years ago
Massimiliano Assante 80b24443e0 just remove da forgotten sysout used for debugging 3 years ago
Massimiliano Assante 3d4667d504 Bug #21794 fixed, added to release current 3 years ago
Massimiliano Assante 0acb08f4ba Bug #21794 fixed, folder names were not URI encoded 3 years ago
Massimiliano Assante fa373c0ff7 updated bom 3 years ago
Massimiliano Assante 90baf04995 ready to release 3 years ago
Massimiliano Assante 9890dfe01c updated use of wrong token provider 3 years ago
Massimiliano Assante b9e4aea1db pom fixed 3 years ago
Massimiliano Assante f87d7e85cf Feature #21507 support new UMATokensProvider class 3 years ago
Massimiliano Assante e9330f651e Feature #21507 support new UMATokensProvider class 3 years ago
Massimiliano Assante 7d43b96e11 another minor fix on getVREFoldersId when user is new 3 years ago
Massimiliano Assante 9b1c436756 fixed the issue on getWorkspaceFolderURL method 3 years ago
Massimiliano Assante b204c9f343 ready to release 3 years ago
Massimiliano Assante 04ab828143 fix bug avoiding the download of files 3 years ago
Roberto Cirillo b4cad2e995 Update 'pom.xml'
fix scm url
3 years ago
Massimiliano Assante 8b7ad4af51 updated pom for release 3 years ago
Massimiliano Assante 1ccb6f519f ready to release 3 years ago
Massimiliano Assante b776f1bbe7 boh 3 years ago
Massimiliano Assante 4e2ef87567 none 3 years ago
Massimiliano Assante ff6cd1f69c none 3 years ago
Massimiliano Assante e567750d6f none 3 years ago
Massimiliano Assante f0c5ca5574 none 3 years ago
Massimiliano Assante 23b109755c none 3 years ago
Massimiliano Assante 3927b75c67 none 3 years ago
Massimiliano Assante 7541e723a4 none 3 years ago
Massimiliano Assante aed9af164b none 3 years ago
Massimiliano Assante 182cc8a94c none 3 years ago
Massimiliano Assante a2d522d7e8 just lowered one log to DEBUG from INFO 3 years ago
Massimiliano Assante 754e599564 removed -snapshot from maven-portal-bom version 3 years ago
Massimiliano Assante 30fca73f1c typo fix 3 years ago
Massimiliano Assante a85af08838 Fix Bug #20552 Workspace widget item counter no longer works 3 years ago
Massimiliano Assante 2dd5e12d8c minor fixes in pom, updated minor version 4 years ago
Massimiliano Assante 1004068c8f Merge branch 'master' of
https://code-repo.d4science.org/gCubeSystem/workspace-widget-portlet.git

Conflicts:
	pom.xml
4 years ago
Massimiliano Assante 2ac20e020c Feature #17913 merged 4 years ago
Massimiliano Assante 909b0ccf81 Feature #17913 4 years ago

BIN
.DS_Store vendored

Binary file not shown.

@ -1,27 +1,27 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" output="target/classes" path="src/main/java">
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
<attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
<attribute name="test" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<classpathentry kind="src" output="target/classes" path="src/main/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
<attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
<attribute name="test" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/classes"/>

@ -3,7 +3,9 @@ org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=ignore
org.eclipse.jdt.core.compiler.release=disabled
org.eclipse.jdt.core.compiler.source=1.8

@ -1,10 +1,78 @@
<?xml version="1.0" encoding="UTF-8"?><project-modules id="moduleCoreId" project-version="1.5.0">
<wb-module deploy-name="workspace-widget-portlet">
<wb-resource deploy-path="/" source-path="/target/m2e-wtp/web-resources"/>
<wb-resource deploy-path="/" source-path="/src/main/webapp" tag="defaultRootSource"/>
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/java"/>
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/resources"/>
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/java"/>
<property name="context-root" value="workspace-widget-portlet"/>
<property name="java-output-path" value="/workspace-widget-portlet/target/classes"/>
</wb-module>
</project-modules>

@ -0,0 +1,37 @@
# Changelog for Workspace Widget Portlet
All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [v1.5.2] - 2021-10-04
- Feature #22109 Workspace widget to load VRE Folders without using JCR indices
## [v1.5.1] - 2021-07-13
- Feature #21507 support new UMATokensProvider class
- Bug #21794 folder names were not URI encoded
## [v1.5.0] - 2021-04-06
- Removed legacy auth dependency
## [v1.4.1] - 2021-01-26
- Fix Bug #20552 Workspace widget item counter no longer works
## [v1.3.1] - 2019-10-09
- Updated to new storage hub api
## [v1.3.0] - 2019-03-04
- Updated to new storage hub exception handling<
- Feature #12796 Workspace widget: recent documents has a different behaviour on URL items
## [v1.0.0] - 2018-05-17
First release

@ -0,0 +1,26 @@
# Acknowledgments
The projects leading to this software have received funding from a series of European Union programmes including:
- the Sixth Framework Programme for Research and Technological Development
- [DILIGENT](https://cordis.europa.eu/project/id/004260) (grant no. 004260).
- the Seventh Framework Programme for research, technological development and demonstration
- [D4Science](https://cordis.europa.eu/project/id/212488) (grant no. 212488);
- [D4Science-II](https://cordis.europa.eu/project/id/239019) (grant no.239019);
- [ENVRI](https://cordis.europa.eu/project/id/283465) (grant no. 283465);
- [iMarine](https://cordis.europa.eu/project/id/283644) (grant no. 283644);
- [EUBrazilOpenBio](https://cordis.europa.eu/project/id/288754) (grant no. 288754).
- the H2020 research and innovation programme
- [SoBigData](https://cordis.europa.eu/project/id/654024) (grant no. 654024);
- [PARTHENOS](https://cordis.europa.eu/project/id/654119) (grant no. 654119);
- [EGI-Engage](https://cordis.europa.eu/project/id/654142) (grant no. 654142);
- [ENVRI PLUS](https://cordis.europa.eu/project/id/654182) (grant no. 654182);
- [BlueBRIDGE](https://cordis.europa.eu/project/id/675680) (grant no. 675680);
- [PerformFISH](https://cordis.europa.eu/project/id/727610) (grant no. 727610);
- [AGINFRA PLUS](https://cordis.europa.eu/project/id/731001) (grant no. 731001);
- [DESIRA](https://cordis.europa.eu/project/id/818194) (grant no. 818194);
- [ARIADNEplus](https://cordis.europa.eu/project/id/823914) (grant no. 823914);
- [RISIS 2](https://cordis.europa.eu/project/id/824091) (grant no. 824091);
- [EOSC-Pillar](https://cordis.europa.eu/project/id/857650) (grant no. 857650);
- [Blue Cloud](https://cordis.europa.eu/project/id/862409) (grant no. 862409);
- [SoBigData-PlusPlus](https://cordis.europa.eu/project/id/871042) (grant no. 871042);

@ -1,19 +0,0 @@
<ReleaseNotes>
<Changeset component="org.gcube.workspace-widget-portlet.1-3-1"
date="2019-10-09">
<Change>Updated to new storage hub api</Change>
</Changeset>
<Changeset component="org.gcube.workspace-widget-portlet.1-3-0"
date="2019-03-04">
<Change>Updated to new storage hub exception handling</Change>
<Change>Feature #12796 Workspace widget: recent documents has a different behaviour on URL items</Change>
</Changeset>
<Changeset component="org.gcube.workspace-widget-portlet.1-1-0"
date="2018-06-12">
<Change>Added mazimise feature</Change>
</Changeset>
<Changeset component="org.gcube.workspace-widget-portlet.1-0-0"
date="2018-05-17">
<Change>First Release</Change>
</Changeset>
</ReleaseNotes>

@ -1,31 +0,0 @@
<assembly
xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd">
<id>servicearchive</id>
<formats>
<format>tar.gz</format>
</formats>
<baseDirectory>/</baseDirectory>
<fileSets>
<fileSet>
<directory>${distroDirectory}</directory>
<outputDirectory>/</outputDirectory>
<useDefaultExcludes>true</useDefaultExcludes>
<includes>
<include>README</include>
<include>LICENSE</include>
<include>changelog.xml</include>
<include>profile.xml</include>
</includes>
<fileMode>755</fileMode>
<filtered>true</filtered>
</fileSet>
</fileSets>
<files>
<file>
<source>target/${build.finalName}.${project.packaging}</source>
<outputDirectory>/${artifactId}</outputDirectory>
</file>
</files>
</assembly>

@ -1,25 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<Resource xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<ID></ID>
<Type>Service</Type>
<Profile>
<Description>${description}</Description>
<Class>PortletUser</Class>
<Name>${artifactId}</Name>
<Version>${version}</Version>
<Packages>
<Software>
<Name>${artifactId}</Name>
<Version>${version}</Version>
<MavenCoordinates>
<groupId>${groupId}</groupId>
<artifactId>${artifactId}</artifactId>
<version>${version}</version>
</MavenCoordinates>
<Files>
<File>target/${build.finalName}.war</File>
</Files>
</Software>
</Packages>
</Profile>
</Resource>

@ -1,5 +1,6 @@
<?xml version="1.0"?>
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
@ -12,19 +13,17 @@
<artifactId>workspace-widget-portlet</artifactId>
<packaging>war</packaging>
<name>workspace-widget-portlet Portlet</name>
<version>1.3.2</version>
<version>1.5.2</version>
<description>
Workspace Widget
</description>
Workspace Widget Portlet is a small Front-end component looking like G Drive which exposes the content of the user's workspace or VRE Folders in read only mode.
</description>
<scm>
<connection>scm:git:https://code-repo.d4science.org/gCubeSystem/workspace-widget-portlet.git</connection>
<developerConnection>scm:git:https://code-repo.d4science.org/gCubeSystem/workspace-widget-portlet.git</developerConnection>
<url>https://code-repo.d4science.org/gCubeSystem/workspace-widget-portlet</url>
<connection>scm:git:https://code-repo.d4science.org/gCubeSystem/${project.artifactId}.git</connection>
<developerConnection>scm:git:https://code-repo.d4science.org/gCubeSystem/${project.artifactId}.git</developerConnection>
<url>https://code-repo.d4science.org/gCubeSystem/${project.artifactId}</url>
</scm>
<properties>
<distroDirectory>distro</distroDirectory>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<liferay.version>6.2.5</liferay.version>
<liferay.maven.plugin.version>6.2.10.12</liferay.maven.plugin.version>
<liferay.auto.deploy.dir>/Users/massi/portal/liferay-portal-6.2-ce-ga6/deploy</liferay.auto.deploy.dir>
@ -37,7 +36,7 @@
<dependency>
<groupId>org.gcube.distribution</groupId>
<artifactId>maven-portal-bom</artifactId>
<version>3.5.0-4.16.0-181969</version>
<version>3.6.3</version>
<type>pom</type>
<scope>import</scope>
</dependency>
@ -77,10 +76,19 @@
<artifactId>common-authorization</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.gcube.portal</groupId>
<artifactId>oidc-library-portal</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.gcube.common</groupId>
<artifactId>oidc-library</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.liferay.portal</groupId>
<artifactId>portal-service</artifactId>
<version>${liferay.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
@ -150,8 +158,8 @@
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<encoding>UTF-8</encoding>
<source>1.8</source>
<target>1.8</target>
<source>${maven.compiler.source}</source>
<target>${maven.compiler.target}</target>
</configuration>
</plugin>
<plugin>
@ -161,7 +169,7 @@
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<configuration>

@ -25,6 +25,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@SuppressWarnings("deprecation")
public class ItemBuilder {
public static final Logger _log = LoggerFactory.getLogger(ItemBuilder.class);
@ -37,6 +38,7 @@ public class ItemBuilder {
* @param currentUserName
* @return
*/
@SuppressWarnings("deprecation")
public static WSItem getItem(WSItem parent, Item workspaceItem, String workspaceItemPath, String currentUserName) {
ItemType type = getItemType(workspaceItem);
boolean isFolder = type.equals(ItemType.PRIVATE_FOLDER)?true:false;
@ -44,7 +46,7 @@ public class ItemBuilder {
String itemName = workspaceItem.getName();
if(isSharedFolder){
_log.info("Is shared folder: "+workspaceItem.getTitle());
_log.debug("Is shared folder: "+workspaceItem.getTitle());
SharedFolder shared = (SharedFolder) workspaceItem;
itemName = shared.isVreFolder()?shared.getDisplayName():workspaceItem.getTitle();
}

@ -7,18 +7,28 @@ import java.util.List;
import javax.portlet.ResourceRequest;
import javax.servlet.http.HttpServletRequest;
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
import org.gcube.common.authorization.library.provider.AccessTokenProvider;
import org.gcube.common.portal.GCubePortalConstants;
import org.gcube.common.portal.PortalContext;
import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.common.storagehub.client.plugins.AbstractPlugin;
import org.gcube.common.storagehub.client.proxies.ItemManagerClient;
import org.gcube.common.storagehub.client.proxies.WorkspaceManagerClient;
import org.gcube.common.storagehub.model.items.Item;
import org.gcube.oidc.rest.JWTToken;
import org.gcube.portal.oidc.lr62.InvalidTokenException;
import org.gcube.portal.oidc.lr62.JWTTokenUtil;
import org.gcube.portal.oidc.lr62.MissingTokenException;
import org.gcube.portal.oidc.lr62.NotAuthorizedException;
import org.gcube.portal.oidc.lr62.OIDCUmaUtil;
import org.gcube.portal.oidc.lr62.RefreshException;
import org.gcube.portal.oidc.lr62.UMAException;
import org.gcube.portlets.user.wswidget.shared.AuthorizedUser;
import org.gcube.portlets.user.wswidget.shared.WSItem;
import com.liferay.portal.kernel.log.Log;
import com.liferay.portal.kernel.log.LogFactoryUtil;
import com.liferay.portal.util.PortalUtil;
public class StorageHubServiceUtil {
private static Log _log = LogFactoryUtil.getLog(StorageHubServiceUtil.class);
@ -29,13 +39,12 @@ public class StorageHubServiceUtil {
* @param itemName
* @param from
* @param offset
* @return
* @return the list of items
*/
public static List<WSItem> getItemChildren(AuthorizedUser authUser, String itemId, String itemName, int from, int offset) {
WSItem toReturn = new WSItem(itemId, itemName, true);
_log.debug("getItemChildren folder/item = " + itemId);
ArrayList<WSItem> children = new ArrayList<>();
SecurityTokenProvider.instance.set(authUser.getSecurityToken());
ItemManagerClient client = AbstractPlugin.item().build();
List<? extends Item> theChildren = null;
try {
@ -61,21 +70,17 @@ public class StorageHubServiceUtil {
}
toReturn.setChildren(children);
Collections.sort(toReturn.getChildren(), new ItemComparator());
_log.debug("*** Returning children size: "+toReturn.getChildren().size());
_log.debug("Returning children size: "+toReturn.getChildren().size());
return children;
}
/**
*
*/
public static int getItemChildrenCount(ResourceRequest request, String itemId) {
String userName = Utils.getCurrentUser(request).getUsername();
String scope = Utils.getCurrentContext(request);
String authorizationToken = Utils.getCurrentUserToken(scope, userName);
SecurityTokenProvider.instance.set(authorizationToken);
ItemManagerClient client = AbstractPlugin.item().build();
int toReturn = -1;
try {
client.childrenCount(itemId, false);
toReturn = client.childrenCount(itemId, false);
}
catch (Exception e) {
e.printStackTrace();
@ -91,7 +96,6 @@ public class StorageHubServiceUtil {
*/
public static List<WSItem> getRootChildren(AuthorizedUser authUser, int from, int offset) {
try {
SecurityTokenProvider.instance.set(authUser.getSecurityToken());
WorkspaceManagerClient client = AbstractPlugin.workspace().build();
Item itemRoot = client.getWorkspace("hl:accounting");
WSItem root = new WSItem(itemRoot.getId(), Utils.HOME_LABEL, true);
@ -112,7 +116,6 @@ public class StorageHubServiceUtil {
WSItem toReturn = new WSItem("recents", "Recent Documents", true);
_log.debug("getRecentItems ");
ArrayList<WSItem> children = new ArrayList<>();
SecurityTokenProvider.instance.set(authUser.getSecurityToken());
WorkspaceManagerClient wsclient = AbstractPlugin.workspace().build();
List<? extends Item> theChildren = wsclient.getRecentModifiedFilePerVre();
@ -136,14 +139,19 @@ public class StorageHubServiceUtil {
* @return the id of the VRE Folder associated to the given context
*/
public static String getWorkspaceFolderURL(HttpServletRequest request) {
String userName = Utils.getCurrentUser(request).getUsername();
String scope = Utils.getCurrentContext(request);
String authorizationToken = Utils.getCurrentUserToken(scope, userName);
SecurityTokenProvider.instance.set(authorizationToken);
String siteLandingPagePath = PortalContext.getConfiguration().getSiteLandingPagePath(request);
String toReturn = siteLandingPagePath;
try {
String currentContext = Utils.getCurrentContext(request);
try {
long userId = PortalUtil.getUser(request).getUserId();
JWTToken umaToken = OIDCUmaUtil.getUMAToken(request, userId, currentContext);
AccessTokenProvider.instance.set(JWTTokenUtil.getAccessTokenString(umaToken));
} catch (Exception e1) {
e1.printStackTrace();
}
ScopeProvider.instance.set(currentContext);
WorkspaceManagerClient wsclient = AbstractPlugin.workspace().build();
String itemId = wsclient.getVreFolder("hl:accounting").getId();
toReturn = new String(new StringBuffer(siteLandingPagePath)
@ -160,23 +168,31 @@ public class StorageHubServiceUtil {
* @param request
* @return the VRE Folders Id
*/
public static String getVREFoldersId(HttpServletRequest request) {
String userName = Utils.getCurrentUser(request).getUsername();
String scope = Utils.getCurrentContext(request);
String authorizationToken = Utils.getCurrentUserToken(scope, userName);
SecurityTokenProvider.instance.set(authorizationToken);
public static String getVREFoldersId(long groupId, HttpServletRequest request, String currentUsername) {
String toReturn = "";
String currentContext = PortalContext.getConfiguration().getCurrentScope(""+groupId);
String username = currentUsername;
try {
JWTToken umaToken = OIDCUmaUtil.getUMAToken(request, username, currentContext);
AccessTokenProvider.instance.set(JWTTokenUtil.getAccessTokenString(umaToken));
} catch (InvalidTokenException | MissingTokenException | RefreshException | NotAuthorizedException
| UMAException e1) {
_log.warn("could not get UMA Token for context="+currentContext);
e1.printStackTrace();
}
_log.debug("getVREFoldersId, context="+currentContext);
ScopeProvider.instance.set(currentContext);
try {
WorkspaceManagerClient wsclient = AbstractPlugin.workspace().build();
try {
List<? extends Item> list = wsclient.getVreFolders("hl:accounting");
toReturn =list.iterator().next().getParentId();
} catch (Exception e) {
_log.info("This user has no VRE Folders", e);
} catch (java.util.NoSuchElementException ex) {
_log.info("This user has no VRE Folders");
return null;
}
}catch (Exception e) {
e.printStackTrace();
_log.warn("Could not load VREFolders id" + e.getMessage());
}
return toReturn;
}

@ -3,6 +3,7 @@ package org.gcube.portlets.user.wswidget;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.Scanner;
import javax.portlet.PortletException;
@ -12,7 +13,8 @@ import javax.portlet.ResourceResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
import org.gcube.common.authorization.library.provider.AccessTokenProvider;
import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.common.storagehub.client.StreamDescriptor;
import org.gcube.common.storagehub.client.dsl.FileContainer;
import org.gcube.common.storagehub.client.dsl.ItemContainer;
@ -23,6 +25,9 @@ import org.gcube.common.storagehub.model.exceptions.StorageHubException;
import org.gcube.common.storagehub.model.items.ExternalLink;
import org.gcube.common.storagehub.model.items.ExternalURL;
import org.gcube.common.storagehub.model.items.Item;
import org.gcube.oidc.rest.JWTToken;
import org.gcube.portal.oidc.lr62.JWTTokenUtil;
import org.gcube.portal.oidc.lr62.OIDCUmaUtil;
import org.gcube.portlets.user.wswidget.shared.AuthorizedUser;
import org.gcube.portlets.user.wswidget.shared.Breadcrumb;
import org.gcube.portlets.user.wswidget.shared.WSItem;
@ -58,6 +63,17 @@ public class WorkspaceWidget extends MVCPortlet {
//check if is a file download
if (fileToDownloadId != null) {
setAuthorizationToken(resourceRequest);
String currentContext = Utils.getCurrentContext(resourceRequest);
ScopeProvider.instance.set(currentContext);
HttpServletRequest httpReq = PortalUtil.getHttpServletRequest(resourceRequest);
long userId;
try {
userId = PortalUtil.getUser(resourceRequest).getUserId();
JWTToken umaToken = OIDCUmaUtil.getUMAToken(httpReq, userId, currentContext);
AccessTokenProvider.instance.set(JWTTokenUtil.getAccessTokenString(umaToken));
} catch (Exception e1) {
e1.printStackTrace();
}
String selectedItemId = fileToDownloadId.split("=")[1];
StorageHubClient client = new StorageHubClient();
FileContainer fileContainer = null;
@ -73,6 +89,7 @@ public class WorkspaceWidget extends MVCPortlet {
} else {
fileContainer = client.open(selectedItemId).asFile();
streamDescr = fileContainer.download(selectedItemId);
_log.info("*** DONE fileContainer.download for itemid=" +selectedItemId);
}
if (item instanceof ExternalURL) { //if is a type URL we open directly the link (HL Created it)
Scanner sc = new Scanner( streamDescr.getStream());
@ -86,7 +103,6 @@ public class WorkspaceWidget extends MVCPortlet {
e.printStackTrace();
}
if (! (item instanceof ExternalURL || item instanceof ExternalLink)) {
HttpServletRequest httpReq = PortalUtil.getHttpServletRequest(resourceRequest);
ServletResponseUtil.sendFile(httpReq,httpRes, streamDescr.getFileName(), streamDescr.getStream(), "application/download");
streamDescr.getStream().close();
}
@ -125,8 +141,13 @@ public class WorkspaceWidget extends MVCPortlet {
toSet = new Breadcrumb(itemId, Utils.getCurrentUser(request).getFirstName()+"\'s home");
request.getPortletSession().setAttribute(BREADCRUMB_ATTR, toSet, PortletSession.APPLICATION_SCOPE);
} else { //is in a VRE
WorkspaceManagerClient wsclient = AbstractPlugin.workspace().build();
itemId = wsclient.getVreFolder("hl:accounting").getId();
_log.debug("looking for vre context");
String context = Utils.getCurrentContext(request);
final String vreContext = context.replace("/", "-").substring(1); //shub expects this name, e.g. gcube-devsec-devVRE
_log.debug("shub vre name to look for: "+vreContext);
StorageHubClient shc = new StorageHubClient();
Optional<ItemContainer<? extends Item>> vreContainer = shc.getVREFolders().getContainers().stream().filter(v -> v.get().getTitle().equals(vreContext)).findFirst();
itemId = vreContainer.get().getId();
itemsList = StorageHubServiceUtil.getItemChildren(authUser, itemId, itemId, start, offset);
String groupName = GroupLocalServiceUtil.getGroup(groupId).getName();
groupName = groupName.replace("_", " ");
@ -257,10 +278,6 @@ public class WorkspaceWidget extends MVCPortlet {
}
private static WSItem getRootItem(ResourceRequest request) {
String userName = Utils.getCurrentUser(request).getUsername();
String scope = Utils.getCurrentContext(request);
String authorizationToken = Utils.getCurrentUserToken(scope, userName);
SecurityTokenProvider.instance.set(authorizationToken);
WorkspaceManagerClient client = AbstractPlugin.workspace().build();
Item itemRoot = client.getWorkspace("hl:accounting");
WSItem root = new WSItem(itemRoot.getId(), Utils.HOME_LABEL, true);
@ -276,9 +293,6 @@ public class WorkspaceWidget extends MVCPortlet {
*/
private AuthorizedUser setAuthorizationToken(ResourceRequest request) {
GCubeUser currentUser = Utils.getCurrentUser(request);
String scope = Utils.getCurrentContext(request);
String authorizationToken = Utils.getCurrentUserToken(scope, currentUser.getUsername());
SecurityTokenProvider.instance.set(authorizationToken);
return new AuthorizedUser(currentUser, authorizationToken, scope);
return new AuthorizedUser(currentUser);
}
}

@ -6,11 +6,10 @@ public class AuthorizedUser {
private GCubeUser user;
private String token;
private String context;
public AuthorizedUser(GCubeUser user, String token, String context) {
public AuthorizedUser(GCubeUser user) {
super();
this.user = user;
this.token = token;
this.context = context;
}
public GCubeUser getUser() {
return user;
@ -18,18 +17,7 @@ public class AuthorizedUser {
public void setUser(GCubeUser user) {
this.user = user;
}
public String getSecurityToken() {
return token;
}
public void setSecurityToken(String token) {
this.token = token;
}
public String getContext() {
return context;
}
public void setContext(String context) {
this.context = context;
}
@Override
public String toString() {
StringBuilder builder = new StringBuilder();

@ -130,7 +130,8 @@
.workspace-widget-portlet .dataTables_wrapper {
margin-left: -5px;
}
overflow-x: hidden;
}
/* .dataTables_wrapper .dataTables_paginate .paginate_button.current, .dataTables_wrapper .dataTables_paginate .paginate_button.current:hover */

@ -3,7 +3,10 @@
<link href="https://fonts.googleapis.com/icon?family=Material+Icons"
rel="stylesheet">
<% pageContext.setAttribute("currentGroup", GroupLocalServiceUtil.getGroup(PortalUtil.getScopeGroupId(request)));
<%
pageContext.setAttribute("currentGroup", GroupLocalServiceUtil.getGroup(PortalUtil.getScopeGroupId(request)));
String currentUsername = PortalUtil.getUser(request).getScreenName();
pageContext.setAttribute("currentUsername", PortalUtil.getUser(request).getScreenName());
%>
<script src="<%=renderRequest.getContextPath()%>/js/datatables.min.js"></script>
@ -21,7 +24,7 @@
<c:set var="maximised" scope="session"
value="${renderRequest.getWindowState().toString().equalsIgnoreCase('maximized')}" />
<table width="100%" style="border: none; border-collapse: inherit;">
<table width="100%" style="border: none; border-collapse: inherit; overflow-x: hidden;">
<tr>
<td><div class="ws-breadcrumb-container"></div></td>
<c:choose>
@ -42,7 +45,7 @@
</c:when>
<c:otherwise>
<td>
<%pageContext.setAttribute("vreFoldersId", StorageHubServiceUtil.getVREFoldersId(request));%>
<%pageContext.setAttribute("vreFoldersId", StorageHubServiceUtil.getVREFoldersId(PortalUtil.getScopeGroupId(request), request, currentUsername));%>
<c:if test="${not empty vreFoldersId}">
<div id="vreFoldersDiv" class="ws-recents">
<a
@ -88,7 +91,7 @@ $.fn.dataTable.ext.errMode = 'none';
function loadItemsListIntoTable(itemId, itemName, hideVreFolders) {
var table = $('#userTable').DataTable();
table.ajax.url('<%=usersCustomDataSourceURL%>'+itemId+'_selectedName='+itemName).load();
table.ajax.url('<%=usersCustomDataSourceURL%>'+itemId+'_selectedName='+encodeURIComponent(itemName)).load();
if (hideVreFolders) {
$('#vreFoldersDiv').hide();
} else {
@ -100,7 +103,7 @@ function loadItemsListIntoTable(itemId, itemName, hideVreFolders) {
function loadRecentItemsListIntoTable(itemId, itemName) {
var table = $('#userTable').DataTable();
table.ajax.url('<%=usersCustomDataSourceURL%>'+itemId+'_selectedName='+itemName).load();
table.ajax.url('<%=usersCustomDataSourceURL%>'+itemId+'_selectedName='+encodeURIComponent(itemName)).load();
$('#userTable_info').hide();
$('#userTable_length').hide();
}

Loading…
Cancel
Save