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.
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
- Feature #21505: Updated to support new UMATokensProvider class

View File

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

View File

@ -66,7 +66,9 @@ public class GCubeHookSiteRoleLocalService extends UserGroupRoleLocalServiceWrap
String previousToken = SecurityTokenProvider.instance.get();
String previousUMAToken = AccessTokenProvider.instance.get();
//this put the necessary auth tokens (legacy e UMA) in ThreadLocal
try {
AuthUtil.setInfraManagerLegacyAndUMATokenInThreadLocal();
String context = gm.getInfrastructureScope(groupId);
String vreFolderTitle = Util.getVREGroupFromContext(context);
_log.debug("The vreFolderTitle on which the VREFolder role is being {} is {}", enable, vreFolderTitle);
@ -80,8 +82,11 @@ public class GCubeHookSiteRoleLocalService extends UserGroupRoleLocalServiceWrap
else
vreFolderManager.removeAdmin(theUserToPromoteOrDeclass);
_log.info("*VREFolder-Hook** add/remove role operation complete");
}
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 {
String previousToken = SecurityTokenProvider.instance.get();
String previousUMAToken = AccessTokenProvider.instance.get();
try {
AuthUtil.setInfraManagerLegacyAndUMATokenInThreadLocal();
_log.info("\n*VREFolder-Hook** new authorizationService PortalClient UMA-Token In ThreadLocal done ****\n\n");
String vreFolderNameForsHub = getVREFolderNameFromContext(context);
GroupManagerClient client = AbstractPlugin.groups().build();
if (add)
client.addUserToGroup(username2Add,vreFolderNameForsHub);
else
client.removeUserFromGroup(username2Add, vreFolderNameForsHub);
_log.info("*VREFolder-Hook** " + username2Add + " was added or removed succefully from this VRE Folder. Added? (if false was removed)" + add);
} 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);
return true;
}