|
|
|
@ -10,15 +10,7 @@ import java.util.Map;
|
|
|
|
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
|
|
|
|
|
|
|
//import org.gcube.common.homelibrary.home.HomeLibrary;
|
|
|
|
|
//import org.gcube.common.homelibrary.home.exceptions.HomeNotFoundException;
|
|
|
|
|
//import org.gcube.common.homelibrary.home.exceptions.InternalErrorException;
|
|
|
|
|
//import org.gcube.common.homelibrary.home.workspace.Workspace;
|
|
|
|
|
//import org.gcube.common.homelibrary.home.workspace.exceptions.WorkspaceFolderNotFoundException;
|
|
|
|
|
import org.gcube.common.portal.PortalContext;
|
|
|
|
|
import org.gcube.common.scope.api.ScopeProvider;
|
|
|
|
|
import org.gcube.common.storagehubwrapper.server.StorageHubWrapper;
|
|
|
|
|
import org.gcube.common.storagehubwrapper.server.tohl.Workspace;
|
|
|
|
|
import org.gcube.portlets.widgets.wsthreddssync.shared.GatewayRolesThredds;
|
|
|
|
|
import org.gcube.vomanagement.usermanagement.GroupManager;
|
|
|
|
|
import org.gcube.vomanagement.usermanagement.RoleManager;
|
|
|
|
@ -39,17 +31,13 @@ import com.liferay.portal.service.UserLocalServiceUtil;
|
|
|
|
|
/**
|
|
|
|
|
* The Class WsUtil.
|
|
|
|
|
*
|
|
|
|
|
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
|
|
|
|
|
* Nov 25, 2016
|
|
|
|
|
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it Nov 25, 2016
|
|
|
|
|
*/
|
|
|
|
|
public class WsUtil {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** The logger. */
|
|
|
|
|
private static Logger logger = LoggerFactory.getLogger(WsUtil.class);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Checks if is within portal.
|
|
|
|
|
*
|
|
|
|
@ -59,14 +47,12 @@ public class WsUtil {
|
|
|
|
|
try {
|
|
|
|
|
UserLocalServiceUtil.getService();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex) {
|
|
|
|
|
} catch (Exception ex) {
|
|
|
|
|
logger.trace("Development Mode ON");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Checks if is session expired.
|
|
|
|
|
*
|
|
|
|
@ -76,119 +62,86 @@ public class WsUtil {
|
|
|
|
|
*/
|
|
|
|
|
public static boolean isSessionExpired(HttpServletRequest httpServletRequest) throws Exception {
|
|
|
|
|
logger.trace("workspace session validating...");
|
|
|
|
|
return PortalContext.getConfiguration().getCurrentUser(httpServletRequest)==null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Gets the workspace from storage hub.
|
|
|
|
|
*
|
|
|
|
|
* @param httpServletRequest the http servlet request
|
|
|
|
|
* @return the workspace from storage hub
|
|
|
|
|
* @throws Exception the exception
|
|
|
|
|
*/
|
|
|
|
|
public Workspace getWorkspaceFromStorageHub(HttpServletRequest httpServletRequest) throws Exception {
|
|
|
|
|
logger.trace("Get Workspace");
|
|
|
|
|
// String scope = PortalContext.getConfiguration().getCurrentScope(httpServletRequest);
|
|
|
|
|
|
|
|
|
|
GCubeUser user = null;
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
String scope = PortalContext.getConfiguration().getCurrentScope(httpServletRequest);
|
|
|
|
|
user = PortalContext.getConfiguration().getCurrentUser(httpServletRequest);
|
|
|
|
|
if (user == null || user.getUsername().isEmpty())
|
|
|
|
|
throw new Exception("Session expired");
|
|
|
|
|
|
|
|
|
|
ScopeProvider.instance.set(scope);
|
|
|
|
|
logger.trace("Scope provider instancied at: "+scope);
|
|
|
|
|
|
|
|
|
|
logger.debug("Getting " + StorageHubWrapper.class.getSimpleName() + " for user: " + user.getUsername()
|
|
|
|
|
+ " by using the scope: " + scope);
|
|
|
|
|
|
|
|
|
|
String token = PortalContext.getConfiguration().getCurrentUserToken(scope, user.getUsername());
|
|
|
|
|
StorageHubWrapper shWrapper = new StorageHubWrapper(scope, token, false, false, true);
|
|
|
|
|
return shWrapper.getWorkspace();
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
logger.error("Error on getting the Workspace via SHUB wrapper", e);
|
|
|
|
|
throw new Exception("Error on gettig the Workspace for userId: " + user);
|
|
|
|
|
}
|
|
|
|
|
return PortalContext.getConfiguration().getCurrentUser(httpServletRequest) == null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Gets the list of Scopes (Root-VO, VOs and VREs) for user and the Thredds roles that user has in them.
|
|
|
|
|
* Gets the list of Scopes (Root-VO, VOs and VREs) for user and the Thredds
|
|
|
|
|
* roles that user has in them.
|
|
|
|
|
*
|
|
|
|
|
* @param user the user
|
|
|
|
|
* @return the VREs and Thredds roles for a given user
|
|
|
|
|
*/
|
|
|
|
|
public static Map<String, GatewayRolesThredds> getScopesWithThreddsRolesForUser(GCubeUser user){
|
|
|
|
|
logger.info("called getScopesThreddsRolesForUser user: "+user+", in all contexts");
|
|
|
|
|
|
|
|
|
|
public static Map<String, GatewayRolesThredds> getScopesWithThreddsRolesForUser(GCubeUser user) {
|
|
|
|
|
logger.info("called getScopesThreddsRolesForUser user: " + user + ", in all contexts");
|
|
|
|
|
|
|
|
|
|
GroupManager groupManager = new LiferayGroupManager();
|
|
|
|
|
Map<String, GatewayRolesThredds> mapRoleByGroupSingleVre = new HashMap<String, GatewayRolesThredds>();
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
|
|
//Retrieving the list of VOs and VREs
|
|
|
|
|
|
|
|
|
|
// Retrieving the list of VOs and VREs
|
|
|
|
|
List<GCubeGroup> listOfGroups = groupManager.listGroupsByUser(user.getUserId());
|
|
|
|
|
//adding also the ROOT-VO
|
|
|
|
|
// adding also the ROOT-VO
|
|
|
|
|
listOfGroups.add(groupManager.getRootVO());
|
|
|
|
|
for (GCubeGroup gCubeGroup : listOfGroups) {
|
|
|
|
|
GatewayRolesThredds threddsRole = getThreddsRoleFor(user, gCubeGroup);
|
|
|
|
|
if(threddsRole != null) {
|
|
|
|
|
if (threddsRole != null) {
|
|
|
|
|
String toFullScope = groupManager.getInfrastructureScope(gCubeGroup.getGroupId());
|
|
|
|
|
mapRoleByGroupSingleVre.put(toFullScope, threddsRole);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
logger.info("For user: "+user+", returning Map (VRE, ThreddsRoles) " + mapRoleByGroupSingleVre);
|
|
|
|
|
|
|
|
|
|
logger.info("For user: " + user + ", returning Map (VRE, ThreddsRoles) " + mapRoleByGroupSingleVre);
|
|
|
|
|
return mapRoleByGroupSingleVre;
|
|
|
|
|
}catch (UserManagementSystemException | UserRetrievalFault | GroupRetrievalFault e) {
|
|
|
|
|
logger.error("An error occurred during geThreddsVreRolesForUser: "+user, e);
|
|
|
|
|
} catch (UserManagementSystemException | UserRetrievalFault | GroupRetrievalFault e) {
|
|
|
|
|
logger.error("An error occurred during geThreddsVreRolesForUser: " + user, e);
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Gets the (highest) thredds role for the user in the scope
|
|
|
|
|
*
|
|
|
|
|
* @param user the user
|
|
|
|
|
* @param user the user
|
|
|
|
|
* @param scope the vre
|
|
|
|
|
* @return the thredds role for
|
|
|
|
|
*/
|
|
|
|
|
public static GatewayRolesThredds getThreddsRoleFor(GCubeUser user, GCubeGroup scope){
|
|
|
|
|
if(user==null || scope==null) {
|
|
|
|
|
logger.warn("called getThreddsRoleFor with invalid parameter user: "+user+", in the scope: "+scope, ", returning null");
|
|
|
|
|
public static GatewayRolesThredds getThreddsRoleFor(GCubeUser user, GCubeGroup scope) {
|
|
|
|
|
if (user == null || scope == null) {
|
|
|
|
|
logger.warn("called getThreddsRoleFor with invalid parameter user: " + user + ", in the scope: " + scope,
|
|
|
|
|
", returning null");
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
logger.info("called getThreddsRoleFor user: "+user.getUsername()+", in the scope: "+scope.getGroupName());
|
|
|
|
|
|
|
|
|
|
logger.info("called getThreddsRoleFor user: " + user.getUsername() + ", in the scope: " + scope.getGroupName());
|
|
|
|
|
try {
|
|
|
|
|
RoleManager roleManager = new LiferayRoleManager();
|
|
|
|
|
List<GCubeRole> roles = roleManager.listRolesByUserAndGroup(user.getUserId(), scope.getGroupId());
|
|
|
|
|
List<GatewayRolesThredds> threddsRoles = new ArrayList<GatewayRolesThredds>();
|
|
|
|
|
for (GCubeRole gCubeRole : roles) {
|
|
|
|
|
if(gCubeRole.getRoleName().equalsIgnoreCase(GatewayRolesThredds.DATA_MANAGER.getRoleName())){
|
|
|
|
|
if (gCubeRole.getRoleName().equalsIgnoreCase(GatewayRolesThredds.DATA_MANAGER.getRoleName())) {
|
|
|
|
|
threddsRoles.add(GatewayRolesThredds.DATA_MANAGER);
|
|
|
|
|
}
|
|
|
|
|
if(gCubeRole.getRoleName().equalsIgnoreCase(GatewayRolesThredds.DATA_EDITOR.getRoleName())){
|
|
|
|
|
if (gCubeRole.getRoleName().equalsIgnoreCase(GatewayRolesThredds.DATA_EDITOR.getRoleName())) {
|
|
|
|
|
threddsRoles.add(GatewayRolesThredds.DATA_EDITOR);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
logger.info("For user: "+user.getUsername()+" in the scope: "+scope.getGroupName()+" read the role/s: " + threddsRoles);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
logger.info("For user: " + user.getUsername() + " in the scope: " + scope.getGroupName()
|
|
|
|
|
+ " read the role/s: " + threddsRoles);
|
|
|
|
|
|
|
|
|
|
GatewayRolesThredds toReturn = null;
|
|
|
|
|
if (threddsRoles.contains(GatewayRolesThredds.DATA_MANAGER))
|
|
|
|
|
toReturn = GatewayRolesThredds.DATA_MANAGER;
|
|
|
|
|
else if (threddsRoles.contains(GatewayRolesThredds.DATA_EDITOR))
|
|
|
|
|
toReturn = GatewayRolesThredds.DATA_EDITOR;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
logger.info("returning highest role: " + toReturn);
|
|
|
|
|
return toReturn;
|
|
|
|
|
}catch (UserRetrievalFault | GroupRetrievalFault e) {
|
|
|
|
|
logger.error("An error occurred during getVreRoleForUser: "+user, e);
|
|
|
|
|
} catch (UserRetrievalFault | GroupRetrievalFault e) {
|
|
|
|
|
logger.error("An error occurred during getVreRoleForUser: " + user, e);
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|