From 780ad7c47300b450eff5dc3fbd93e51769e13dc7 Mon Sep 17 00:00:00 2001 From: Massimiliano Assante Date: Thu, 30 Jan 2020 19:21:12 +0100 Subject: [PATCH] fixed bug infra manager role --- .../MyCreateUserAccountListener.java | 34 +++++++++-------- .../WorkspaceCreateAccountThread.java | 37 ++++++++++--------- 2 files changed, 39 insertions(+), 32 deletions(-) diff --git a/src/main/java/org/gcube/portal/usersaccount/MyCreateUserAccountListener.java b/src/main/java/org/gcube/portal/usersaccount/MyCreateUserAccountListener.java index cf5b539..ba92074 100644 --- a/src/main/java/org/gcube/portal/usersaccount/MyCreateUserAccountListener.java +++ b/src/main/java/org/gcube/portal/usersaccount/MyCreateUserAccountListener.java @@ -66,25 +66,29 @@ public class MyCreateUserAccountListener extends BaseModelListener { _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 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 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 theAdminRoles = rm.listRolesByUserAndGroup(theAdmin.getUserId(), groupId); List rolesString = new ArrayList(); - for (GCubeRole gCubeRole : theAdminRoles) { - rolesString.add(gCubeRole.getRoleName()); - } +// List 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)); diff --git a/src/main/java/org/gcube/portal/usersaccount/WorkspaceCreateAccountThread.java b/src/main/java/org/gcube/portal/usersaccount/WorkspaceCreateAccountThread.java index a3ae555..3689511 100644 --- a/src/main/java/org/gcube/portal/usersaccount/WorkspaceCreateAccountThread.java +++ b/src/main/java/org/gcube/portal/usersaccount/WorkspaceCreateAccountThread.java @@ -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 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 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 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 rolesString = new ArrayList(); - for (GCubeRole gCubeRole : theAdminRoles) { - rolesString.add(gCubeRole.getRoleName()); - } +// List 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();