From dfba6ad6bc87fe8e0e4ff55554f93957430719a7 Mon Sep 17 00:00:00 2001 From: Francesco Mangiacrapa Date: Wed, 6 Mar 2019 11:39:23 +0000 Subject: [PATCH] updating the checkGrantToAccessFarmID git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/user/performfish-analytics-portlet@178491 82a268e6-3cf1-43bd-a215-b396298e98cf --- .../PerformFishAnalyticsServiceImpl.java | 34 ++++++++++++++----- 1 file changed, 25 insertions(+), 9 deletions(-) diff --git a/src/main/java/org/gcube/portlets/user/performfishanalytics/server/PerformFishAnalyticsServiceImpl.java b/src/main/java/org/gcube/portlets/user/performfishanalytics/server/PerformFishAnalyticsServiceImpl.java index ad2ef16..d4ab48f 100644 --- a/src/main/java/org/gcube/portlets/user/performfishanalytics/server/PerformFishAnalyticsServiceImpl.java +++ b/src/main/java/org/gcube/portlets/user/performfishanalytics/server/PerformFishAnalyticsServiceImpl.java @@ -50,8 +50,10 @@ import org.gcube.portlets.user.performfishanalytics.shared.dataminer.DataMinerRe import org.gcube.portlets.user.performfishanalytics.shared.exceptions.SessionExpired; import org.gcube.portlets.user.performfishanalytics.shared.performfishservice.PerformFishInitParameter; import org.gcube.portlets.user.performfishanalytics.shared.performfishservice.PerformFishResponse; -import org.gcube.vomanagement.usermanagement.impl.LiferayGroupManager; -import org.gcube.vomanagement.usermanagement.model.GCubeGroup; +import org.gcube.vomanagement.usermanagement.exception.GroupRetrievalFault; +import org.gcube.vomanagement.usermanagement.exception.UserRetrievalFault; +import org.gcube.vomanagement.usermanagement.impl.LiferayRoleManager; +import org.gcube.vomanagement.usermanagement.model.GCubeTeam; import org.gcube.vomanagement.usermanagement.model.GCubeUser; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -285,17 +287,31 @@ public class PerformFishAnalyticsServiceImpl extends RemoteServiceServlet if(farmId == -1){ throw new Exception("Your input farm ID seems to be not valid. Please contact the D4Science support"); } - List groups = new LiferayGroupManager().listGroupsByUser(userId); - log.debug("Groups retrieved from LR are: "+groups); - for (GCubeGroup g : groups) { - log.debug("Checking the group id: "+g.getGroupId()); - if (g.getGroupId() == farmId){ - log.info("GCubeGroup matching the FARM_ID "+farmId+" found!"); + + long groupId; + try { + groupId = PortalContext.getConfiguration().getCurrentGroupId(this.getThreadLocalRequest()); + } catch (Exception e) { + log.error("Error getting the group id: ",e); + throw new Exception("Your input farm ID seems to be not valid. Please contact the D4Science support"); + } + log.debug("The group id is: "+groupId); + + List teams = new ArrayList<>(); + try { + teams = new LiferayRoleManager().listTeamsByUserAndGroup(userId, groupId); + } catch (UserRetrievalFault | GroupRetrievalFault e) { + log.warn("Error listing the GCubeTeams: ",e); + } + for (GCubeTeam team : teams) { + if (team.getTeamId() == farmId) { + log.info(GCubeTeam.class.getSimpleName() +" matching the FARM_ID "+farmId+" FOUND!"); return true; } } - log.info("GCubeGroup matching the FARM_ID "+farmId+" NOT found!"); + log.info(GCubeTeam.class.getSimpleName() +" matching the FARM_ID "+farmId+" NOT FOUND!"); return false; + }else{ //IN TEST MODE NOT CHECKING NOTHING log.info("I'm in testing mode, grant the rights to access the farmID {} for current user",farmID);