fixed bug infra manager role

pull/1/head
Massimiliano Assante 4 years ago
parent a5cac5b109
commit 780ad7c473

@ -66,25 +66,29 @@ public class MyCreateUserAccountListener extends BaseModelListener<User> {
_log.debug("Getting super user with role {}", Constants.AUTORISED_INFRA_ROLE);
//get the super user
String infraContext = "/"+PortalContext.getConfiguration().getInfrastructureName();
long groupId = gm.getGroupIdFromInfrastructureScope(infraContext);
long roleId = rm.getRoleId(Constants.AUTORISED_INFRA_ROLE, groupId);
List<GCubeUser> users = uMan.listUsersByGroupAndRole(groupId, roleId);
if (users.isEmpty()) {
_log.error("Cannot delete the user: there is no user having role " + Constants.AUTORISED_INFRA_ROLE + " on context: " + infraContext);
return;
}
else {
GCubeUser theAdmin = users.get(0);
String adminUsername = theAdmin.getUsername();
// 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<GCubeRole> theAdminRoles = rm.listRolesByUserAndGroup(theAdmin.getUserId(), groupId);
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(theAdminToken, rolesString);",theAdminToken);
Thread dropUserWorkspaceThread = new Thread(new RemovedUserAccountThread(username2Delete, theAdminToken, rolesString));
dropUserWorkspaceThread.start();
}
// }
_log.info("Trying to remove user from LDAP ...");
Thread removeFromLDAPThread = new Thread(new RemovedUserFromLDAPThread(username2Delete));

@ -41,29 +41,32 @@ public class WorkspaceCreateAccountThread implements Runnable {
try {
//get the super user
String infraContext = "/"+PortalContext.getConfiguration().getInfrastructureName();
long groupId = new LiferayGroupManager().getGroupIdFromInfrastructureScope(infraContext);
RoleManager rm = new LiferayRoleManager();
UserManager uMan = new LiferayUserManager();
long roleId = rm.getRoleId(AUTORISED_INFRA_ROLE, groupId);
List<GCubeUser> users = uMan.listUsersByGroupAndRole(groupId, roleId);
if (users.isEmpty()) {
_log.error("Cannot create this user account on storageHub 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(theAdminToken, rolesString);",theAdminToken);
authorizationService().setTokenRoles(theAdminToken, rolesString);
SecurityTokenProvider.instance.set(theAdminToken);
StorageHubClient shc = new StorageHubClient();
shc.createUserAccount(currentUsername);
SecurityTokenProvider.instance.set(previousToken);
}
// }
}
catch (Exception e) {
e.printStackTrace();

Loading…
Cancel
Save