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
This commit is contained in:
Francesco Mangiacrapa 2019-03-06 11:39:23 +00:00
parent b2a2aedce5
commit dfba6ad6bc
1 changed files with 25 additions and 9 deletions

View File

@ -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.exceptions.SessionExpired;
import org.gcube.portlets.user.performfishanalytics.shared.performfishservice.PerformFishInitParameter; import org.gcube.portlets.user.performfishanalytics.shared.performfishservice.PerformFishInitParameter;
import org.gcube.portlets.user.performfishanalytics.shared.performfishservice.PerformFishResponse; import org.gcube.portlets.user.performfishanalytics.shared.performfishservice.PerformFishResponse;
import org.gcube.vomanagement.usermanagement.impl.LiferayGroupManager; import org.gcube.vomanagement.usermanagement.exception.GroupRetrievalFault;
import org.gcube.vomanagement.usermanagement.model.GCubeGroup; 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.gcube.vomanagement.usermanagement.model.GCubeUser;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -285,17 +287,31 @@ public class PerformFishAnalyticsServiceImpl extends RemoteServiceServlet
if(farmId == -1){ if(farmId == -1){
throw new Exception("Your input farm ID seems to be not valid. Please contact the D4Science support"); throw new Exception("Your input farm ID seems to be not valid. Please contact the D4Science support");
} }
List<GCubeGroup> groups = new LiferayGroupManager().listGroupsByUser(userId);
log.debug("Groups retrieved from LR are: "+groups); long groupId;
for (GCubeGroup g : groups) { try {
log.debug("Checking the group id: "+g.getGroupId()); groupId = PortalContext.getConfiguration().getCurrentGroupId(this.getThreadLocalRequest());
if (g.getGroupId() == farmId){ } catch (Exception e) {
log.info("GCubeGroup matching the FARM_ID "+farmId+" found!"); 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<GCubeTeam> 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; 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; return false;
}else{ }else{
//IN TEST MODE NOT CHECKING NOTHING //IN TEST MODE NOT CHECKING NOTHING
log.info("I'm in testing mode, grant the rights to access the farmID {} for current user",farmID); log.info("I'm in testing mode, grant the rights to access the farmID {} for current user",farmID);