This commit is contained in:
Massimiliano Assante 2021-04-06 10:39:35 +02:00
parent a2d522d7e8
commit 182cc8a94c
6 changed files with 18 additions and 43 deletions

View File

@ -4,6 +4,10 @@
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.4.2-SNAPSHOT] - 2021-04-06
Removed legacy auth dependency
## [v1.4.1] - 2021-01-26
- Fix Bug #20552 Workspace widget item counter no longer works

View File

@ -13,7 +13,7 @@
<artifactId>workspace-widget-portlet</artifactId>
<packaging>war</packaging>
<name>workspace-widget-portlet Portlet</name>
<version>1.4.1</version>
<version>1.4.2-SNAPSHOT</version>
<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>
@ -36,7 +36,7 @@
<dependency>
<groupId>org.gcube.distribution</groupId>
<artifactId>maven-portal-bom</artifactId>
<version>3.6.0</version>
<version>3.6.1-SNAPSHOT</version>
<type>pom</type>
<scope>import</scope>
</dependency>

View File

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

View File

@ -7,9 +7,9 @@ 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.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;
@ -35,7 +35,6 @@ public class StorageHubServiceUtil {
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 {
@ -68,10 +67,6 @@ public class StorageHubServiceUtil {
*
*/
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 {
@ -91,7 +86,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 +106,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,10 +129,6 @@ 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;
@ -161,11 +150,9 @@ public class StorageHubServiceUtil {
* @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);
String toReturn = "";
String currentContext = PortalContext.getConfiguration().getCurrentScope(request);
ScopeProvider.instance.set(currentContext);
try {
WorkspaceManagerClient wsclient = AbstractPlugin.workspace().build();
try {

View File

@ -12,7 +12,6 @@ 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.storagehub.client.StreamDescriptor;
import org.gcube.common.storagehub.client.dsl.FileContainer;
import org.gcube.common.storagehub.client.dsl.ItemContainer;
@ -73,6 +72,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());
@ -85,7 +85,8 @@ public class WorkspaceWidget extends MVCPortlet {
} catch (StorageHubException e) {
e.printStackTrace();
}
if (! (item instanceof ExternalURL || item instanceof ExternalLink)) {
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();
@ -257,10 +258,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 +273,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);
}
}

View File

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