This commit is contained in:
Massimiliano Assante 2021-11-30 15:44:30 +01:00
parent 2f6b6af28c
commit d6780fea79
4 changed files with 42 additions and 29 deletions

View File

@ -4,6 +4,10 @@
All notable changes to this project will be documented in this file. 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). This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [v6.8.3-SNAPSHOT] - 2021-11-30
- Bug Fix #22483: setUser2VREFolder may not restore ThreadLocal user variable
## [v6.8.2] - 2021-05-25 ## [v6.8.2] - 2021-05-25
- Feature #21505: Updated to support new UMATokensProvider class - Feature #21505: Updated to support new UMATokensProvider class

View File

@ -12,7 +12,7 @@
<groupId>org.gcube.portal.plugins</groupId> <groupId>org.gcube.portal.plugins</groupId>
<artifactId>VREFolder-hook</artifactId> <artifactId>VREFolder-hook</artifactId>
<name>VREFolder-hook Hook</name> <name>VREFolder-hook Hook</name>
<version>6.8.2</version> <version>6.8.3-SNAPSHOT</version>
<packaging>war</packaging> <packaging>war</packaging>
<description> <description>
VREFolder-hook handles the user adding/removal from the related Home Library VRE Folder VREFolder-hook handles the user adding/removal from the related Home Library VRE Folder

View File

@ -66,22 +66,27 @@ public class GCubeHookSiteRoleLocalService extends UserGroupRoleLocalServiceWrap
String previousToken = SecurityTokenProvider.instance.get(); String previousToken = SecurityTokenProvider.instance.get();
String previousUMAToken = AccessTokenProvider.instance.get(); String previousUMAToken = AccessTokenProvider.instance.get();
//this put the necessary auth tokens (legacy e UMA) in ThreadLocal //this put the necessary auth tokens (legacy e UMA) in ThreadLocal
AuthUtil.setInfraManagerLegacyAndUMATokenInThreadLocal(); try {
String context = gm.getInfrastructureScope(groupId); AuthUtil.setInfraManagerLegacyAndUMATokenInThreadLocal();
String vreFolderTitle = Util.getVREGroupFromContext(context);
_log.debug("The vreFolderTitle on which the VREFolder role is being {} is {}", enable, vreFolderTitle); String context = gm.getInfrastructureScope(groupId);
StorageHubClient shc = new StorageHubClient(); String vreFolderTitle = Util.getVREGroupFromContext(context);
VREFolderManager vreFolderManager = shc.getVreFolderManager(vreFolderTitle); _log.debug("The vreFolderTitle on which the VREFolder role is being {} is {}", enable, vreFolderTitle);
StorageHubClient shc = new StorageHubClient();
String theUserToPromoteOrDeclass = new LiferayUserManager().getUserById(userId).getUsername(); VREFolderManager vreFolderManager = shc.getVreFolderManager(vreFolderTitle);
_log.info("The {} is being promoted? {} ", theUserToPromoteOrDeclass, enable);
if (enable) String theUserToPromoteOrDeclass = new LiferayUserManager().getUserById(userId).getUsername();
vreFolderManager.setAdmin(theUserToPromoteOrDeclass); _log.info("The {} is being promoted? {} ", theUserToPromoteOrDeclass, enable);
else if (enable)
vreFolderManager.removeAdmin(theUserToPromoteOrDeclass); vreFolderManager.setAdmin(theUserToPromoteOrDeclass);
_log.info("*VREFolder-Hook** add/remove role operation complete"); else
vreFolderManager.removeAdmin(theUserToPromoteOrDeclass);
AccessTokenProvider.instance.set(previousUMAToken); _log.info("*VREFolder-Hook** add/remove role operation complete");
SecurityTokenProvider.instance.set(previousToken); }
finally {
AccessTokenProvider.instance.set(previousUMAToken);
SecurityTokenProvider.instance.set(previousToken);
_log.warn("An error occurred (or the user was already Admin) when trying to update shub role of userId "+ userId + " to the groupId: " + groupId);
}
} }
} }

View File

@ -151,18 +151,22 @@ public class GCubeHookUserLocalService extends UserLocalServiceWrapper {
private boolean setUser2VREFolder(GroupManager gm, UserManager uMan, String username2Add, String context, boolean add) throws Exception { private boolean setUser2VREFolder(GroupManager gm, UserManager uMan, String username2Add, String context, boolean add) throws Exception {
String previousToken = SecurityTokenProvider.instance.get(); String previousToken = SecurityTokenProvider.instance.get();
String previousUMAToken = AccessTokenProvider.instance.get(); String previousUMAToken = AccessTokenProvider.instance.get();
AuthUtil.setInfraManagerLegacyAndUMATokenInThreadLocal(); try {
_log.info("\n*VREFolder-Hook** new authorizationService PortalClient UMA-Token In ThreadLocal done ****\n\n"); AuthUtil.setInfraManagerLegacyAndUMATokenInThreadLocal();
String vreFolderNameForsHub = getVREFolderNameFromContext(context); _log.info("\n*VREFolder-Hook** new authorizationService PortalClient UMA-Token In ThreadLocal done ****\n\n");
GroupManagerClient client = AbstractPlugin.groups().build(); String vreFolderNameForsHub = getVREFolderNameFromContext(context);
if (add)
client.addUserToGroup(username2Add,vreFolderNameForsHub); GroupManagerClient client = AbstractPlugin.groups().build();
else if (add)
client.removeUserFromGroup(username2Add, vreFolderNameForsHub); client.addUserToGroup(username2Add,vreFolderNameForsHub);
else
client.removeUserFromGroup(username2Add, vreFolderNameForsHub);
} finally {
AccessTokenProvider.instance.set(previousUMAToken);
SecurityTokenProvider.instance.set(previousToken);
_log.warn("An error occurred (or the user was already member) when trying to remove or add the user "+ username2Add + " to the VRE context: " + context);
}
_log.info("*VREFolder-Hook** " + username2Add + " was added or removed succefully from this VRE Folder. Added? (if false was removed)" + add); _log.info("*VREFolder-Hook** " + username2Add + " was added or removed succefully from this VRE Folder. Added? (if false was removed)" + add);
AccessTokenProvider.instance.set(previousUMAToken);
SecurityTokenProvider.instance.set(previousToken);
return true; return true;
} }