diff --git a/CHANGELOG.md b/CHANGELOG.md index c510991..c8dbf1b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,11 +5,11 @@ 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). -## [v6.7.0] - 2020-11-17 +## [v6.7.1] - 2020-11-17 Ported to git -Removed Home Library dependency, integrated support to send events to the Orchestrator service and Keycloak +Removed trigger that updates LDAP group upon users add/remove to VREs ## [v6.6.0] - 2018-03-02 diff --git a/pom.xml b/pom.xml index b64aa85..cd36212 100644 --- a/pom.xml +++ b/pom.xml @@ -12,7 +12,7 @@ org.gcube.portal.plugins VREFolder-hook VREFolder-hook Hook - 6.7.0 + 6.7.1-SNAPSHOT war VREFolder-hook handles the user adding/removal from the related Home Library VRE Folder @@ -22,7 +22,7 @@ scm:git:https://code-repo.d4science.org/gCubeSystem/${project.artifactId}.git https://code-repo.d4science.org/gCubeSystem/${project.artifactId} - + 6.2.5 6.2.10.12 /Users/massi/portal/liferay-portal-6.2-ce-ga6/deploy @@ -44,7 +44,18 @@ org.gcube.common - storagehub-client-library + home-library + provided + + + org.gcube.common + home-library-model + provided + + + org.gcube.common + home-library-jcr + provided org.gcube.core diff --git a/src/main/java/org/gcube/portal/plugins/GCubeHookSiteRoleLocalService.java b/src/main/java/org/gcube/portal/plugins/GCubeHookSiteRoleLocalService.java index 1b25782..e501ead 100644 --- a/src/main/java/org/gcube/portal/plugins/GCubeHookSiteRoleLocalService.java +++ b/src/main/java/org/gcube/portal/plugins/GCubeHookSiteRoleLocalService.java @@ -1,58 +1,37 @@ package org.gcube.portal.plugins; -import static org.gcube.common.authorization.client.Constants.authorizationService; - -import java.util.ArrayList; import java.util.List; -import org.gcube.common.authorization.library.provider.SecurityTokenProvider; -import org.gcube.common.authorization.library.provider.UmaJWTProvider; +import org.gcube.common.homelibrary.home.HomeLibrary; +import org.gcube.common.homelibrary.home.workspace.usermanager.UserManager; import org.gcube.common.portal.PortalContext; import org.gcube.common.scope.api.ScopeProvider; -import org.gcube.common.storagehub.client.dsl.StorageHubClient; -import org.gcube.common.storagehub.client.dsl.Util; -import org.gcube.common.storagehub.client.dsl.VREFolderManager; -import org.gcube.portal.oidc.lr62.OIDCUmaUtil; import org.gcube.vomanagement.usermanagement.GroupManager; -import org.gcube.vomanagement.usermanagement.RoleManager; 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.GatewayRolesNames; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import com.liferay.portal.model.Role; -import com.liferay.portal.model.User; import com.liferay.portal.model.UserGroupRole; import com.liferay.portal.service.RoleLocalServiceUtil; import com.liferay.portal.service.UserGroupRoleLocalService; import com.liferay.portal.service.UserGroupRoleLocalServiceWrapper; +import com.liferay.portal.service.UserLocalServiceUtil; public class GCubeHookSiteRoleLocalService extends UserGroupRoleLocalServiceWrapper { - /** - * logger - */ - private static final Logger _log = LoggerFactory.getLogger(GCubeHookSiteRoleLocalService.class); - private GroupManager gm; - private LiferayUserManager uMan; - - public GCubeHookSiteRoleLocalService(UserGroupRoleLocalService userGroupRoleLocalService) { - super(userGroupRoleLocalService); - gm = new LiferayGroupManager(); - uMan = new LiferayUserManager(); - System.out.println("GCubeHookSiteRoleLocalService hook is UP & Listening ..."); - } - - //TODO: as soon as Feature https://support.d4science.org/issues/17726 is delivered take care of this also - @Override - public java.util.List addUserGroupRoles(long[] userIds, long groupId, - long roleId) throws com.liferay.portal.kernel.exception.SystemException { - List toReturn = super.addUserGroupRoles(userIds, groupId, roleId); - return toReturn; - } + /** + * logger + */ + private static final Logger _log = LoggerFactory.getLogger(GCubeHookSiteRoleLocalService.class); + private GroupManager gm; + public GCubeHookSiteRoleLocalService(UserGroupRoleLocalService userGroupRoleLocalService) { + super(userGroupRoleLocalService); + gm = new LiferayGroupManager(); + System.out.println("GCubeHookSiteRoleLocalService hook is UP & Listening ..."); + } + @Override public java.util.List addUserGroupRoles( long userId, long groupId, long[] roleIds) throws com.liferay.portal.kernel.exception.SystemException { @@ -81,61 +60,22 @@ public class GCubeHookSiteRoleLocalService extends UserGroupRoleLocalServiceWrap return toReturn; } + private void setVREFolderAdministrator(long userId, long groupId, boolean enable) throws Exception { - private boolean setVREFolderAdministrator(long userId, long groupId, boolean enable) throws Exception { - String context = gm.getInfrastructureScope(groupId); - ScopeProvider.instance.set(context); - String vreFolderTitle = Util.getVREGroupFromContext(context); - _log.info("The vreFolderTitle on which the VREFolder role is being {} is {}", enable, vreFolderTitle); - _log.debug("Before StorageHubClient shc = new StorageHubClient();"); - StorageHubClient shc = new StorageHubClient(); - _log.debug("Before shc.getVreFolderManager(vreFolderTitle);"); - VREFolderManager vreFolderManager = shc.getVreFolderManager(vreFolderTitle); + String scopeVREFolder = gm.getInfrastructureScope(groupId); - String previousToken = SecurityTokenProvider.instance.get(); + String currScope = ScopeProvider.instance.get(); + String scopeToset = "/"+PortalContext.getConfiguration().getInfrastructureName(); + ScopeProvider.instance.set(scopeToset); - //get the super user - _log.debug("//get the super user"); - - String infraContext = "/" + PortalContext.getConfiguration().getInfrastructureName(); - long rootgroupId = gm.getGroupIdFromInfrastructureScope(infraContext); - User theAdmin = LiferayUserManager.getRandomUserWithRole(rootgroupId, GatewayRolesNames.INFRASTRUCTURE_MANAGER); - if (theAdmin == null) { - _log.warn("Cannot add the user as VRE Folder admin: there is no user having role " - + GatewayRolesNames.INFRASTRUCTURE_MANAGER); - return false; - } else { - RoleManager rm = new LiferayRoleManager(); - String adminUsername = theAdmin.getScreenName(); - _log.info("Got the super user: " + adminUsername); - String theAdminToken = PortalContext.getConfiguration().getCurrentUserToken(infraContext, adminUsername); - List rolesString = new ArrayList(); - List theAdminRoles = rm.listRolesByUserAndGroup(theAdmin.getUserId(), rootgroupId); - for (GCubeRole gCubeRole : theAdminRoles) { - rolesString.add(gCubeRole.getRoleName()); - } - rolesString.add(GatewayRolesNames.INFRASTRUCTURE_MANAGER.getRoleName()); - _log.info("authorizationService().setTokenRoles(theAdminToken, rolesString);" + theAdminToken); - authorizationService().setTokenRoles(theAdminToken, rolesString); - SecurityTokenProvider.instance.set(theAdminToken); - - String previousUmaToken = UmaJWTProvider.instance.get(); - OIDCUmaUtil.provideConfiguredPortalClientUMATokenInThreadLocal(infraContext); - - String theUserToPromoteOrDeclass = uMan.getUserById(userId).getUsername(); - _log.info("The {} is being promoted? {} ", theUserToPromoteOrDeclass, enable); - if (enable) - vreFolderManager.setAdmin(theUserToPromoteOrDeclass); - else - vreFolderManager.removeAdmin(theUserToPromoteOrDeclass); - SecurityTokenProvider.instance.set(previousToken); - - if (previousUmaToken != null) { - UmaJWTProvider.instance.set(previousUmaToken); - } - - return true; - } - } + String username = UserLocalServiceUtil.getUser(userId).getScreenName(); + _log.debug("User " + username + " is going to be VRE Folder Admin?" + enable); + UserManager hlUm = HomeLibrary.getHomeManagerFactory().getUserManager(); + if (enable) + hlUm.setAdministrator(scopeVREFolder, username); + else + hlUm.removeAdministrator(scopeVREFolder, username); + ScopeProvider.instance.set(currScope); + } } diff --git a/src/main/java/org/gcube/portal/plugins/GCubeHookUserLocalService.java b/src/main/java/org/gcube/portal/plugins/GCubeHookUserLocalService.java index 137f9e0..686f3ce 100644 --- a/src/main/java/org/gcube/portal/plugins/GCubeHookUserLocalService.java +++ b/src/main/java/org/gcube/portal/plugins/GCubeHookUserLocalService.java @@ -1,27 +1,14 @@ package org.gcube.portal.plugins; -import static org.gcube.common.authorization.client.Constants.authorizationService; - -import java.util.ArrayList; -import java.util.List; - -import org.gcube.common.authorization.library.provider.SecurityTokenProvider; -import org.gcube.common.authorization.library.provider.UmaJWTProvider; +import org.gcube.common.homelibrary.home.HomeLibrary; import org.gcube.common.portal.PortalContext; import org.gcube.common.scope.api.ScopeProvider; -import org.gcube.common.storagehub.client.plugins.AbstractPlugin; -import org.gcube.common.storagehub.client.proxies.GroupManagerClient; -import org.gcube.portal.oidc.lr62.OIDCUmaUtil; import org.gcube.portal.plugins.thread.CheckShareLatexUserThread; import org.gcube.portal.plugins.thread.RemoveUserTokenFromVREThread; + import org.gcube.vomanagement.usermanagement.GroupManager; -import org.gcube.vomanagement.usermanagement.RoleManager; -import org.gcube.vomanagement.usermanagement.UserManager; 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.GatewayRolesNames; import com.liferay.portal.kernel.exception.SystemException; import com.liferay.portal.kernel.log.Log; @@ -35,7 +22,6 @@ import com.liferay.portal.service.UserLocalServiceWrapper; * */ public class GCubeHookUserLocalService extends UserLocalServiceWrapper { - /** * logger */ @@ -137,7 +123,8 @@ public class GCubeHookUserLocalService extends UserLocalServiceWrapper { //add the user to shareLatex Thread t = new Thread(new CheckShareLatexUserThread(username, scope)); t.start(); - setUser2VREFolder(gm, um, username, scope, true); + org.gcube.common.homelibrary.home.workspace.usermanager.UserManager hlUm = HomeLibrary.getHomeManagerFactory().getUserManager(); + hlUm.associateUserToGroup(scope, username); } else { _log.debug("Group is not a VRE, SKIP adding"); } @@ -147,56 +134,6 @@ public class GCubeHookUserLocalService extends UserLocalServiceWrapper { } ScopeProvider.instance.set(currScope); } - - private boolean setUser2VREFolder(GroupManager gm, UserManager uMan, String username2Add, String context, boolean add) throws Exception { - String previousToken = SecurityTokenProvider.instance.get(); - //get the super user - String infraContext = "/"+PortalContext.getConfiguration().getInfrastructureName(); - long rootgroupId = gm.getGroupIdFromInfrastructureScope(infraContext); - User theAdmin = LiferayUserManager.getRandomUserWithRole(rootgroupId, GatewayRolesNames.INFRASTRUCTURE_MANAGER); - if (theAdmin == null) { - _log.warn("Cannot add the user as VRE Folder admin: there is no user having role " + GatewayRolesNames.INFRASTRUCTURE_MANAGER); - return false; - } - else { - RoleManager rm = new LiferayRoleManager(); - String adminUsername = theAdmin.getScreenName(); - _log.info("Got the super user: " +adminUsername); - String theAdminToken = PortalContext.getConfiguration().getCurrentUserToken(infraContext, adminUsername); - List rolesString = new ArrayList(); - List theAdminRoles = rm.listRolesByUserAndGroup(theAdmin.getUserId(), rootgroupId); - for (GCubeRole gCubeRole : theAdminRoles) { - rolesString.add(gCubeRole.getRoleName()); - } - rolesString.add(GatewayRolesNames.INFRASTRUCTURE_MANAGER.getRoleName()); - _log.info("authorizationService().setTokenRoles(theAdminToken, rolesString);" +theAdminToken); - authorizationService().setTokenRoles(theAdminToken, rolesString); - SecurityTokenProvider.instance.set(theAdminToken); - - String previousUmaToken = UmaJWTProvider.instance.get(); - OIDCUmaUtil.provideConfiguredPortalClientUMATokenInThreadLocal(infraContext); - GroupManagerClient client = AbstractPlugin.groups().build(); - if (add) - client.addUserToGroup(username2Add, getVREFolderNameFromContext(context)); - else - client.removeUserFromGroup(username2Add, getVREFolderNameFromContext(context)); - SecurityTokenProvider.instance.set(previousToken); - - if (previousUmaToken != null) { - UmaJWTProvider.instance.set(previousUmaToken); - } - - return true; - } - } - - private static String getVREFolderNameFromContext(String context) { - if (context.startsWith("/")) { - return context.substring(1).replace("/", "-"); - } - return null; - } - /** * * @param groupId @@ -223,8 +160,9 @@ public class GCubeHookUserLocalService extends UserLocalServiceWrapper { _log.debug("Group is a VRE, proceeding with removal ..."); String scope = gm.getInfrastructureScope(groupId); org.gcube.vomanagement.usermanagement.UserManager um = new LiferayUserManager(); - String username = um.getUserById(userId).getUsername(); - setUser2VREFolder(gm, um, username, scope, false); + String username = um.getUserById(userId).getUsername(); + org.gcube.common.homelibrary.home.workspace.usermanager.UserManager hlUm = HomeLibrary.getHomeManagerFactory().getUserManager(); + hlUm.removeUserFromGroup(scope, username); Thread tToken = new Thread(new RemoveUserTokenFromVREThread(username, scope)); tToken.start(); } else {