patch for getting infra manager role
This commit is contained in:
parent
027a53e026
commit
978bde8610
|
@ -97,29 +97,36 @@ public class GCubeHookSiteRoleLocalService extends UserGroupRoleLocalServiceWrap
|
||||||
String context = gm.getInfrastructureScope(groupId);
|
String context = gm.getInfrastructureScope(groupId);
|
||||||
ScopeProvider.instance.set(context);
|
ScopeProvider.instance.set(context);
|
||||||
String vreFolderTitle = Util.getVREGroupFromContext(context);
|
String vreFolderTitle = Util.getVREGroupFromContext(context);
|
||||||
_log.debug("The vreFolderTitle on which the VREFolder role is being {} is {}", enable, vreFolderTitle);
|
_log.info("The vreFolderTitle on which the VREFolder role is being {} is {}", enable, vreFolderTitle);
|
||||||
|
_log.info("Before StorageHubClient shc = new StorageHubClient();");
|
||||||
StorageHubClient shc = new StorageHubClient();
|
StorageHubClient shc = new StorageHubClient();
|
||||||
|
_log.info("Before shc.getVreFolderManager(vreFolderTitle);");
|
||||||
VREFolderManager vreFolderManager = shc.getVreFolderManager(vreFolderTitle);
|
VREFolderManager vreFolderManager = shc.getVreFolderManager(vreFolderTitle);
|
||||||
|
|
||||||
String previousToken = SecurityTokenProvider.instance.get();
|
String previousToken = SecurityTokenProvider.instance.get();
|
||||||
//get the super user
|
//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();
|
// RoleManager rm = new LiferayRoleManager();
|
||||||
long roleId = rm.getRoleId(HookConstants.AUTORISED_INFRA_ROLE, rootgroupId);
|
// long roleId = rm.getRoleId(HookConstants.AUTORISED_INFRA_ROLE, rootgroupId);
|
||||||
List<GCubeUser> users = uMan.listUsersByGroupAndRole(rootgroupId, roleId);
|
// List<GCubeUser> users = uMan.listUsersByGroupAndRole(rootgroupId, 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 add the user as VRE Folder admin: there is no user having role {} on context: {}", HookConstants.AUTORISED_INFRA_ROLE, infraContext);
|
||||||
return false;
|
// return false;
|
||||||
}
|
// }
|
||||||
else {
|
// else {
|
||||||
GCubeUser theAdmin = users.get(0);
|
//GCubeUser theAdmin = users.get(0);
|
||||||
String theAdminToken = PortalContext.getConfiguration().getCurrentUserToken(infraContext, theAdmin.getUsername());
|
String adminUsername = "lucio.lelii";
|
||||||
List<GCubeRole> theAdminRoles = rm.listRolesByUserAndGroup(theAdmin.getUserId(), rootgroupId);
|
_log.info("Got the super user: {}",adminUsername);
|
||||||
|
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);
|
||||||
|
|
||||||
|
@ -131,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;
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -155,22 +155,26 @@ 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 groupId = gm.getGroupIdFromInfrastructureScope(infraContext);
|
// long rootgroupId = gm.getGroupIdFromInfrastructureScope(infraContext);
|
||||||
RoleManager rm = new LiferayRoleManager();
|
// RoleManager rm = new LiferayRoleManager();
|
||||||
long roleId = rm.getRoleId(HookConstants.AUTORISED_INFRA_ROLE, groupId);
|
// long roleId = rm.getRoleId(HookConstants.AUTORISED_INFRA_ROLE, rootgroupId);
|
||||||
List<GCubeUser> users = uMan.listUsersByGroupAndRole(groupId, roleId);
|
// List<GCubeUser> users = uMan.listUsersByGroupAndRole(rootgroupId, roleId);
|
||||||
if (users.isEmpty()) {
|
// if (users.isEmpty()) {
|
||||||
_log.error("Cannot add the user to the VRE Folder: there is no user having role " + HookConstants.AUTORISED_INFRA_ROLE + " on context: " + infraContext);
|
// _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;
|
// return false;
|
||||||
}
|
// }
|
||||||
else {
|
// else {
|
||||||
GCubeUser theAdmin = users.get(0);
|
//GCubeUser theAdmin = users.get(0);
|
||||||
String theAdminToken = PortalContext.getConfiguration().getCurrentUserToken(infraContext, theAdmin.getUsername());
|
String adminUsername = "lucio.lelii";
|
||||||
List<GCubeRole> theAdminRoles = rm.listRolesByUserAndGroup(theAdmin.getUserId(), groupId);
|
_log.info("Got the super user: " +adminUsername);
|
||||||
|
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);
|
||||||
GroupManagerClient client = AbstractPlugin.groups().build();
|
GroupManagerClient client = AbstractPlugin.groups().build();
|
||||||
|
@ -180,7 +184,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) {
|
||||||
|
|
Loading…
Reference in New Issue