This commit is contained in:
Massimiliano Assante 2018-05-29 12:47:08 +00:00
parent de0f8b49ba
commit 2308b24a1b
1 changed files with 24 additions and 10 deletions

View File

@ -12,6 +12,8 @@ import org.gcube.common.storagehub.client.proxies.ItemManagerClient;
import org.gcube.common.storagehub.client.proxies.WorkspaceManagerClient;
import org.gcube.common.storagehub.model.acls.ACL;
import org.gcube.common.storagehub.model.items.Item;
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.LogFactoryUtil;
@ -32,7 +34,7 @@ public class StorageHubServiceUtil {
Item itemRoot = client.getWorkspace(ACCOUNTING_HL_NODE_NAME);
return itemRoot;
}
public static Item getItem(HttpServletRequest request, String itemId) {
PortalContext pContext = PortalContext.getConfiguration();
String userName = pContext.getCurrentUser(request).getUsername();
@ -44,7 +46,7 @@ public class StorageHubServiceUtil {
Item toReturn = client.get(itemId, ACCOUNTING_HL_NODE_NAME);
return toReturn;
}
public static List<? extends Item> getParents(HttpServletRequest request, String itemId) {
PortalContext pContext = PortalContext.getConfiguration();
String userName = pContext.getCurrentUser(request).getUsername();
@ -56,7 +58,7 @@ public class StorageHubServiceUtil {
List<? extends Item> toReturn = client.getAnchestors(itemId, ACCOUNTING_HL_NODE_NAME);
return toReturn;
}
/**
*
* @param request
@ -84,8 +86,8 @@ public class StorageHubServiceUtil {
}
return toReturn;
}
public static String getUserACLForFolderId(HttpServletRequest request, String folderId) {
PortalContext pContext = PortalContext.getConfiguration();
String userName = pContext.getCurrentUser(request).getUsername();
@ -93,22 +95,34 @@ public class StorageHubServiceUtil {
String authorizationToken = pContext.getCurrentUserToken(scope, userName);
ScopeProvider.instance.set(scope);
SecurityTokenProvider.instance.set(authorizationToken);
Item theFolder = getItem(request, folderId);
if (!theFolder.isShared()) {
return "OWNER";
} else {
ItemManagerClient client = AbstractPlugin.item().build();
List<ACL> acls = client.getACL(folderId);
SharedFolder sharedFolder = (SharedFolder) theFolder;
boolean found = false; //this is needed because in case o VRE Foder the permission is assigned ot the group and not to the user.
for (ACL acl : acls) {
if (acl.getPricipal().compareTo(userName) == 0)
return acl.getAccessTypes().toString();
System.out.println("ACL: "+acl.getPricipal().toString() + " types: "+ acl.getAccessTypes().toString());
if (acl.getPricipal().compareTo(userName) == 0) {
found = true;
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 "NO PERMISSIONS";
return "UNDEFINED";
}
/**
*
*/