added chagelog and reviewed code for Site and VRE Folder creation

master
Massimiliano Assante 3 years ago
parent 9c984fea4b
commit cb7759fc6f

@ -0,0 +1,17 @@
# Changelog for VRE Deploy Portlet
All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [v4.3.1-SNAPSHOT] - 2021-02-02
Ported to git
modified to support the new IAM Keycloak based
## [v1.0.0] - 2008-10-21
First release, for changes between 1.0 version and 4.2 see changelog xml in distro folder.

@ -0,0 +1,26 @@
# Acknowledgments
The projects leading to this software have received funding from a series of European Union programmes including:
- the Sixth Framework Programme for Research and Technological Development
- [DILIGENT](https://cordis.europa.eu/project/id/004260) (grant no. 004260).
- the Seventh Framework Programme for research, technological development and demonstration
- [D4Science](https://cordis.europa.eu/project/id/212488) (grant no. 212488);
- [D4Science-II](https://cordis.europa.eu/project/id/239019) (grant no.239019);
- [ENVRI](https://cordis.europa.eu/project/id/283465) (grant no. 283465);
- [iMarine](https://cordis.europa.eu/project/id/283644) (grant no. 283644);
- [EUBrazilOpenBio](https://cordis.europa.eu/project/id/288754) (grant no. 288754).
- the H2020 research and innovation programme
- [SoBigData](https://cordis.europa.eu/project/id/654024) (grant no. 654024);
- [PARTHENOS](https://cordis.europa.eu/project/id/654119) (grant no. 654119);
- [EGI-Engage](https://cordis.europa.eu/project/id/654142) (grant no. 654142);
- [ENVRI PLUS](https://cordis.europa.eu/project/id/654182) (grant no. 654182);
- [BlueBRIDGE](https://cordis.europa.eu/project/id/675680) (grant no. 675680);
- [PerformFISH](https://cordis.europa.eu/project/id/727610) (grant no. 727610);
- [AGINFRA PLUS](https://cordis.europa.eu/project/id/731001) (grant no. 731001);
- [DESIRA](https://cordis.europa.eu/project/id/818194) (grant no. 818194);
- [ARIADNEplus](https://cordis.europa.eu/project/id/823914) (grant no. 823914);
- [RISIS 2](https://cordis.europa.eu/project/id/824091) (grant no. 824091);
- [EOSC-Pillar](https://cordis.europa.eu/project/id/857650) (grant no. 857650);
- [Blue Cloud](https://cordis.europa.eu/project/id/862409) (grant no. 862409);
- [SoBigData-PlusPlus](https://cordis.europa.eu/project/id/871042) (grant no. 871042);

@ -13,7 +13,7 @@
<groupId>org.gcube.portlets.admin</groupId>
<artifactId>vre-deploy</artifactId>
<packaging>war</packaging>
<version>4.3.0</version>
<version>4.3.1-SNAPSHOT</version>
<name>gCube VRE Deploy Wizard Portlet</name>
<description>
gCube VRE Deploy Wizard Portlet.
@ -82,6 +82,12 @@
<artifactId>home-library</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.gcube.portal</groupId>
<artifactId>oidc-library-portal</artifactId>
<version>[1.0.0-SNAPSHOT, 2.0.0-SNAPSHOT)</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.gcube.portlets.user</groupId>
<artifactId>gcube-widgets</artifactId>

@ -54,6 +54,7 @@ import org.gcube.portal.custom.communitymanager.ThemesIdManager;
import org.gcube.portal.custom.communitymanager.components.GCUBESiteLayout;
import org.gcube.portal.custom.communitymanager.impl.GCubeSiteManagerImpl;
import org.gcube.portal.custom.scopemanager.scopehelper.ScopeHelper;
import org.gcube.portal.oidc.lr62.OIDCUmaUtil;
import org.gcube.portlets.admin.vredeployer.client.VredeployerService;
import org.gcube.portlets.admin.vredeployer.client.model.VREFunctionalityModel;
import org.gcube.portlets.admin.vredeployer.shared.ResourceCategory;
@ -79,7 +80,9 @@ 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.vomanagement.usermanagement.model.GatewayRolesNames;
import org.gcube.vremanagement.vremodel.cl.stubs.types.FunctionalityItem;
import org.gcube.vremanagement.vremodel.cl.stubs.types.GHN;
import org.gcube.vremanagement.vremodel.cl.stubs.types.GHNsPerFunctionality;
@ -359,11 +362,11 @@ public class VREDeployerServiceImpl extends RemoteServiceServlet implements Vre
}
for (String func : funCategories.keySet()) {
System.out.println("-"+func);
log.debug("-"+func);
for(ResourceCategory category : funCategories.get(func)) {
System.out.println("--"+category.getName());
log.debug("--"+category.getName());
for(ResourceCategoryItem rc: category.getItems()) {
System.out.println("----"+rc.getName() + " : " + rc.isSelected());
log.debug("----"+rc.getName() + " : " + rc.isSelected());
}
}
}
@ -394,7 +397,7 @@ public class VREDeployerServiceImpl extends RemoteServiceServlet implements Vre
List<RunningInstanceMessage> services = toWorkWith.foundServices();
if (services != null) {
for (RunningInstanceMessage se : services) {
System.out.println(se.serviceName() + " - " + se.serviceClass());
log.debug(se.serviceName() + " - " + se.serviceClass());
}
}
@ -553,7 +556,7 @@ public class VREDeployerServiceImpl extends RemoteServiceServlet implements Vre
log.info("ADDING user designer and manager, found designer: " + designer + " found manager: "+manager);
long vreCreatedId = createCommunityAndLayoutAndHLFolder(vreName, description);
long vreCreatedId = createCommunityAndLayoutAndVREFolder(vreName, description, designer, manager);
log.info("--- createCommunityAndLayout COMPLETED, vreCreatedId="+vreCreatedId);
String vreScope = "";
@ -696,29 +699,30 @@ public class VREDeployerServiceImpl extends RemoteServiceServlet implements Vre
GroupManager gm = new LiferayGroupManager();
String previousToken = SecurityTokenProvider.instance.get();
//get the super user
log.info("Getting super user with role {}", GatewayRolesNames.INFRASTRUCTURE_MANAGER.getRoleName());
//get the super user
String infraContext = "/"+PortalContext.getConfiguration().getInfrastructureName();
// 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);
long rootgroupId = gm.getGroupIdFromInfrastructureScope(infraContext);
User theAdmin = LiferayUserManager.getRandomUserWithRole(rootgroupId, GatewayRolesNames.INFRASTRUCTURE_MANAGER);
if (theAdmin == null) {
log.error("Cannot create VRE Folder for this new VRE, There is no user having role {} on context: " + GatewayRolesNames.INFRASTRUCTURE_MANAGER.getRoleName());
}
String adminUsername = theAdmin.getScreenName();
log.info("Got the super user: {}",adminUsername);
String theAdminToken = PortalContext.getConfiguration().getCurrentUserToken(infraContext, adminUsername);
List<String> rolesString = new ArrayList<String>();
// 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");
List<GCubeRole> theAdminRoles = new LiferayRoleManager().listRolesByUserAndGroup(theAdmin.getUserId(), rootgroupId);
for (GCubeRole gCubeRole : theAdminRoles) {
rolesString.add(gCubeRole.getRoleName());
}
rolesString.add(GatewayRolesNames.INFRASTRUCTURE_MANAGER.getRoleName());
log.info("legacy authorizationService().setTokenRoles done");
authorizationService().setTokenRoles(theAdminToken, rolesString);
SecurityTokenProvider.instance.set(theAdminToken);
OIDCUmaUtil.provideConfiguredPortalClientUMATokenInThreadLocal("/" + PortalContext.getConfiguration().getInfrastructureName());
System.out.println("\n\n***** new authorizationService PortalClient UMA-Token In ThreadLocal done **** ");
String newVreContext = gm.getInfrastructureScope(vreCreated.getGroupId());
StorageHubClient shc = new StorageHubClient();
String vreFolderName = Util.getVREGroupFromContext(newVreContext);
@ -791,11 +795,7 @@ public class VREDeployerServiceImpl extends RemoteServiceServlet implements Vre
//*** Overall deploy status report part
toReturn.setGlobalStatus(convStatus(toConvert.getStatus()));
//*** Cloud deploy report part
GHNonCloudReport cDeploy = toConvert.getCloudDeployingReport();
System.out.println("***** GHNonCloudReport Not Selected ******");
log.trace("***** GHNonCloudReport Not Selected ******");
ClientCloudReport cdp = new ClientCloudReport();
cdp.setStatus(DeployStatus.SKIP);
toReturn.setCloudReport(cdp);
@ -880,7 +880,7 @@ public class VREDeployerServiceImpl extends RemoteServiceServlet implements Vre
/**
* Creates the community and its layout in Liferay
*/
private long createCommunityAndLayoutAndHLFolder(String vreName, String description) {
private long createCommunityAndLayoutAndVREFolder(String vreName, String description, String designer, String manager) {
if (vreExists(vreName)) {
log.warn("VRE Exists already");
@ -901,11 +901,8 @@ public class VREDeployerServiceImpl extends RemoteServiceServlet implements Vre
String desc = (session.getAttribute(DESCRIPTION) == null) ? "No Description found": session.getAttribute(DESCRIPTION).toString(); //desc
String designer = (String) session.getAttribute(DESIGNER);
log.info("Designer found Name : " + designer);
String manager = (String) session.getAttribute(MANAGER);
log.info("Manager found Name : " + manager);
log.info("Designer assigned: " + designer);
log.info("Manager assigned : " + manager);
try {
@ -919,8 +916,8 @@ public class VREDeployerServiceImpl extends RemoteServiceServlet implements Vre
long groupId = vreCreated.getGroupId();
Group lrGroup = GroupLocalServiceUtil.getGroup(groupId);
GCubeUser userBean = new LiferayUserManager().getUserByUsername(session.getUsername());
User lrUser = UserLocalServiceUtil.getUser(userBean.getUserId());
GCubeUser currentVREManagerUserBean = new LiferayUserManager().getUserByUsername(session.getUsername());
User lrUser = UserLocalServiceUtil.getUser(currentVREManagerUserBean.getUserId());
SiteManagerUtil.createLayout(lrGroup, lrUser, siteLayout);
@ -931,17 +928,17 @@ public class VREDeployerServiceImpl extends RemoteServiceServlet implements Vre
log.info("Assigned theme with id: " + themid + " to groupid: " + groupId);
//the method above create a VRE and assign the manager Role to the person that triggers the creation
//the method above creates a VRE and assign the manager Role to the person that triggers the creation
//however the VRE-Designer and the VRE-Manager persons of the VRE could be different and need to be created too
UserManager uman = new LiferayUserManager();
//if the manager is not the one who triggered the creation
String currUser = session.getUsername();
String currUser = currentVREManagerUserBean.getUsername();
log.info("***Username of who triggered the creation is: " + currUser);
log.info("Trying to create VRE Group Folder through Storage Hub ...");
createVRESharedGroupFolder(uman, vreCreated, designer, manager, description);
log.info("--- createVRESharedGroupFolder OK, sending Message to designer.");
log.info("--- createVRESharedGroupFolder OK, now assigning the designer and manager to the Site (VRE)");
RoleManager rm = new LiferayRoleManager();
@ -949,23 +946,24 @@ public class VREDeployerServiceImpl extends RemoteServiceServlet implements Vre
//add the role VRE-Manager
long userId = uman.getUserId(manager);
uman.assignUserToGroup(groupId, userId);
log.info("Added manager " + manager + " to group " + vreName + " with Success");
log.info("\n\n*** Added selected VRE-Manager " + manager + " to group " + vreName + " with Success");
log.info("Assigning Role: VRE-Manager");
log.info("\n\n*** Now trying assigning Site Role VRE-Manager to " + manager);
long roleId = rm.getRoleIdByName(VRE_MANAGER);
rm.assignRoleToUser(userId, groupId, roleId);
log.info("Admin Role VRE-Manager Associated to user " + manager + " .... returning ...");
log.info("Site Role VRE-Manager associated to user " + manager + " with Success");
}
//if the designer is different
if (designer.compareTo(manager) != 0) {
log.info("\n\n*** the VRE-Designer is not equal to the VRE-Manager, need to add " + designer + " to this Site (VRE)");
//add the role VRE-Designer
long userId = uman.getUserId(designer);
uman.assignUserToGroup(groupId, userId);
log.info("Added designer " + designer + " to group " + vreName + " with Success");
log.info("\n\n*** Now trying assigning Site Role VRE-Designer to " + designer);
long roleId = rm.getRoleIdByName(VRE_DESIGNER);
rm.assignRoleToUser(userId, groupId, roleId);
log.info("Admin Role VRE-Designer Associated to user " + designer + " .... returning ...");
log.info("Site Role VRE-Designer associated to user " + designer + " .... returning ...");
}
return groupId;

Loading…
Cancel
Save