fixed bug infra manager role
This commit is contained in:
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);
|
_log.debug("Getting super user with role {}", Constants.AUTORISED_INFRA_ROLE);
|
||||||
//get the super user
|
//get the super user
|
||||||
String infraContext = "/"+PortalContext.getConfiguration().getInfrastructureName();
|
String infraContext = "/"+PortalContext.getConfiguration().getInfrastructureName();
|
||||||
long groupId = gm.getGroupIdFromInfrastructureScope(infraContext);
|
// long rootgroupId = gm.getGroupIdFromInfrastructureScope(infraContext);
|
||||||
long roleId = rm.getRoleId(Constants.AUTORISED_INFRA_ROLE, groupId);
|
// RoleManager rm = new LiferayRoleManager();
|
||||||
List<GCubeUser> users = uMan.listUsersByGroupAndRole(groupId, roleId);
|
// long roleId = rm.getRoleId(HookConstants.AUTORISED_INFRA_ROLE, rootgroupId);
|
||||||
if (users.isEmpty()) {
|
// List<GCubeUser> users = uMan.listUsersByGroupAndRole(rootgroupId, roleId);
|
||||||
_log.error("Cannot delete the user: there is no user having role " + Constants.AUTORISED_INFRA_ROLE + " on context: " + infraContext);
|
// if (users.isEmpty()) {
|
||||||
return;
|
// _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);
|
// else {
|
||||||
String adminUsername = theAdmin.getUsername();
|
//GCubeUser theAdmin = users.get(0);
|
||||||
|
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<GCubeRole> theAdminRoles = rm.listRolesByUserAndGroup(theAdmin.getUserId(), groupId);
|
|
||||||
List<String> rolesString = new ArrayList<String>();
|
List<String> rolesString = new ArrayList<String>();
|
||||||
for (GCubeRole gCubeRole : theAdminRoles) {
|
// List<GCubeRole> theAdminRoles = rm.listRolesByUserAndGroup(theAdmin.getUserId(), rootgroupId);
|
||||||
rolesString.add(gCubeRole.getRoleName());
|
// 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));
|
Thread dropUserWorkspaceThread = new Thread(new RemovedUserAccountThread(username2Delete, theAdminToken, rolesString));
|
||||||
dropUserWorkspaceThread.start();
|
dropUserWorkspaceThread.start();
|
||||||
}
|
// }
|
||||||
|
|
||||||
_log.info("Trying to remove user from LDAP ...");
|
_log.info("Trying to remove user from LDAP ...");
|
||||||
Thread removeFromLDAPThread = new Thread(new RemovedUserFromLDAPThread(username2Delete));
|
Thread removeFromLDAPThread = new Thread(new RemovedUserFromLDAPThread(username2Delete));
|
||||||
|
|
|
@ -41,29 +41,32 @@ public class WorkspaceCreateAccountThread implements Runnable {
|
||||||
try {
|
try {
|
||||||
//get the super user
|
//get the super user
|
||||||
String infraContext = "/"+PortalContext.getConfiguration().getInfrastructureName();
|
String infraContext = "/"+PortalContext.getConfiguration().getInfrastructureName();
|
||||||
long groupId = new LiferayGroupManager().getGroupIdFromInfrastructureScope(infraContext);
|
// long rootgroupId = gm.getGroupIdFromInfrastructureScope(infraContext);
|
||||||
RoleManager rm = new LiferayRoleManager();
|
// RoleManager rm = new LiferayRoleManager();
|
||||||
UserManager uMan = new LiferayUserManager();
|
// long roleId = rm.getRoleId(HookConstants.AUTORISED_INFRA_ROLE, rootgroupId);
|
||||||
long roleId = rm.getRoleId(AUTORISED_INFRA_ROLE, groupId);
|
// List<GCubeUser> users = uMan.listUsersByGroupAndRole(rootgroupId, roleId);
|
||||||
List<GCubeUser> users = uMan.listUsersByGroupAndRole(groupId, roleId);
|
// if (users.isEmpty()) {
|
||||||
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);
|
||||||
_log.error("Cannot create this user account on storageHub there is no user having role {} on context {}", AUTORISED_INFRA_ROLE , infraContext);
|
// return false;
|
||||||
return;
|
// }
|
||||||
}
|
// else {
|
||||||
else {
|
//GCubeUser theAdmin = users.get(0);
|
||||||
GCubeUser theAdmin = users.get(0);
|
String adminUsername = "lucio.lelii";
|
||||||
String theAdminToken = PortalContext.getConfiguration().getCurrentUserToken(infraContext, theAdmin.getUsername());
|
_log.info("Got the super user: {}",adminUsername);
|
||||||
List<GCubeRole> theAdminRoles = rm.listRolesByUserAndGroup(theAdmin.getUserId(), groupId);
|
String theAdminToken = PortalContext.getConfiguration().getCurrentUserToken(infraContext, adminUsername);
|
||||||
List<String> rolesString = new ArrayList<String>();
|
List<String> rolesString = new ArrayList<String>();
|
||||||
for (GCubeRole gCubeRole : theAdminRoles) {
|
// List<GCubeRole> theAdminRoles = rm.listRolesByUserAndGroup(theAdmin.getUserId(), rootgroupId);
|
||||||
rolesString.add(gCubeRole.getRoleName());
|
// for (GCubeRole gCubeRole : theAdminRoles) {
|
||||||
}
|
// rolesString.add(gCubeRole.getRoleName());
|
||||||
|
// }
|
||||||
|
rolesString.add("Infrastructure-Manager");
|
||||||
|
_log.info("authorizationService().setTokenRoles(theAdminToken, rolesString);",theAdminToken);
|
||||||
authorizationService().setTokenRoles(theAdminToken, rolesString);
|
authorizationService().setTokenRoles(theAdminToken, rolesString);
|
||||||
SecurityTokenProvider.instance.set(theAdminToken);
|
SecurityTokenProvider.instance.set(theAdminToken);
|
||||||
StorageHubClient shc = new StorageHubClient();
|
StorageHubClient shc = new StorageHubClient();
|
||||||
shc.createUserAccount(currentUsername);
|
shc.createUserAccount(currentUsername);
|
||||||
SecurityTokenProvider.instance.set(previousToken);
|
SecurityTokenProvider.instance.set(previousToken);
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
catch (Exception e) {
|
catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
|
Loading…
Reference in New Issue