fixed the retrieval of authorised users for JCR

This commit is contained in:
Massimiliano Assante 2020-01-31 09:12:38 +01:00
parent a583933be6
commit 9c984fea4b
1 changed files with 20 additions and 17 deletions

View File

@ -79,7 +79,6 @@ import org.gcube.vomanagement.usermanagement.exception.UserManagementSystemExcep
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.model.GCubeRole;
import org.gcube.vomanagement.usermanagement.model.GCubeUser;
import org.gcube.vremanagement.vremodel.cl.stubs.types.FunctionalityItem;
import org.gcube.vremanagement.vremodel.cl.stubs.types.GHN;
@ -698,22 +697,26 @@ public class VREDeployerServiceImpl extends RemoteServiceServlet implements Vre
String previousToken = SecurityTokenProvider.instance.get();
//get the super user
String infraContext = "/"+PortalContext.getConfiguration().getInfrastructureName();
long groupId = gm.getGroupIdFromInfrastructureScope(infraContext);
RoleManager rm = new LiferayRoleManager();
long roleId = rm.getRoleId(AUTORISED_INFRA_ROLE, groupId);
List<GCubeUser> users = uMan.listUsersByGroupAndRole(groupId, roleId);
if (users.isEmpty()) {
log.error("Cannot create the VRE Folder: there is no user having role {} on context {}", AUTORISED_INFRA_ROLE , infraContext);
return;
}
else {
GCubeUser theAdmin = users.get(0);
String theAdminToken = PortalContext.getConfiguration().getCurrentUserToken(infraContext, theAdmin.getUsername());
List<GCubeRole> theAdminRoles = rm.listRolesByUserAndGroup(theAdmin.getUserId(), groupId);
// long rootgroupId = gm.getGroupIdFromInfrastructureScope(infraContext);
// RoleManager rm = new LiferayRoleManager();
// long roleId = rm.getRoleId(HookConstants.AUTORISED_INFRA_ROLE, rootgroupId);
// List<GCubeUser> users = uMan.listUsersByGroupAndRole(rootgroupId, roleId);
// if (users.isEmpty()) {
// _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 {
//GCubeUser theAdmin = users.get(0);
String adminUsername = "lucio.lelii";
log.info("Got the super user: " +adminUsername);
String theAdminToken = PortalContext.getConfiguration().getCurrentUserToken(infraContext, adminUsername);
List<String> rolesString = new ArrayList<String>();
for (GCubeRole gCubeRole : theAdminRoles) {
rolesString.add(gCubeRole.getRoleName());
}
// List<GCubeRole> theAdminRoles = rm.listRolesByUserAndGroup(theAdmin.getUserId(), rootgroupId);
// for (GCubeRole gCubeRole : theAdminRoles) {
// rolesString.add(gCubeRole.getRoleName());
// }
rolesString.add("Infrastructure-Manager");
log.info("authorizationService().setTokenRoles done");
authorizationService().setTokenRoles(theAdminToken, rolesString);
SecurityTokenProvider.instance.set(theAdminToken);
String newVreContext = gm.getInfrastructureScope(vreCreated.getGroupId());
@ -730,7 +733,7 @@ public class VREDeployerServiceImpl extends RemoteServiceServlet implements Vre
log.info("Created the VRE Folder on storageHub: {} ", vreFolderName);
SecurityTokenProvider.instance.set(previousToken);
}
//}
}
/**
*