diff --git a/pom.xml b/pom.xml
index f6934d2..4c58d7a 100644
--- a/pom.xml
+++ b/pom.xml
@@ -42,21 +42,6 @@
org.gcube.core
common-encryption
-
- org.gcube.common
- home-library
- provided
-
-
- org.gcube.common
- home-library-model
- provided
-
-
- org.gcube.common
- home-library-jcr
- provided
-
org.gcube.dvos
usermanagement-core
diff --git a/src/main/java/org/gcube/portal/plugins/GCubeHookSiteRoleLocalService.java b/src/main/java/org/gcube/portal/plugins/GCubeHookSiteRoleLocalService.java
index bec6777..3efb894 100644
--- a/src/main/java/org/gcube/portal/plugins/GCubeHookSiteRoleLocalService.java
+++ b/src/main/java/org/gcube/portal/plugins/GCubeHookSiteRoleLocalService.java
@@ -6,16 +6,17 @@ import java.util.ArrayList;
import java.util.List;
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
-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.plugins.AbstractPlugin;
-import org.gcube.common.storagehub.client.proxies.GroupManagerClient;
+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.plugins.util.HookConstants;
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.GCubeUser;
import org.slf4j.Logger;
@@ -36,18 +37,24 @@ public class GCubeHookSiteRoleLocalService extends UserGroupRoleLocalServiceWrap
*/
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 userId, long groupId, long[] roleIds)
- throws com.liferay.portal.kernel.exception.SystemException {
+ 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;
+ }
+
+ @Override
+ public java.util.List addUserGroupRoles(long userId, long groupId, long[] roleIds) throws com.liferay.portal.kernel.exception.SystemException {
List toReturn = super.addUserGroupRoles(userId, groupId, roleIds);
-
try {
String context = gm.getInfrastructureScope(groupId);
String username = UserLocalServiceUtil.getUser(userId).getScreenName();
@@ -86,24 +93,46 @@ public class GCubeHookSiteRoleLocalService extends UserGroupRoleLocalServiceWrap
return toReturn;
}
- private void setVREFolderAdministrator(long userId, long groupId, boolean enable) throws Exception {
-
- String scopeVREFolder = gm.getInfrastructureScope(groupId);
-
- String currScope = ScopeProvider.instance.get();
- String scopeToset = "/"+PortalContext.getConfiguration().getInfrastructureName();
- ScopeProvider.instance.set(scopeToset);
-
- 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);
+ 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.debug("The vreFolderTitle on which the VREFolder role is being {} is {}", enable, vreFolderTitle);
+ StorageHubClient shc = new StorageHubClient();
+ VREFolderManager vreFolderManager = shc.getVreFolderManager(vreFolderTitle);
+
+ String previousToken = SecurityTokenProvider.instance.get();
+ //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 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 theAdminToken = PortalContext.getConfiguration().getCurrentUserToken(infraContext, theAdmin.getUsername());
+ List theAdminRoles = rm.listRolesByUserAndGroup(theAdmin.getUserId(), rootgroupId);
+ List rolesString = new ArrayList();
+ for (GCubeRole gCubeRole : theAdminRoles) {
+ rolesString.add(gCubeRole.getRoleName());
+ }
+ authorizationService().setTokenRoles(theAdminToken, rolesString);
+ SecurityTokenProvider.instance.set(theAdminToken);
+
+ 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);
+ return true;
+ }
}
-
-
+
+
}
diff --git a/src/main/java/org/gcube/portal/plugins/GCubeHookUserLocalService.java b/src/main/java/org/gcube/portal/plugins/GCubeHookUserLocalService.java
index 0479859..34fe02b 100644
--- a/src/main/java/org/gcube/portal/plugins/GCubeHookUserLocalService.java
+++ b/src/main/java/org/gcube/portal/plugins/GCubeHookUserLocalService.java
@@ -13,6 +13,7 @@ import org.gcube.common.storagehub.client.proxies.GroupManagerClient;
import org.gcube.portal.plugins.thread.CheckShareLatexUserThread;
import org.gcube.portal.plugins.thread.RemoveUserTokenFromVREThread;
import org.gcube.portal.plugins.thread.UpdateUserToLDAPGroupThread;
+import org.gcube.portal.plugins.util.HookConstants;
import org.gcube.vomanagement.usermanagement.GroupManager;
import org.gcube.vomanagement.usermanagement.RoleManager;
import org.gcube.vomanagement.usermanagement.UserManager;
@@ -34,7 +35,7 @@ import com.liferay.portal.service.UserLocalServiceWrapper;
*
*/
public class GCubeHookUserLocalService extends UserLocalServiceWrapper {
- public static final String AUTORISED_INFRA_ROLE = "Infrastructure-Manager";
+
/**
* logger
*/
@@ -151,14 +152,15 @@ public class GCubeHookUserLocalService extends UserLocalServiceWrapper {
}
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 groupId = gm.getGroupIdFromInfrastructureScope(infraContext);
RoleManager rm = new LiferayRoleManager();
- long roleId = rm.getRoleId(AUTORISED_INFRA_ROLE, groupId);
+ long roleId = rm.getRoleId(HookConstants.AUTORISED_INFRA_ROLE, groupId);
List users = uMan.listUsersByGroupAndRole(groupId, roleId);
if (users.isEmpty()) {
- _log.error("Cannot add the user to the VRE Folder: there is no user having role " + AUTORISED_INFRA_ROLE + " on context: " + infraContext);
+ _log.error("Cannot add the user to the VRE Folder: there is no user having role " + HookConstants.AUTORISED_INFRA_ROLE + " on context: " + infraContext);
return false;
}
else {
@@ -176,6 +178,7 @@ public class GCubeHookUserLocalService extends UserLocalServiceWrapper {
client.addUserToGroup(username2Add, getVREFolderNameFromContext(context));
else
client.removeUserFromGroup(username2Add, getVREFolderNameFromContext(context));
+ SecurityTokenProvider.instance.set(previousToken);
return true;
}
}
diff --git a/src/main/java/org/gcube/portal/plugins/util/HookConstants.java b/src/main/java/org/gcube/portal/plugins/util/HookConstants.java
new file mode 100644
index 0000000..f15e900
--- /dev/null
+++ b/src/main/java/org/gcube/portal/plugins/util/HookConstants.java
@@ -0,0 +1,7 @@
+package org.gcube.portal.plugins.util;
+
+public class HookConstants {
+
+ public static final String AUTORISED_INFRA_ROLE = "Infrastructure-Manager";
+
+}