Fixing class cast exceptiong during get USER ACL Info (see: https://support.d4science.org/issues/12956)

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/widgets/workspace-explorer@174463 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Francesco Mangiacrapa 2018-11-29 14:06:19 +00:00
parent 43557eaad8
commit 54bd178d8a
2 changed files with 47 additions and 21 deletions

View File

@ -1,4 +1,11 @@
<ReleaseNotes> <ReleaseNotes>
<Changeset component="portlets-widgets.workspace-explorer.2-0-2"
date="${buildDate}">
<Change>[Incident #77436] Fixing class cast Exception for FolderItem son of a SharedFolder
</Change>
<Change>Fixed breadcrumb on SelectDialaog
</Change>
</Changeset>
<Changeset component="portlets-widgets.workspace-explorer.2-0-1" <Changeset component="portlets-widgets.workspace-explorer.2-0-1"
date="${buildDate}"> date="${buildDate}">
<Change>[Task #10943] Removed final to a Constant <Change>[Task #10943] Removed final to a Constant

View File

@ -14,6 +14,7 @@ import org.gcube.common.storagehub.model.acls.ACL;
import org.gcube.common.storagehub.model.items.FolderItem; import org.gcube.common.storagehub.model.items.FolderItem;
import org.gcube.common.storagehub.model.items.Item; import org.gcube.common.storagehub.model.items.Item;
import org.gcube.common.storagehub.model.items.SharedFolder; import org.gcube.common.storagehub.model.items.SharedFolder;
import org.gcube.common.storagehub.model.items.VreFolder;
import com.liferay.portal.kernel.log.Log; import com.liferay.portal.kernel.log.Log;
import com.liferay.portal.kernel.log.LogFactoryUtil; import com.liferay.portal.kernel.log.LogFactoryUtil;
@ -58,7 +59,7 @@ public class StorageHubServiceUtil {
List<? extends Item> toReturn = client.getAnchestors(itemId, ACCOUNTING_HL_NODE_NAME); List<? extends Item> toReturn = client.getAnchestors(itemId, ACCOUNTING_HL_NODE_NAME);
return toReturn; return toReturn;
} }
public static FolderItem createFolder(HttpServletRequest request, String parentId, String name, String description) { public static FolderItem createFolder(HttpServletRequest request, String parentId, String name, String description) {
PortalContext pContext = PortalContext.getConfiguration(); PortalContext pContext = PortalContext.getConfiguration();
String userName = pContext.getCurrentUser(request).getUsername(); String userName = pContext.getCurrentUser(request).getUsername();
@ -72,7 +73,7 @@ public class StorageHubServiceUtil {
} }
/** /**
* *
* @param request * @param request
* @return the VRE Folders Id * @return the VRE Folders Id
*/ */
@ -92,7 +93,7 @@ public class StorageHubServiceUtil {
} catch (Exception e) { } catch (Exception e) {
_log.info("This user has no VRE Folders", e); _log.info("This user has no VRE Folders", e);
return null; return null;
} }
}catch (Exception e) { }catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
@ -108,26 +109,44 @@ public class StorageHubServiceUtil {
ScopeProvider.instance.set(scope); ScopeProvider.instance.set(scope);
SecurityTokenProvider.instance.set(authorizationToken); SecurityTokenProvider.instance.set(authorizationToken);
Item theFolder = getItem(request, folderId); Item theItem = getItem(request, folderId);
if (!theFolder.isShared()) {
return "OWNER"; //IS IT REALLY A FOLDER?
} else { if (theItem instanceof FolderItem){
ItemManagerClient client = AbstractPlugin.item().build(); //THE FOLDER IS NOT SHARED
List<ACL> acls = client.getACL(folderId); if (!theItem.isShared()) {
SharedFolder sharedFolder = (SharedFolder) theFolder; return "OWNER";
} else {
boolean found = false; //this is needed because in case o VRE Foder the permission is assigned ot the group and not to the user. //HERE THE FOLDER IS SHARED
for (ACL acl : acls) { ItemManagerClient client = AbstractPlugin.item().build();
if (acl.getPricipal().compareTo(userName) == 0) { FolderItem folderItem = (FolderItem) theItem;
found = true; SharedFolder sharedfolder;
return acl.getAccessTypes().get(0).toString(); if (theItem instanceof SharedFolder || theItem instanceof VreFolder) {
} ///THE FolderItem IS THE ROOT SHARED FOLDER
} sharedfolder = (SharedFolder) folderItem;
if (!found && sharedFolder.isVreFolder()) {
}else{
//THE FolderItem IS SON OF ROOT SHARED FOLDER SO REQUESTING THE ROOT SHARED FOLDER
sharedfolder = (SharedFolder) client.getRootSharedFolder(folderItem.getId());
_log.warn("This item "+folderId+" is a folder not castable at "+SharedFolder.class.getSimpleName() + " or at "+VreFolder.class.getSimpleName());
}
List<ACL> acls = client.getACL(sharedfolder.getId());
boolean found = false; //this is needed because in case o VRE Foder the permission is assigned to the group and not to the user.
for (ACL acl : acls) { for (ACL acl : acls) {
if (acl.getPricipal().startsWith(pContext.getInfrastructureName())) if (acl.getPricipal().compareTo(userName) == 0) {
found = true;
return acl.getAccessTypes().get(0).toString(); return acl.getAccessTypes().get(0).toString();
}
} }
if (!found && sharedfolder.isVreFolder()) {
for (ACL acl : acls) {
if (acl.getPricipal().startsWith(pContext.getInfrastructureName()))
return acl.getAccessTypes().get(0).toString();
}
}
} }
} }
return "UNDEFINED"; return "UNDEFINED";
@ -135,7 +154,7 @@ public class StorageHubServiceUtil {
/** /**
* *
*/ */
public static int getItemChildrenCount(HttpServletRequest request, String itemId) { public static int getItemChildrenCount(HttpServletRequest request, String itemId) {
PortalContext pContext = PortalContext.getConfiguration(); PortalContext pContext = PortalContext.getConfiguration();