feature_27467 #7

Merged
francesco.mangiacrapa merged 4 commits from feature_27467 into master 2024-06-11 11:37:07 +02:00
2 changed files with 116 additions and 87 deletions

View File

@ -36,7 +36,6 @@ import com.google.gwt.user.client.Cookies;
import com.google.gwt.user.client.Window; import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.rpc.AsyncCallback; import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.Frame; import com.google.gwt.user.client.ui.Frame;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.Image; import com.google.gwt.user.client.ui.Image;
import com.google.gwt.user.client.ui.RootPanel; import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.ui.ScrollPanel; import com.google.gwt.user.client.ui.ScrollPanel;

View File

@ -6,6 +6,7 @@ package org.gcube.portlets.gcubeckan.gcubeckandatacatalog.server;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.stream.Collectors;
import javax.servlet.http.HttpSession; import javax.servlet.http.HttpSession;
@ -31,32 +32,30 @@ import org.gcube.vomanagement.usermanagement.model.GatewayRolesNames;
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;
/** /**
* The Class UserUtil. * The Class UserUtil.
*
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
* @author Costantino Perciante costantino.perciante@isti.cnr.it * @author Costantino Perciante costantino.perciante@isti.cnr.it Jun 21, 2016
* Jun 21, 2016
*/ */
public class UserUtil { public class UserUtil {
//private static Logger LOG = LoggerFactory.getLogger(UserUtil.class); // private static Logger LOG = LoggerFactory.getLogger(UserUtil.class);
private static final Log logger = LogFactoryUtil.getLog(UserUtil.class); private static final Log logger = LogFactoryUtil.getLog(UserUtil.class);
private static final String ADD_USER_TO_OTHER_ORG_KEY = "ADD_USER_TO_OTHER_ORG_KEY"; private static final String ADD_USER_TO_OTHER_ORG_KEY = "ADD_USER_TO_OTHER_ORG_KEY";
/** /**
* Gets the list vre for user and the role the user has in them. * Gets the list vre for user and the role the user has in them. retrieve the
* retrieve the groups to whom a given user belongs (given the user EMail) * groups to whom a given user belongs (given the user EMail)
* @param userEMail the user e mail *
* @param httpSession * @param userEMail the user e mail
* @param pathVre * @param httpSession
* @param pathVre
* @return the list vre for user * @return the list vre for user
*/ */
public static Map<String, String> getVreRoleForUser(String userEMail, String context, DataCatalogue instance, boolean isViewPerVREEnabled, public static Map<String, String> getVreRoleForUser(String userEMail, String context, DataCatalogue instance,
HttpSession httpSession){ boolean isViewPerVREEnabled, HttpSession httpSession) {
GroupManager groupManager = new LiferayGroupManager(); GroupManager groupManager = new LiferayGroupManager();
UserManager userManager = new LiferayUserManager(); UserManager userManager = new LiferayUserManager();
@ -66,58 +65,55 @@ public class UserUtil {
try { try {
user = userManager.getUserByEmail(userEMail); user = userManager.getUserByEmail(userEMail);
// filter according the current context: if it is a VO/VRE, we send all the VRES under the VO. If it is the root vo, we send all user's vres. // filter according the current context: if it is a VO/VRE, we send all the VRES
// under the VO. If it is the root vo, we send all user's vres.
long groupIdContext = groupManager.getGroupIdFromInfrastructureScope(context); long groupIdContext = groupManager.getGroupIdFromInfrastructureScope(context);
GCubeGroup currentVRE = groupManager.getGroup(groupIdContext); GCubeGroup currentVRE = groupManager.getGroup(groupIdContext);
String localRoleInThisVre = RolesCkanGroupOrOrg.convertToCkanCapacity(getLiferayHighestRoleInOrg(roleManager.listRolesByUserAndGroup(user.getUserId(), currentVRE.getGroupId()))); String localRoleInThisVre = RolesCkanGroupOrOrg.convertToCkanCapacity(getLiferayHighestRoleInOrg(
roleManager.listRolesByUserAndGroup(user.getUserId(), currentVRE.getGroupId())));
// ckan-connector will do it // ckan-connector will do it
mapRoleByGroupSingleVre.put(currentVRE.getGroupName().toLowerCase(), mapRoleByGroupSingleVre.put(currentVRE.getGroupName().toLowerCase(), localRoleInThisVre);
localRoleInThisVre);
// perform further checks // perform further checks
if(!isViewPerVREEnabled){ if (!isViewPerVREEnabled) {
String keyPerScope = context + ADD_USER_TO_OTHER_ORG_KEY; String keyPerScope = context + ADD_USER_TO_OTHER_ORG_KEY;
Boolean alreadyAdded = (Boolean)httpSession.getAttribute(keyPerScope); Boolean alreadyAdded = (Boolean) httpSession.getAttribute(keyPerScope);
if(alreadyAdded == null || !alreadyAdded){ if (alreadyAdded == null || !alreadyAdded) {
new AddUserToOrganizationThread( new AddUserToOrganizationThread(instance, user, groupManager.listGroupsByUser(user.getUserId()),
instance, isViewPerVREEnabled, groupIdContext, roleManager, groupManager, localRoleInThisVre).start();
user,
groupManager.listGroupsByUser(user.getUserId()),
isViewPerVREEnabled,
groupIdContext,
roleManager,
groupManager,
localRoleInThisVre).
start();
httpSession.setAttribute(keyPerScope, true); httpSession.setAttribute(keyPerScope, true);
} }
} }
logger.debug("Returning Map to the ckan connector : " + mapRoleByGroupSingleVre); logger.debug("Returning Map to the ckan connector : " + mapRoleByGroupSingleVre);
return mapRoleByGroupSingleVre; return mapRoleByGroupSingleVre;
}catch (UserManagementSystemException | UserRetrievalFault | GroupRetrievalFault e) { } catch (UserManagementSystemException | UserRetrievalFault | GroupRetrievalFault e) {
logger.error("An error occurred during get list of VREs for user: "+userEMail, e); logger.error("An error occurred during get list of VREs for user: " + userEMail, e);
return null; return null;
} }
} }
/** /**
* Retrieve the highest ckan role the user has and also retrieve the list of organizations (scopes) in which the user has the ckan-admin or ckan-editor role * Retrieve the highest ckan role the user has and also retrieve the list of
* @param currentScope the current scope * organizations (scopes) in which the user has the ckan-admin or ckan-editor
* @param username the current username * role
* @param groupName the current groupName *
* @param gcubeCkanDataCatalogServiceImpl * @param currentScope the current scope
* @param orgsInWhichAdminRole * @param username the current username
* @param ckanUtils ckanUtils * @param groupName the current groupName
* @param gcubeCkanDataCatalogServiceImpl
* @param orgsInWhichAdminRole
* @param ckanUtils ckanUtils
*/ */
public static RolesCkanGroupOrOrg getHighestRole(String currentScope, String username, String groupName, GcubeCkanDataCatalogServiceImpl gcubeCkanDataCatalogServiceImpl, List<OrganizationBean> orgsInWhichAtLeastEditorRole){ public static RolesCkanGroupOrOrg getHighestRole(String currentScope, String username, String groupName,
GcubeCkanDataCatalogServiceImpl gcubeCkanDataCatalogServiceImpl,
List<OrganizationBean> orgsInWhichAtLeastEditorRole) {
// base role as default value // base role as default value
RolesCkanGroupOrOrg toReturn = RolesCkanGroupOrOrg.MEMBER; RolesCkanGroupOrOrg toReturn = RolesCkanGroupOrOrg.MEMBER;
try{ try {
UserManager userManager = new LiferayUserManager(); UserManager userManager = new LiferayUserManager();
RoleManager roleManager = new LiferayRoleManager(); RoleManager roleManager = new LiferayRoleManager();
@ -135,83 +131,92 @@ public class UserUtil {
List<GCubeGroup> groups = groupManager.listGroupsByUser(userid); List<GCubeGroup> groups = groupManager.listGroupsByUser(userid);
// root (so check into the root, the VOs and the VRES) // root (so check into the root, the VOs and the VRES)
if(groupManager.isRootVO(currentGroupId)){ if (groupManager.isRootVO(currentGroupId)) {
logger.info("The current scope is the Root Vo, so the list of organizations of the user " + username + " is " + groups); logger.info("The current scope is the Root Vo, so the list of organizations of the user " + username
+ " is " + groups);
for (GCubeGroup gCubeGroup : groups) { for (GCubeGroup gCubeGroup : groups) {
if(!groupManager.isVRE(gCubeGroup.getGroupId())) if (!groupManager.isVRE(gCubeGroup.getGroupId()))
continue; continue;
// get the name of this group // get the name of this group
String gCubeGroupName = gCubeGroup.getGroupName(); String gCubeGroupName = gCubeGroup.getGroupName();
// get the role of the users in this group // get the role of the users in this group
List<GCubeRole> roles = roleManager.listRolesByUserAndGroup(userid, groupManager.getGroupId(gCubeGroupName)); List<GCubeRole> roles = roleManager.listRolesByUserAndGroup(userid,
groupManager.getGroupId(gCubeGroupName));
// get highest role // get highest role
RolesCkanGroupOrOrg correspondentRoleToCheck = getLiferayHighestRoleInOrg(roles); RolesCkanGroupOrOrg correspondentRoleToCheck = getLiferayHighestRoleInOrg(roles);
// be sure it is so // be sure it is so
checkIfRoleIsSetInCkanInstance(username, gCubeGroupName, gCubeGroup.getGroupId(), checkIfRoleIsSetInCkanInstance(username, gCubeGroupName, gCubeGroup.getGroupId(),
correspondentRoleToCheck, groupManager, gcubeCkanDataCatalogServiceImpl, orgsInWhichAtLeastEditorRole); correspondentRoleToCheck, groupManager, gcubeCkanDataCatalogServiceImpl,
orgsInWhichAtLeastEditorRole);
toReturn = RolesCkanGroupOrOrg.getHigher(toReturn, correspondentRoleToCheck); toReturn = RolesCkanGroupOrOrg.getHigher(toReturn, correspondentRoleToCheck);
} }
}else if(groupManager.isVO(currentGroupId)){ } else if (groupManager.isVO(currentGroupId)) {
logger.debug("The list of organizations of the user " + username + " to scan is the one under the VO " + groupName); logger.debug("The list of organizations of the user " + username + " to scan is the one under the VO "
+ groupName);
for (GCubeGroup gCubeGroup : groups) { for (GCubeGroup gCubeGroup : groups) {
// if the gCubeGroup is not under the VO or it is not the VO continue // if the gCubeGroup is not under the VO or it is not the VO continue
if(currentGroupId != gCubeGroup.getParentGroupId() || currentGroupId != gCubeGroup.getGroupId()) if (currentGroupId != gCubeGroup.getParentGroupId() || currentGroupId != gCubeGroup.getGroupId())
continue; continue;
String gCubeGroupName = gCubeGroup.getGroupName(); String gCubeGroupName = gCubeGroup.getGroupName();
List<GCubeRole> roles = roleManager.listRolesByUserAndGroup(userid, groupManager.getGroupId(gCubeGroupName)); List<GCubeRole> roles = roleManager.listRolesByUserAndGroup(userid,
groupManager.getGroupId(gCubeGroupName));
// get highest role // get highest role
RolesCkanGroupOrOrg correspondentRoleToCheck = getLiferayHighestRoleInOrg(roles); RolesCkanGroupOrOrg correspondentRoleToCheck = getLiferayHighestRoleInOrg(roles);
// be sure it is so // be sure it is so
checkIfRoleIsSetInCkanInstance(username, gCubeGroupName, gCubeGroup.getGroupId(), checkIfRoleIsSetInCkanInstance(username, gCubeGroupName, gCubeGroup.getGroupId(),
correspondentRoleToCheck, groupManager, gcubeCkanDataCatalogServiceImpl, orgsInWhichAtLeastEditorRole); correspondentRoleToCheck, groupManager, gcubeCkanDataCatalogServiceImpl,
orgsInWhichAtLeastEditorRole);
toReturn = RolesCkanGroupOrOrg.getHigher(toReturn, correspondentRoleToCheck); toReturn = RolesCkanGroupOrOrg.getHigher(toReturn, correspondentRoleToCheck);
} }
}else if(groupManager.isVRE(currentGroupId)){ } else if (groupManager.isVRE(currentGroupId)) {
List<GCubeRole> roles = roleManager.listRolesByUserAndGroup(userManager.getUserId(username), groupManager.getGroupId(groupName)); List<GCubeRole> roles = roleManager.listRolesByUserAndGroup(userManager.getUserId(username),
groupManager.getGroupId(groupName));
logger.debug("The current scope is the vre " + groupName); logger.debug("The current scope is the vre " + groupName);
// get highest role // get highest role
RolesCkanGroupOrOrg correspondentRoleToCheck = getLiferayHighestRoleInOrg(roles); RolesCkanGroupOrOrg correspondentRoleToCheck = getLiferayHighestRoleInOrg(roles);
// the ckan connector already did the job for us but we need name and title // the ckan connector already did the job for us but we need name and title
checkIfRoleIsSetInCkanInstance(username, groupName, currentGroupId, checkIfRoleIsSetInCkanInstance(username, groupName, currentGroupId, correspondentRoleToCheck,
correspondentRoleToCheck, groupManager, gcubeCkanDataCatalogServiceImpl, orgsInWhichAtLeastEditorRole); groupManager, gcubeCkanDataCatalogServiceImpl, orgsInWhichAtLeastEditorRole);
toReturn = correspondentRoleToCheck; toReturn = correspondentRoleToCheck;
} }
}catch(Exception e){ } catch (Exception e) {
logger.error("Unable to retrieve the role information for this user. Returning member role", e); logger.error("Unable to retrieve the role information for this user. Returning member role", e);
return RolesCkanGroupOrOrg.MEMBER; return RolesCkanGroupOrOrg.MEMBER;
} }
// return the role // return the role
logger.debug("Returning role " + toReturn + " for user " + username); logger.debug("Returning role " + toReturn + " for user " + username);
return toReturn; return toReturn;
} }
/** /**
* Check if the role admin/editor is set or must be set into the ckan instance at this scope * Check if the role admin/editor is set or must be set into the ckan instance
* at this scope
*
* @param username * @param username
* @param gCubeGroupName * @param gCubeGroupName
* @param groupId * @param groupId
@ -222,47 +227,72 @@ public class UserUtil {
* @throws UserManagementSystemException * @throws UserManagementSystemException
* @throws GroupRetrievalFault * @throws GroupRetrievalFault
*/ */
private static void checkIfRoleIsSetInCkanInstance(String username, private static void checkIfRoleIsSetInCkanInstance(String username, String gCubeGroupName, long groupId,
String gCubeGroupName, long groupId, RolesCkanGroupOrOrg correspondentRoleToCheck, GroupManager groupManager,
RolesCkanGroupOrOrg correspondentRoleToCheck, GcubeCkanDataCatalogServiceImpl gcubeCkanDataCatalogServiceImpl,
GroupManager groupManager, List<OrganizationBean> orgsInWhichAtLeastEditorRole)
GcubeCkanDataCatalogServiceImpl gcubeCkanDataCatalogServiceImpl, List<OrganizationBean> orgsInWhichAtLeastEditorRole) throws UserManagementSystemException, GroupRetrievalFault { throws UserManagementSystemException, GroupRetrievalFault {
// with this invocation, we check if the role is present in ckan and if it is not it will be added // with this invocation, we check if the role is present in ckan and if it is
DataCatalogue catalogue = gcubeCkanDataCatalogServiceImpl.getCatalogue(groupManager.getInfrastructureScope(groupId)); // not it will be added
DataCatalogue catalogue = gcubeCkanDataCatalogServiceImpl
.getCatalogue(groupManager.getInfrastructureScope(groupId));
// if there is an instance of ckan in this scope.. // if there is an instance of ckan in this scope..
if(catalogue != null){ if (catalogue != null) {
boolean res = catalogue.checkRoleIntoOrganization(username, gCubeGroupName, correspondentRoleToCheck); boolean res = catalogue.checkRoleIntoOrganization(username, gCubeGroupName, correspondentRoleToCheck);
if(res && !correspondentRoleToCheck.equals(RolesCkanGroupOrOrg.MEMBER)){ if (res && !correspondentRoleToCheck.equals(RolesCkanGroupOrOrg.MEMBER)) {
// get the orgs of the user and retrieve its title and name // get the orgs of the user and retrieve its title and name
CkanOrganization organization = catalogue.getOrganizationByName(gCubeGroupName.toLowerCase()); CkanOrganization organization = catalogue.getOrganizationByName(gCubeGroupName.toLowerCase());
orgsInWhichAtLeastEditorRole.add(new OrganizationBean(organization.getTitle(), organization.getName(), true)); orgsInWhichAtLeastEditorRole
.add(new OrganizationBean(organization.getTitle(), organization.getName(), true));
} }
} } else
else logger.warn(
logger.warn("It seems there is no ckan instance into scope " + groupManager.getInfrastructureScope(groupId)); "It seems there is no ckan instance into scope " + groupManager.getInfrastructureScope(groupId));
} }
/** /**
* Retrieve the ckan role among a list of liferay roles * Retrieve the ckan role among a list of liferay roles
*
* @param roles * @param roles
* @return MEMBER/EDITOR/ADMIN role * @return MEMBER/EDITOR/ADMIN role
*/ */
public static RolesCkanGroupOrOrg getLiferayHighestRoleInOrg( public static RolesCkanGroupOrOrg getLiferayHighestRoleInOrg(List<GCubeRole> roles) {
List<GCubeRole> roles) { logger.info("getLiferayHighestRoleInOrg in: " + roles);
// NOTE: it is supposed that there is just one role for this person correspondent to the one in the catalog RolesCkanGroupOrOrg highestRoleFound = null;
for (GCubeRole gCubeRole : roles) {
if(gCubeRole.getRoleName().equalsIgnoreCase(GatewayRolesNames.CATALOGUE_ADMIN.getRoleName())){ if(roles==null || roles.isEmpty()) {
return RolesCkanGroupOrOrg.ADMIN; highestRoleFound = RolesCkanGroupOrOrg.MEMBER;
} logger.info("getLiferayHighestRoleInOrg returns: " + highestRoleFound +", as default");
if(gCubeRole.getRoleName().equalsIgnoreCase(GatewayRolesNames.CATALOGUE_EDITOR.getRoleName())){ return highestRoleFound;
return RolesCkanGroupOrOrg.EDITOR;
}
} }
return RolesCkanGroupOrOrg.MEMBER;
List<GCubeRole> adminList = roles.stream()
.filter(a -> a.getRoleName().equalsIgnoreCase(GatewayRolesNames.CATALOGUE_ADMIN.getRoleName()))
.collect(Collectors.toList());
if (adminList.size() > 0) {
highestRoleFound = RolesCkanGroupOrOrg.ADMIN;
logger.info("getLiferayHighestRoleInOrg returns: " + highestRoleFound);
return highestRoleFound;
}
List<GCubeRole> editorList = roles.stream()
.filter(a -> a.getRoleName().equalsIgnoreCase(GatewayRolesNames.CATALOGUE_EDITOR.getRoleName()))
.collect(Collectors.toList());
if (editorList.size() > 0) {
highestRoleFound = RolesCkanGroupOrOrg.EDITOR;
logger.info("getLiferayHighestRoleInOrg returns: " + highestRoleFound);
return highestRoleFound;
}
highestRoleFound = RolesCkanGroupOrOrg.MEMBER;
logger.info("getLiferayHighestRoleInOrg returns: " + highestRoleFound);
return highestRoleFound;
} }
} }