Moved to maven-portal-bom 3.6.3

Just to include new version of ws-thredds
master
Francesco Mangiacrapa 3 years ago
parent f25dd02ca4
commit 17c705f6db

@ -4,6 +4,15 @@ 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).
## [v1.5.0-SNAPSHOT] - 2021-07-20
#### Enhancements
[#21346] Moved to AccessTokenProvider for UMA tokens "context switches"
[#21576] Adding filtering for gateway to get scopes with THREDDS role for users
Moved to maven-portal-bom 3.6.3
Just to include new version of ws-thredds
## [v1.4.1-SNAPSHOT] - 2021-07-20 ## [v1.4.1-SNAPSHOT] - 2021-07-20
Moved to maven-portal-bom 3.6.3 Moved to maven-portal-bom 3.6.3

@ -12,7 +12,7 @@
<groupId>org.gcube.portlets.widgets</groupId> <groupId>org.gcube.portlets.widgets</groupId>
<artifactId>ws-thredds-sync-widget</artifactId> <artifactId>ws-thredds-sync-widget</artifactId>
<packaging>jar</packaging> <packaging>jar</packaging>
<version>1.4.1-SNAPSHOT</version> <version>1.5.0-SNAPSHOT</version>
<name>ws-thredds-sync-widget</name> <name>ws-thredds-sync-widget</name>
<description> <description>
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 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

@ -8,11 +8,12 @@ import java.util.Map;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import org.gcube.common.authorization.library.provider.AccessTokenProvider;
import org.gcube.common.authorization.library.provider.SecurityTokenProvider; import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
import org.gcube.common.authorization.library.provider.UmaJWTProvider;
import org.gcube.common.portal.PortalContext; import org.gcube.common.portal.PortalContext;
import org.gcube.common.scope.api.ScopeProvider; import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.oidc.rest.JWTToken; import org.gcube.oidc.rest.JWTToken;
import org.gcube.portal.oidc.lr62.JWTTokenUtil;
import org.gcube.portal.oidc.lr62.OIDCUmaUtil; import org.gcube.portal.oidc.lr62.OIDCUmaUtil;
import org.gcube.portal.wssynclibrary.shared.ItemNotSynched; import org.gcube.portal.wssynclibrary.shared.ItemNotSynched;
import org.gcube.portal.wssynclibrary.shared.WorkspaceFolderLocked; import org.gcube.portal.wssynclibrary.shared.WorkspaceFolderLocked;
@ -28,12 +29,11 @@ import org.gcube.vomanagement.usermanagement.model.GCubeUser;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
/** /**
* The Class SyncronizeWithThredds. * The Class SyncronizeWithThredds.
* *
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it Feb 7, 2018 * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it Feb 7, 2018
* updated May, 2021 * updated May, 2021
*/ */
public class SyncronizeWithThredds { public class SyncronizeWithThredds {
@ -84,40 +84,31 @@ public class SyncronizeWithThredds {
logger.debug("Setting UMA context with target scope: " + targetScope + ", user: " + user.getUsername()); logger.debug("Setting UMA context with target scope: " + targetScope + ", user: " + user.getUsername());
String previousUMAToken = null; String previousUMAToken = null;
try { try {
previousUMAToken = UmaJWTProvider.instance.get(); previousUMAToken = AccessTokenProvider.instance.get();
JWTToken umaToken = OIDCUmaUtil.getUMAToken(httpRequest, user.getUsername(), targetScope); JWTToken umaToken = OIDCUmaUtil.getUMAToken(httpRequest, user.getUsername(), targetScope);
setContextForUMA(umaToken.getRaw());
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");
// UmaJWTProvider.instance.set(umaToken);
AccessTokenProvider.instance.set(JWTTokenUtil.getAccessTokenString(umaToken));
logger.debug("UmaJWTProvider instance set performed to : " + subAccessToken + "-MASKED-TOKEN");
} catch (Exception e) { } catch (Exception e) {
logger.warn("Error on set context for UMA: ", e); logger.warn("Error on set context for UMA: ", e);
if (previousUMAToken != null) { if (previousUMAToken != null) {
logger.info("Setting previous UMA Token: " + previousUMAToken.substring(0, 10) + "-MASKED-TOKEN"); logger.info("Setting previous UMA Token: " + previousUMAToken.substring(0, 10) + "-MASKED-TOKEN");
setContextForUMA(previousUMAToken); AccessTokenProvider.instance.set(previousUMAToken);
} }
} }
return previousUMAToken; return previousUMAToken;
} }
/**
* Reset context for UMA.
*
* @param umaToken the uma token
* @return the string
*/
private void setContextForUMA(String umaToken) {
logger.info("called set context for UMA");
if (umaToken == null || umaToken.isEmpty()) {
logger.info("Uma Token is null or empty, skipping operation");
return;
}
logger.info("Going to set UMA Token: " + umaToken.substring(0, 10) + "-MASKED-TOKEN");
UmaJWTProvider.instance.set(umaToken);
logger.debug("UmaJWTProvider instance set performed to : " + umaToken.substring(0, 10) + "-MASKED-TOKEN");
}
/** /**
* Checks if is item synched. * Checks if is item synched.
* *
@ -140,19 +131,19 @@ public class SyncronizeWithThredds {
/** /**
* Gets the configuration. * Gets the configuration.
* *
* @param folderId the folder id * @param folderId the folder id
* @param loadStatus the load status. If true it loads the status by calling the * @param loadStatus the load status. If true it loads the status by calling
* {@link SyncEngine#check(String, boolean)} but it is time * the {@link SyncEngine#check(String, boolean)} but it is
* consuming. Otherwise it calls the * time consuming. Otherwise it calls the
* {@link SyncEngine#getConfig(String)} without sync status * {@link SyncEngine#getConfig(String)} without sync status
* @param httpRequest the http request * @param httpRequest the http request
* @param user the user * @param user the user
* @return the configuration * @return the configuration
* @throws ItemNotSynched the item not synched * @throws ItemNotSynched the item not synched
* @throws Exception the exception * @throws Exception the exception
*/ */
public ThSyncFolderDescriptor getConfiguration(String folderId, boolean loadStatus, HttpServletRequest httpRequest, GCubeUser user) public ThSyncFolderDescriptor getConfiguration(String folderId, boolean loadStatus, HttpServletRequest httpRequest,
throws ItemNotSynched, Exception { GCubeUser user) throws ItemNotSynched, Exception {
ThSyncFolderDescriptor config = null; ThSyncFolderDescriptor config = null;
String wsScope = PortalContext.getConfiguration().getCurrentScope(httpRequest); String wsScope = PortalContext.getConfiguration().getCurrentScope(httpRequest);
@ -162,11 +153,11 @@ public class SyncronizeWithThredds {
String previousUmaToken = null; String previousUmaToken = null;
String targetScope = null; String targetScope = null;
try { try {
setContextParameters(wsScope, wsUserToken); setContextParameters(wsScope, wsUserToken);
if (loadStatus) { if (loadStatus) {
config = workspaceThreddsSynchronizeLib.getConfiguration(folderId); config = workspaceThreddsSynchronizeLib.getConfiguration(folderId);
// context switch for UMA token // context switch for UMA token
targetScope = config.getConfiguration().getTargetContext(); targetScope = config.getConfiguration().getTargetContext();
@ -174,10 +165,10 @@ public class SyncronizeWithThredds {
// context switch for gcube-token and scope // context switch for gcube-token and scope
// getting token into target scope // getting token into target scope
String targetScopeUserToken = PortalContext.getConfiguration().getCurrentUserToken(targetScope, String targetScopeUserToken = PortalContext.getConfiguration().getCurrentUserToken(targetScope,
user.getUsername()); user.getUsername());
setContextParameters(targetScope, targetScopeUserToken); setContextParameters(targetScope, targetScopeUserToken);
config = workspaceThreddsSynchronizeLib.checkItemSynched(folderId); config = workspaceThreddsSynchronizeLib.checkItemSynched(folderId);
} else { } else {
config = workspaceThreddsSynchronizeLib.getConfiguration(folderId); config = workspaceThreddsSynchronizeLib.getConfiguration(folderId);
@ -187,18 +178,19 @@ public class SyncronizeWithThredds {
logger.debug("WorkspaceNotSynchedException catched. The item with id: " + folderId + " is not synched"); logger.debug("WorkspaceNotSynchedException catched. The item with id: " + folderId + " is not synched");
} catch (WorkspaceFolderLocked e1) { } catch (WorkspaceFolderLocked e1) {
logger.info("The folder with id: " + folderId + " is locked"); logger.info("The folder with id: " + folderId + " is locked");
throw new Exception("The folder with id: "+folderId +" is currently locked. Another sync process is in progress"); throw new Exception(
"The folder with id: " + folderId + " is currently locked. Another sync process is in progress");
} catch (Exception e) { } catch (Exception e) {
logger.error("Error on reading the configuration for id: " + folderId, e); logger.error("Error on reading the configuration for id: " + folderId, e);
throw e; throw e;
} finally { } finally {
if(previousUmaToken!=null) { if (previousUmaToken != null) {
// resetting UMA token in the WS scope // resetting UMA token in the WS scope
setContextForUMA(previousUmaToken); AccessTokenProvider.instance.set(previousUmaToken);
} }
if (originalScope != null && targetScope!=null && originalScope.compareTo(targetScope) != 0) { if (originalScope != null && targetScope != null && originalScope.compareTo(targetScope) != 0) {
logger.info("Resetting the scope: " + originalScope + " which was original WS context"); logger.info("Resetting the scope: " + originalScope + " which was original WS context");
ScopeProvider.instance.set(originalScope); ScopeProvider.instance.set(originalScope);
if (originalToken != null) { if (originalToken != null) {
@ -250,8 +242,10 @@ public class SyncronizeWithThredds {
} finally { } finally {
// resetting UMA token in the WS scope if (previousUmaToken != null) {
setContextForUMA(previousUmaToken); // resetting UMA token in the WS scope
AccessTokenProvider.instance.set(previousUmaToken);
}
if (originalScope != null && originalScope.compareTo(targetScope) != 0) { if (originalScope != null && originalScope.compareTo(targetScope) != 0) {
logger.info("Resetting the scope: " + originalScope + " which was original WS context"); logger.info("Resetting the scope: " + originalScope + " which was original WS context");
@ -332,13 +326,15 @@ public class SyncronizeWithThredds {
return workspaceThreddsSynchronizeLib.doSync(folderId); return workspaceThreddsSynchronizeLib.doSync(folderId);
} catch (Exception e) { } catch (Exception e) {
logger.error("Error on doSyncFolder for folderId: "+folderId, e); logger.error("Error on doSyncFolder for folderId: " + folderId, e);
throw e; throw e;
} finally { } finally {
// resetting UMA token in the WS scope if (previousUmaToken != null) {
setContextForUMA(previousUmaToken); // resetting UMA token in the WS scope
AccessTokenProvider.instance.set(previousUmaToken);
}
if (originalScope != null && originalScope.compareTo(targetScope) != 0) { if (originalScope != null && originalScope.compareTo(targetScope) != 0) {
logger.info("Resetting the scope: " + originalScope + " which was original WS context"); logger.info("Resetting the scope: " + originalScope + " which was original WS context");
@ -408,8 +404,10 @@ public class SyncronizeWithThredds {
} finally { } finally {
// resetting UMA token in the WS scope if (previousUmaToken != null) {
setContextForUMA(previousUmaToken); // resetting UMA token in the WS scope
AccessTokenProvider.instance.set(previousUmaToken);
}
if (originalScope != null && originalScope.compareTo(targetScope) != 0) { if (originalScope != null && originalScope.compareTo(targetScope) != 0) {
logger.info("Resetting the scope: " + originalScope + " which was original WS context"); logger.info("Resetting the scope: " + originalScope + " which was original WS context");

@ -37,7 +37,6 @@ import org.slf4j.LoggerFactory;
import com.google.gwt.user.server.rpc.RemoteServiceServlet; import com.google.gwt.user.server.rpc.RemoteServiceServlet;
import com.liferay.portal.service.UserLocalServiceUtil; import com.liferay.portal.service.UserLocalServiceUtil;
// TODO: Auto-generated Javadoc // TODO: Auto-generated Javadoc
/** /**
* The server side implementation of the RPC service. * 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()); GCubeUser user = PortalContext.getConfiguration().getCurrentUser(this.getThreadLocalRequest());
return getConfiguration(folderId, loadStatus, this.getThreadLocalRequest(), user); return getConfiguration(folderId, loadStatus, this.getThreadLocalRequest(), user);
} }
/** /**
* Gets the configuration. * Gets the configuration.
* *
* @param folderId the folder id * @param folderId the folder id
* @param loadStatus the load status * @param loadStatus the load status
* @param httpRequest the http request * @param httpRequest the http request
* @param user the user * @param user the user
* @return the configuration * @return the configuration
* @throws Exception the exception * @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); logger.debug("called internal getConfiguration for folderId: " + folderId);
try { try {
ThSyncFolderDescriptor theConfig = getSyncService().getConfiguration(folderId, loadStatus, httpRequest, user); ThSyncFolderDescriptor theConfig = getSyncService().getConfiguration(folderId, loadStatus, httpRequest,
user);
if (theConfig != null) { if (theConfig != null) {
logger.info("Folder id: " + folderId + " is synched"); logger.info("Folder id: " + folderId + " is synched");
@ -197,10 +197,11 @@ public class ThreddsWorkspaceSyncServiceImpl extends RemoteServiceServlet implem
config = BeanConverter.toThSynchFolderConfiguration(clientConfig, folderId, config = BeanConverter.toThSynchFolderConfiguration(clientConfig, folderId,
clientConfig.getSelectedScope().getScopeName()); clientConfig.getSelectedScope().getScopeName());
logger.debug("Creating server config " + config); logger.debug("Creating server config " + config);
}else { } else {
logger.info("The config sent from client is null, Loading it from ws-thredds"); logger.info("The config sent from client is null, Loading it from ws-thredds");
ThSyncFolderDescriptor descr = getSyncService().getConfiguration(folderId, false, this.getThreadLocalRequest(), user); ThSyncFolderDescriptor descr = getSyncService().getConfiguration(folderId, false,
logger.info("From ws-thredds loaded the config: "+config); this.getThreadLocalRequest(), user);
logger.info("From ws-thredds loaded the config: " + config);
config = descr.getConfiguration(); config = descr.getConfiguration();
} }
@ -210,7 +211,10 @@ public class ThreddsWorkspaceSyncServiceImpl extends RemoteServiceServlet implem
return status; return status;
} catch (Exception e) { } catch (Exception e) {
logger.error("Do sync Folder error: ", 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 { try {
GCubeUser user = PortalContext.getConfiguration().getCurrentUser(this.getThreadLocalRequest()); 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(), return getSyncService().doUnSync(folderId, true, foldeDesr.getConfiguration(), this.getThreadLocalRequest(),
user); user);
} catch (Exception e) { } catch (Exception e) {
@ -249,7 +254,6 @@ public class ThreddsWorkspaceSyncServiceImpl extends RemoteServiceServlet implem
public Map<String, GatewayRolesThredds> getScopesWithThreddsRolesForLoggedUser() throws Exception { public Map<String, GatewayRolesThredds> getScopesWithThreddsRolesForLoggedUser() throws Exception {
logger.info("called getScopesWithThreddsRolesForLoggedUser"); logger.info("called getScopesWithThreddsRolesForLoggedUser");
GCubeUser user = null;
Map<String, GatewayRolesThredds> mapScopesRoles = null; Map<String, GatewayRolesThredds> mapScopesRoles = null;
// DEV MODE // DEV MODE
@ -260,11 +264,13 @@ public class ThreddsWorkspaceSyncServiceImpl extends RemoteServiceServlet implem
// mapScopesRoles.put( "/gcube/devNext/NextNext", GatewayRolesThredds.THREDDS_PUBLISHER); // mapScopesRoles.put( "/gcube/devNext/NextNext", GatewayRolesThredds.THREDDS_PUBLISHER);
return mapScopesRoles; return mapScopesRoles;
} }
GCubeUser user = null;
try { try {
user = PortalContext.getConfiguration().getCurrentUser(this.getThreadLocalRequest()); 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); logger.info("returning Map(scopes,roles): " + mapScopesRoles);
return mapScopesRoles; return mapScopesRoles;

@ -7,6 +7,7 @@ import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set;
import javax.servlet.http.HttpServletRequest; 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.GroupRetrievalFault;
import org.gcube.vomanagement.usermanagement.exception.UserManagementSystemException; import org.gcube.vomanagement.usermanagement.exception.UserManagementSystemException;
import org.gcube.vomanagement.usermanagement.exception.UserRetrievalFault; 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.LiferayGroupManager;
import org.gcube.vomanagement.usermanagement.impl.LiferayRoleManager; import org.gcube.vomanagement.usermanagement.impl.LiferayRoleManager;
import org.gcube.vomanagement.usermanagement.model.GCubeGroup; import org.gcube.vomanagement.usermanagement.model.GCubeGroup;
@ -70,17 +72,27 @@ public class WsUtil {
* roles that user has in them. * roles that user has in them.
* *
* @param user the user * @param user the user
* @param gatewayHostname the gateway hostname
* @return the VREs and Thredds roles for a given user * @return the VREs and Thredds roles for a given user
*/ */
public static Map<String, GatewayRolesThredds> getScopesWithThreddsRolesForUser(GCubeUser user) { public static Map<String, GatewayRolesThredds> getScopesWithThreddsRolesForUser(GCubeUser user, String gatewayHostname) {
logger.info("called getScopesThreddsRolesForUser user: " + user + ", in all contexts"); logger.info("called getScopesThreddsRolesForUser user: " + user + ", in the gateway Contexts/VREs");
GroupManager groupManager = new LiferayGroupManager(); GroupManager groupManager = new LiferayGroupManager();
Map<String, GatewayRolesThredds> mapRoleByGroupSingleVre = new HashMap<String, GatewayRolesThredds>(); Map<String, GatewayRolesThredds> mapRoleByGroupSingleVre = new HashMap<String, GatewayRolesThredds>();
try { try {
long userId = user.getUserId();
// list of Scopes filtered for gateway
Set<GCubeGroup> filteredGroupsForGatw = groupManager.listGroupsByUserAndSite(userId, gatewayHostname);
List<GCubeGroup> listOfGroups = new ArrayList<GCubeGroup>(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<GCubeGroup> listOfGroups = groupManager.listGroupsByUser(user.getUserId());
// adding also the ROOT-VO // adding also the ROOT-VO
listOfGroups.add(groupManager.getRootVO()); listOfGroups.add(groupManager.getRootVO());
for (GCubeGroup gCubeGroup : listOfGroups) { for (GCubeGroup gCubeGroup : listOfGroups) {
@ -96,6 +108,9 @@ public class WsUtil {
} catch (UserManagementSystemException | UserRetrievalFault | GroupRetrievalFault e) { } catch (UserManagementSystemException | UserRetrievalFault | GroupRetrievalFault e) {
logger.error("An error occurred during geThreddsVreRolesForUser: " + user, e); logger.error("An error occurred during geThreddsVreRolesForUser: " + user, e);
return null; return null;
} catch (VirtualGroupNotExistingException e) {
logger.error("An error occurred during geThreddsVreRolesForUser: " + user, e);
return null;
} }
} }

Loading…
Cancel
Save