Feature #17726 Migrate VRE Folder hook Workspace operations to Storage Hub
git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/portal/liferay62-plugins/VREFolder-hook@183523 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
5bd5d9b47f
commit
d83be63440
15
pom.xml
15
pom.xml
|
@ -42,21 +42,6 @@
|
|||
<groupId>org.gcube.core</groupId>
|
||||
<artifactId>common-encryption</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.gcube.common</groupId>
|
||||
<artifactId>home-library</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.gcube.common</groupId>
|
||||
<artifactId>home-library-model</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.gcube.common</groupId>
|
||||
<artifactId>home-library-jcr</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.gcube.dvos</groupId>
|
||||
<artifactId>usermanagement-core</artifactId>
|
||||
|
|
|
@ -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<com.liferay.portal.model.UserGroupRole> addUserGroupRoles(
|
||||
long userId, long groupId, long[] roleIds)
|
||||
throws com.liferay.portal.kernel.exception.SystemException {
|
||||
public java.util.List<com.liferay.portal.model.UserGroupRole> addUserGroupRoles(long[] userIds, long groupId, long roleId) throws com.liferay.portal.kernel.exception.SystemException {
|
||||
List<UserGroupRole> toReturn = super.addUserGroupRoles(userIds, groupId, roleId);
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
@Override
|
||||
public java.util.List<com.liferay.portal.model.UserGroupRole> addUserGroupRoles(long userId, long groupId, long[] roleIds) throws com.liferay.portal.kernel.exception.SystemException {
|
||||
List<UserGroupRole> 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<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 theAdminToken = PortalContext.getConfiguration().getCurrentUserToken(infraContext, theAdmin.getUsername());
|
||||
List<GCubeRole> theAdminRoles = rm.listRolesByUserAndGroup(theAdmin.getUserId(), rootgroupId);
|
||||
List<String> rolesString = new ArrayList<String>();
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -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<GCubeUser> 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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
package org.gcube.portal.plugins.util;
|
||||
|
||||
public class HookConstants {
|
||||
|
||||
public static final String AUTORISED_INFRA_ROLE = "Infrastructure-Manager";
|
||||
|
||||
}
|
Loading…
Reference in New Issue