diff --git a/CHANGELOG.md b/CHANGELOG.md index 7ee7a17..c7a9b7e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,13 @@ 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). +## [v1.5.0-SNAPSHOT] - 2021-06-11 + +#### Enhancements + +[#21346] Moved to AccessTokenProvider for UMA tokens "context switches" +[#21576] Adding filtering for gateway to get scopes with THREDDS role for users + ## [v1.4.0-SNAPSHOT] - 2021-05-10 #### Enhancements diff --git a/pom.xml b/pom.xml index 38843fb..13c38ec 100644 --- a/pom.xml +++ b/pom.xml @@ -12,7 +12,7 @@ org.gcube.portlets.widgets ws-thredds-sync-widget jar - 1.4.0-SNAPSHOT + 1.5.0-SNAPSHOT ws-thredds-sync-widget gCube ws-thredds-sync-widget is a widget to use and interact with ws-thredds facility in order to syncronize the Workspace folders with Thredds Reporitory folders diff --git a/src/main/java/org/gcube/portlets/widgets/wsthreddssync/server/SyncronizeWithThredds.java b/src/main/java/org/gcube/portlets/widgets/wsthreddssync/server/SyncronizeWithThredds.java index a6d9da0..4339943 100644 --- a/src/main/java/org/gcube/portlets/widgets/wsthreddssync/server/SyncronizeWithThredds.java +++ b/src/main/java/org/gcube/portlets/widgets/wsthreddssync/server/SyncronizeWithThredds.java @@ -86,17 +86,17 @@ public class SyncronizeWithThredds { try { previousUMAToken = AccessTokenProvider.instance.get(); JWTToken umaToken = OIDCUmaUtil.getUMAToken(httpRequest, user.getUsername(), targetScope); - + if (umaToken == null) { logger.info("Uma Token is null or empty, skipping operation and returning null"); return null; } String subAccessToken = umaToken.getAccessTokenString().substring(0, 10); - logger.info("Going to set UMA Token: " + subAccessToken+ "-MASKED-TOKEN"); + logger.info("Going to set UMA Token: " + subAccessToken + "-MASKED-TOKEN"); // UmaJWTProvider.instance.set(umaToken); AccessTokenProvider.instance.set(JWTTokenUtil.getAccessTokenString(umaToken)); - logger.debug("UmaJWTProvider instance set performed to : " + subAccessToken+ "-MASKED-TOKEN"); + logger.debug("UmaJWTProvider instance set performed to : " + subAccessToken + "-MASKED-TOKEN"); } catch (Exception e) { logger.warn("Error on set context for UMA: ", e); diff --git a/src/main/java/org/gcube/portlets/widgets/wsthreddssync/server/ThreddsWorkspaceSyncServiceImpl.java b/src/main/java/org/gcube/portlets/widgets/wsthreddssync/server/ThreddsWorkspaceSyncServiceImpl.java index 7e3bfb7..f04bcc5 100644 --- a/src/main/java/org/gcube/portlets/widgets/wsthreddssync/server/ThreddsWorkspaceSyncServiceImpl.java +++ b/src/main/java/org/gcube/portlets/widgets/wsthreddssync/server/ThreddsWorkspaceSyncServiceImpl.java @@ -37,7 +37,6 @@ import org.slf4j.LoggerFactory; import com.google.gwt.user.server.rpc.RemoteServiceServlet; import com.liferay.portal.service.UserLocalServiceUtil; - // TODO: Auto-generated Javadoc /** * The server side implementation of the RPC service. @@ -133,23 +132,24 @@ public class ThreddsWorkspaceSyncServiceImpl extends RemoteServiceServlet implem GCubeUser user = PortalContext.getConfiguration().getCurrentUser(this.getThreadLocalRequest()); return getConfiguration(folderId, loadStatus, this.getThreadLocalRequest(), user); } - /** * Gets the configuration. * - * @param folderId the folder id - * @param loadStatus the load status + * @param folderId the folder id + * @param loadStatus the load status * @param httpRequest the http request - * @param user the user + * @param user the user * @return the configuration * @throws Exception the exception */ - public WsThreddsSynchFolderDescriptor getConfiguration(String folderId, boolean loadStatus, HttpServletRequest httpRequest, GCubeUser user) throws Exception { + public WsThreddsSynchFolderDescriptor getConfiguration(String folderId, boolean loadStatus, + HttpServletRequest httpRequest, GCubeUser user) throws Exception { logger.debug("called internal getConfiguration for folderId: " + folderId); try { - ThSyncFolderDescriptor theConfig = getSyncService().getConfiguration(folderId, loadStatus, httpRequest, user); + ThSyncFolderDescriptor theConfig = getSyncService().getConfiguration(folderId, loadStatus, httpRequest, + user); if (theConfig != null) { logger.info("Folder id: " + folderId + " is synched"); @@ -197,10 +197,11 @@ public class ThreddsWorkspaceSyncServiceImpl extends RemoteServiceServlet implem config = BeanConverter.toThSynchFolderConfiguration(clientConfig, folderId, clientConfig.getSelectedScope().getScopeName()); logger.debug("Creating server config " + config); - }else { + } else { logger.info("The config sent from client is null, Loading it from ws-thredds"); - ThSyncFolderDescriptor descr = getSyncService().getConfiguration(folderId, false, this.getThreadLocalRequest(), user); - logger.info("From ws-thredds loaded the config: "+config); + ThSyncFolderDescriptor descr = getSyncService().getConfiguration(folderId, false, + this.getThreadLocalRequest(), user); + logger.info("From ws-thredds loaded the config: " + config); config = descr.getConfiguration(); } @@ -210,7 +211,10 @@ public class ThreddsWorkspaceSyncServiceImpl extends RemoteServiceServlet implem return status; } catch (Exception e) { logger.error("Do sync Folder error: ", e); - throw new Exception("Sorry, an error occurred during synchonization phase. The server encountered the error: "+e.getMessage(), e); + throw new Exception( + "Sorry, an error occurred during synchonization phase. The server encountered the error: " + + e.getMessage(), + e); } } @@ -228,7 +232,8 @@ public class ThreddsWorkspaceSyncServiceImpl extends RemoteServiceServlet implem try { GCubeUser user = PortalContext.getConfiguration().getCurrentUser(this.getThreadLocalRequest()); - ThSyncFolderDescriptor foldeDesr = getSyncService().getConfiguration(folderId, false, this.getThreadLocalRequest(), user); + ThSyncFolderDescriptor foldeDesr = getSyncService().getConfiguration(folderId, false, + this.getThreadLocalRequest(), user); return getSyncService().doUnSync(folderId, true, foldeDesr.getConfiguration(), this.getThreadLocalRequest(), user); } catch (Exception e) { @@ -249,7 +254,6 @@ public class ThreddsWorkspaceSyncServiceImpl extends RemoteServiceServlet implem public Map getScopesWithThreddsRolesForLoggedUser() throws Exception { logger.info("called getScopesWithThreddsRolesForLoggedUser"); - GCubeUser user = null; Map mapScopesRoles = null; // DEV MODE @@ -260,11 +264,13 @@ public class ThreddsWorkspaceSyncServiceImpl extends RemoteServiceServlet implem // mapScopesRoles.put( "/gcube/devNext/NextNext", GatewayRolesThredds.THREDDS_PUBLISHER); return mapScopesRoles; } - + + GCubeUser user = null; try { user = PortalContext.getConfiguration().getCurrentUser(this.getThreadLocalRequest()); - mapScopesRoles = WsUtil.getScopesWithThreddsRolesForUser(user); + String gatewayHostname = GenericUtils.getGatewayClientHostname(this.getThreadLocalRequest()); + mapScopesRoles = WsUtil.getScopesWithThreddsRolesForUser(user, gatewayHostname); logger.info("returning Map(scopes,roles): " + mapScopesRoles); return mapScopesRoles; diff --git a/src/main/java/org/gcube/portlets/widgets/wsthreddssync/server/WsUtil.java b/src/main/java/org/gcube/portlets/widgets/wsthreddssync/server/WsUtil.java index 51ec50d..ec6c436 100644 --- a/src/main/java/org/gcube/portlets/widgets/wsthreddssync/server/WsUtil.java +++ b/src/main/java/org/gcube/portlets/widgets/wsthreddssync/server/WsUtil.java @@ -7,6 +7,7 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Set; import javax.servlet.http.HttpServletRequest; @@ -17,6 +18,7 @@ import org.gcube.vomanagement.usermanagement.RoleManager; import org.gcube.vomanagement.usermanagement.exception.GroupRetrievalFault; import org.gcube.vomanagement.usermanagement.exception.UserManagementSystemException; import org.gcube.vomanagement.usermanagement.exception.UserRetrievalFault; +import org.gcube.vomanagement.usermanagement.exception.VirtualGroupNotExistingException; import org.gcube.vomanagement.usermanagement.impl.LiferayGroupManager; import org.gcube.vomanagement.usermanagement.impl.LiferayRoleManager; import org.gcube.vomanagement.usermanagement.model.GCubeGroup; @@ -70,17 +72,27 @@ public class WsUtil { * roles that user has in them. * * @param user the user + * @param gatewayHostname the gateway hostname * @return the VREs and Thredds roles for a given user */ - public static Map getScopesWithThreddsRolesForUser(GCubeUser user) { - logger.info("called getScopesThreddsRolesForUser user: " + user + ", in all contexts"); + public static Map getScopesWithThreddsRolesForUser(GCubeUser user, String gatewayHostname) { + logger.info("called getScopesThreddsRolesForUser user: " + user + ", in the gateway Contexts/VREs"); GroupManager groupManager = new LiferayGroupManager(); Map mapRoleByGroupSingleVre = new HashMap(); try { + + long userId = user.getUserId(); + // list of Scopes filtered for gateway + Set filteredGroupsForGatw = groupManager.listGroupsByUserAndSite(userId, gatewayHostname); + List listOfGroups = new ArrayList(filteredGroupsForGatw); + logger.info("list of VREs for user "+user.getUsername()+" in the gateway " + gatewayHostname + " are: " + listOfGroups.size()); + if(logger.isDebugEnabled()) { + for (GCubeGroup gCubeGroup : listOfGroups) { + logger.info("the user "+user.getUsername()+" is registered in the VRE "+gCubeGroup.getGroupName()); + } + } - // Retrieving the list of VOs and VREs - List listOfGroups = groupManager.listGroupsByUser(user.getUserId()); // adding also the ROOT-VO listOfGroups.add(groupManager.getRootVO()); for (GCubeGroup gCubeGroup : listOfGroups) { @@ -96,6 +108,9 @@ public class WsUtil { } catch (UserManagementSystemException | UserRetrievalFault | GroupRetrievalFault e) { logger.error("An error occurred during geThreddsVreRolesForUser: " + user, e); return null; + } catch (VirtualGroupNotExistingException e) { + logger.error("An error occurred during geThreddsVreRolesForUser: " + user, e); + return null; } }