updated methods for performance improvement
This commit is contained in:
parent
707659a994
commit
8b945a4993
|
@ -12,15 +12,19 @@ import org.gcube.common.storagehub.client.dsl.StorageHubClient;
|
||||||
import org.gcube.common.storagehub.client.dsl.Util;
|
import org.gcube.common.storagehub.client.dsl.Util;
|
||||||
import org.gcube.common.storagehub.client.dsl.VREFolderManager;
|
import org.gcube.common.storagehub.client.dsl.VREFolderManager;
|
||||||
import org.gcube.vomanagement.usermanagement.GroupManager;
|
import org.gcube.vomanagement.usermanagement.GroupManager;
|
||||||
|
import org.gcube.vomanagement.usermanagement.RoleManager;
|
||||||
import org.gcube.vomanagement.usermanagement.impl.LiferayGroupManager;
|
import org.gcube.vomanagement.usermanagement.impl.LiferayGroupManager;
|
||||||
|
import org.gcube.vomanagement.usermanagement.impl.LiferayRoleManager;
|
||||||
import org.gcube.vomanagement.usermanagement.impl.LiferayUserManager;
|
import org.gcube.vomanagement.usermanagement.impl.LiferayUserManager;
|
||||||
import org.gcube.vomanagement.usermanagement.model.GCubeRole;
|
import org.gcube.vomanagement.usermanagement.model.GCubeRole;
|
||||||
|
import org.gcube.vomanagement.usermanagement.model.GatewayRolesNames;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import com.liferay.portal.kernel.exception.PortalException;
|
import com.liferay.portal.kernel.exception.PortalException;
|
||||||
import com.liferay.portal.kernel.exception.SystemException;
|
import com.liferay.portal.kernel.exception.SystemException;
|
||||||
import com.liferay.portal.model.Role;
|
import com.liferay.portal.model.Role;
|
||||||
|
import com.liferay.portal.model.User;
|
||||||
import com.liferay.portal.model.UserGroupRole;
|
import com.liferay.portal.model.UserGroupRole;
|
||||||
import com.liferay.portal.service.RoleLocalServiceUtil;
|
import com.liferay.portal.service.RoleLocalServiceUtil;
|
||||||
import com.liferay.portal.service.UserGroupRoleLocalService;
|
import com.liferay.portal.service.UserGroupRoleLocalService;
|
||||||
|
@ -54,10 +58,10 @@ public class GCubeHookSiteRoleLocalService extends UserGroupRoleLocalServiceWrap
|
||||||
try {
|
try {
|
||||||
String context = gm.getInfrastructureScope(groupId);
|
String context = gm.getInfrastructureScope(groupId);
|
||||||
String username = UserLocalServiceUtil.getUser(userId).getScreenName();
|
String username = UserLocalServiceUtil.getUser(userId).getScreenName();
|
||||||
/* Commenting this part as when the user is just created it fails*/
|
/* Check this part CAREFULLY as when the user is just created it fails*/
|
||||||
// String userToken = authorizationService().resolveTokenByUserAndContext(username, context);
|
String userToken = authorizationService().resolveTokenByUserAndContext(username, context);
|
||||||
// List<String> userRoles = getUserRoles(roleIds);
|
List<String> userRoles = getUserRoles(roleIds);
|
||||||
// authorizationService().setTokenRoles(userToken, userRoles);
|
authorizationService().setTokenRoles(userToken, userRoles);
|
||||||
_log.debug("Check if addUserGroupRoles is done in a VRE");
|
_log.debug("Check if addUserGroupRoles is done in a VRE");
|
||||||
if (gm.isVRE(groupId)) {
|
if (gm.isVRE(groupId)) {
|
||||||
_log.debug("addUserGroupRoles performed in a VRE, groupId=" + groupId);
|
_log.debug("addUserGroupRoles performed in a VRE, groupId=" + groupId);
|
||||||
|
@ -103,27 +107,26 @@ public class GCubeHookSiteRoleLocalService extends UserGroupRoleLocalServiceWrap
|
||||||
String previousToken = SecurityTokenProvider.instance.get();
|
String previousToken = SecurityTokenProvider.instance.get();
|
||||||
//get the super user
|
//get the super user
|
||||||
_log.info("//get the super user");
|
_log.info("//get the super user");
|
||||||
|
|
||||||
String infraContext = "/"+PortalContext.getConfiguration().getInfrastructureName();
|
String infraContext = "/"+PortalContext.getConfiguration().getInfrastructureName();
|
||||||
// long rootgroupId = gm.getGroupIdFromInfrastructureScope(infraContext);
|
long rootgroupId = gm.getGroupIdFromInfrastructureScope(infraContext);
|
||||||
// RoleManager rm = new LiferayRoleManager();
|
User theAdmin = LiferayUserManager.getRandomUserWithRole(rootgroupId, GatewayRolesNames.INFRASTRUCTURE_MANAGER);
|
||||||
// long roleId = rm.getRoleId(HookConstants.AUTORISED_INFRA_ROLE, rootgroupId);
|
if (theAdmin == null) {
|
||||||
// List<GCubeUser> users = uMan.listUsersByGroupAndRole(rootgroupId, roleId);
|
_log.warn("Cannot add the user as VRE Folder admin: there is no user having role " + GatewayRolesNames.INFRASTRUCTURE_MANAGER);
|
||||||
// if (users.isEmpty()) {
|
return false;
|
||||||
// _log.error("Cannot add the user as VRE Folder admin: there is no user having role {} on context: {}", HookConstants.AUTORISED_INFRA_ROLE, infraContext);
|
}
|
||||||
// return false;
|
else {
|
||||||
// }
|
RoleManager rm = new LiferayRoleManager();
|
||||||
// else {
|
String adminUsername = theAdmin.getScreenName();
|
||||||
//GCubeUser theAdmin = users.get(0);
|
_log.info("Got the super user: " +adminUsername);
|
||||||
String adminUsername = "lucio.lelii";
|
|
||||||
_log.info("Got the super user: {}",adminUsername);
|
|
||||||
String theAdminToken = PortalContext.getConfiguration().getCurrentUserToken(infraContext, adminUsername);
|
String theAdminToken = PortalContext.getConfiguration().getCurrentUserToken(infraContext, adminUsername);
|
||||||
List<String> rolesString = new ArrayList<String>();
|
List<String> rolesString = new ArrayList<String>();
|
||||||
// List<GCubeRole> theAdminRoles = rm.listRolesByUserAndGroup(theAdmin.getUserId(), rootgroupId);
|
List<GCubeRole> theAdminRoles = rm.listRolesByUserAndGroup(theAdmin.getUserId(), rootgroupId);
|
||||||
// for (GCubeRole gCubeRole : theAdminRoles) {
|
for (GCubeRole gCubeRole : theAdminRoles) {
|
||||||
// rolesString.add(gCubeRole.getRoleName());
|
rolesString.add(gCubeRole.getRoleName());
|
||||||
// }
|
}
|
||||||
rolesString.add("Infrastructure-Manager");
|
rolesString.add(GatewayRolesNames.INFRASTRUCTURE_MANAGER.getRoleName());
|
||||||
_log.info("authorizationService().setTokenRoles(theAdminToken, rolesString);",theAdminToken);
|
_log.info("authorizationService().setTokenRoles(theAdminToken, rolesString);" +theAdminToken);
|
||||||
authorizationService().setTokenRoles(theAdminToken, rolesString);
|
authorizationService().setTokenRoles(theAdminToken, rolesString);
|
||||||
SecurityTokenProvider.instance.set(theAdminToken);
|
SecurityTokenProvider.instance.set(theAdminToken);
|
||||||
|
|
||||||
|
@ -135,7 +138,7 @@ public class GCubeHookSiteRoleLocalService extends UserGroupRoleLocalServiceWrap
|
||||||
vreFolderManager.removeAdmin(theUserToPromoteOrDeclass);
|
vreFolderManager.removeAdmin(theUserToPromoteOrDeclass);
|
||||||
SecurityTokenProvider.instance.set(previousToken);
|
SecurityTokenProvider.instance.set(previousToken);
|
||||||
return true;
|
return true;
|
||||||
// }
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -13,7 +13,6 @@ import org.gcube.common.storagehub.client.proxies.GroupManagerClient;
|
||||||
import org.gcube.portal.plugins.thread.CheckShareLatexUserThread;
|
import org.gcube.portal.plugins.thread.CheckShareLatexUserThread;
|
||||||
import org.gcube.portal.plugins.thread.RemoveUserTokenFromVREThread;
|
import org.gcube.portal.plugins.thread.RemoveUserTokenFromVREThread;
|
||||||
import org.gcube.portal.plugins.thread.UpdateUserToLDAPGroupThread;
|
import org.gcube.portal.plugins.thread.UpdateUserToLDAPGroupThread;
|
||||||
import org.gcube.portal.plugins.util.HookConstants;
|
|
||||||
import org.gcube.vomanagement.usermanagement.GroupManager;
|
import org.gcube.vomanagement.usermanagement.GroupManager;
|
||||||
import org.gcube.vomanagement.usermanagement.RoleManager;
|
import org.gcube.vomanagement.usermanagement.RoleManager;
|
||||||
import org.gcube.vomanagement.usermanagement.UserManager;
|
import org.gcube.vomanagement.usermanagement.UserManager;
|
||||||
|
@ -21,7 +20,7 @@ import org.gcube.vomanagement.usermanagement.impl.LiferayGroupManager;
|
||||||
import org.gcube.vomanagement.usermanagement.impl.LiferayRoleManager;
|
import org.gcube.vomanagement.usermanagement.impl.LiferayRoleManager;
|
||||||
import org.gcube.vomanagement.usermanagement.impl.LiferayUserManager;
|
import org.gcube.vomanagement.usermanagement.impl.LiferayUserManager;
|
||||||
import org.gcube.vomanagement.usermanagement.model.GCubeRole;
|
import org.gcube.vomanagement.usermanagement.model.GCubeRole;
|
||||||
import org.gcube.vomanagement.usermanagement.model.GCubeUser;
|
import org.gcube.vomanagement.usermanagement.model.GatewayRolesNames;
|
||||||
|
|
||||||
import com.liferay.portal.kernel.exception.SystemException;
|
import com.liferay.portal.kernel.exception.SystemException;
|
||||||
import com.liferay.portal.kernel.log.Log;
|
import com.liferay.portal.kernel.log.Log;
|
||||||
|
@ -155,25 +154,23 @@ public class GCubeHookUserLocalService extends UserLocalServiceWrapper {
|
||||||
String previousToken = SecurityTokenProvider.instance.get();
|
String previousToken = SecurityTokenProvider.instance.get();
|
||||||
//get the super user
|
//get the super user
|
||||||
String infraContext = "/"+PortalContext.getConfiguration().getInfrastructureName();
|
String infraContext = "/"+PortalContext.getConfiguration().getInfrastructureName();
|
||||||
// long rootgroupId = gm.getGroupIdFromInfrastructureScope(infraContext);
|
long rootgroupId = gm.getGroupIdFromInfrastructureScope(infraContext);
|
||||||
// RoleManager rm = new LiferayRoleManager();
|
User theAdmin = LiferayUserManager.getRandomUserWithRole(rootgroupId, GatewayRolesNames.INFRASTRUCTURE_MANAGER);
|
||||||
// long roleId = rm.getRoleId(HookConstants.AUTORISED_INFRA_ROLE, rootgroupId);
|
if (theAdmin == null) {
|
||||||
// List<GCubeUser> users = uMan.listUsersByGroupAndRole(rootgroupId, roleId);
|
_log.warn("Cannot add the user as VRE Folder admin: there is no user having role " + GatewayRolesNames.INFRASTRUCTURE_MANAGER);
|
||||||
// if (users.isEmpty()) {
|
return false;
|
||||||
// _log.error("Cannot add the user as VRE Folder admin: there is no user having role {} on context: {}", HookConstants.AUTORISED_INFRA_ROLE, infraContext);
|
}
|
||||||
// return false;
|
else {
|
||||||
// }
|
RoleManager rm = new LiferayRoleManager();
|
||||||
// else {
|
String adminUsername = theAdmin.getScreenName();
|
||||||
//GCubeUser theAdmin = users.get(0);
|
|
||||||
String adminUsername = "lucio.lelii";
|
|
||||||
_log.info("Got the super user: " +adminUsername);
|
_log.info("Got the super user: " +adminUsername);
|
||||||
String theAdminToken = PortalContext.getConfiguration().getCurrentUserToken(infraContext, adminUsername);
|
String theAdminToken = PortalContext.getConfiguration().getCurrentUserToken(infraContext, adminUsername);
|
||||||
List<String> rolesString = new ArrayList<String>();
|
List<String> rolesString = new ArrayList<String>();
|
||||||
// List<GCubeRole> theAdminRoles = rm.listRolesByUserAndGroup(theAdmin.getUserId(), rootgroupId);
|
List<GCubeRole> theAdminRoles = rm.listRolesByUserAndGroup(theAdmin.getUserId(), rootgroupId);
|
||||||
// for (GCubeRole gCubeRole : theAdminRoles) {
|
for (GCubeRole gCubeRole : theAdminRoles) {
|
||||||
// rolesString.add(gCubeRole.getRoleName());
|
rolesString.add(gCubeRole.getRoleName());
|
||||||
// }
|
}
|
||||||
rolesString.add("Infrastructure-Manager");
|
rolesString.add(GatewayRolesNames.INFRASTRUCTURE_MANAGER.getRoleName());
|
||||||
_log.info("authorizationService().setTokenRoles(theAdminToken, rolesString);" +theAdminToken);
|
_log.info("authorizationService().setTokenRoles(theAdminToken, rolesString);" +theAdminToken);
|
||||||
authorizationService().setTokenRoles(theAdminToken, rolesString);
|
authorizationService().setTokenRoles(theAdminToken, rolesString);
|
||||||
SecurityTokenProvider.instance.set(theAdminToken);
|
SecurityTokenProvider.instance.set(theAdminToken);
|
||||||
|
@ -184,7 +181,7 @@ public class GCubeHookUserLocalService extends UserLocalServiceWrapper {
|
||||||
client.removeUserFromGroup(username2Add, getVREFolderNameFromContext(context));
|
client.removeUserFromGroup(username2Add, getVREFolderNameFromContext(context));
|
||||||
SecurityTokenProvider.instance.set(previousToken);
|
SecurityTokenProvider.instance.set(previousToken);
|
||||||
return true;
|
return true;
|
||||||
//}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String getVREFolderNameFromContext(String context) {
|
private static String getVREFolderNameFromContext(String context) {
|
||||||
|
|
|
@ -1,7 +0,0 @@
|
||||||
package org.gcube.portal.plugins.util;
|
|
||||||
|
|
||||||
public class HookConstants {
|
|
||||||
|
|
||||||
public static final String AUTORISED_INFRA_ROLE = "Infrastructure-Manager";
|
|
||||||
|
|
||||||
}
|
|
Loading…
Reference in New Issue