starting work on Feature #20979

This commit is contained in:
Francesco Mangiacrapa 2021-03-16 18:16:50 +01:00
parent 660d869ab5
commit ec3c24f78b
5 changed files with 71 additions and 34 deletions

View File

@ -3,10 +3,13 @@
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).
## [v1.3.0-SNAPSHOT] - 2021-03-03 ## [v1.3.0-SNAPSHOT] - 2021-03-16
[#20847] Support the roles of THREDDS Admin and THREDDS Publisher [#20847] Support the roles of THREDDS Admin and THREDDS Publisher
[#20979] Changed the business logic to invoke the lib ws-thredds
## [v1.2.0] - 2020-07-21 ## [v1.2.0] - 2020-07-21
[#19676] Migrated to git/jenkins [#19676] Migrated to git/jenkins

View File

@ -54,7 +54,7 @@ public class BeanConverter {
ws.setSelectedScope(selectedScope); ws.setSelectedScope(selectedScope);
logger.debug("Resolved SCOPE: " + selectedScope + " from token"); logger.debug("Resolved SCOPE: " + selectedScope + " from token");
} catch (Exception e) { } catch (Exception e) {
// TODO: handle exception logger.error("I cannot resolve the scope for the token: "+t.getConfiguration().getTargetToken());
} }
} }

View File

@ -90,8 +90,9 @@ public class SyncronizeWithThredds {
try{ try{
if(firstSync) { if(firstSync) {
if(thConfig==null) if(thConfig==null) {
throw new Exception("A valid folder configuration must be provided to perforom synchronization"); throw new Exception("A valid folder configuration must be provided to perform the synchronization");
}
logger.info("First sync setting synchronized folder configuration: "+thConfig); logger.info("First sync setting synchronized folder configuration: "+thConfig);
workspaceThreddsSynchronize.setSynchronizedFolder(thConfig, folderId); workspaceThreddsSynchronize.setSynchronizedFolder(thConfig, folderId);

View File

@ -2,7 +2,6 @@ package org.gcube.portlets.widgets.wsthreddssync.server;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
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 java.util.Set;
@ -100,31 +99,62 @@ public class ThreddsWorkspaceSyncServiceImpl extends RemoteServiceServlet implem
public ThSyncStatus doSyncFolder(final String folderId, WsThreddsSynchFolderConfiguration clientConfig) throws Exception{ public ThSyncStatus doSyncFolder(final String folderId, WsThreddsSynchFolderConfiguration clientConfig) throws Exception{
logger.info("Performing doSyncFolder method on id: "+folderId +", config: "+clientConfig); logger.info("Performing doSyncFolder method on id: "+folderId +", config: "+clientConfig);
String originalScope = null;
String originalToken = null;
try { try {
GCubeUser user = PortalContext.getConfiguration().getCurrentUser(this.getThreadLocalRequest());
PortalContext portalContext = PortalContext.getConfiguration();
final GCubeUser user = portalContext.getCurrentUser(this.getThreadLocalRequest());
final String wsScope = portalContext.getCurrentScope(this.getThreadLocalRequest());
final String wsUserToken = portalContext.getCurrentUserToken(wsScope, user.getUsername());
//Thread Local contexts
originalScope = wsScope;
originalToken = wsUserToken;
String targetScopeUserToken = null; String targetScopeUserToken = null;
ThSynchFolderConfiguration config = null; ThSynchFolderConfiguration config = null;
if(clientConfig!=null) { if(clientConfig!=null) {
targetScopeUserToken = PortalContext.getConfiguration().getCurrentUserToken(clientConfig.getSelectedScope().getScopeName(), user.getUsername()); targetScopeUserToken = portalContext.getCurrentUserToken(clientConfig.getSelectedScope().getScopeName(), user.getUsername());
config = BeanConverter.toThSynchFolderConfiguration(clientConfig, folderId, targetScopeUserToken); config = BeanConverter.toThSynchFolderConfiguration(clientConfig, folderId, targetScopeUserToken);
logger.debug("Creating server config "+config); logger.debug("Creating server config "+config);
} }
/* Commented because Feature #20979
logger.info("Calling doSyncFolder on folderId: "+folderId +", config: "+config); logger.info("Calling doSyncFolder on folderId: "+folderId +", config: "+config);
String wsScope = PortalContext.getConfiguration().getCurrentScope(this.getThreadLocalRequest()); String wsScope = PortalContext.getConfiguration().getCurrentScope(this.getThreadLocalRequest());
String wsUserToken = PortalContext.getConfiguration().getCurrentUserToken(wsScope, user.getUsername()); String wsUserToken = PortalContext.getConfiguration().getCurrentUserToken(wsScope, user.getUsername());
*/
ThSyncStatus status = getSyncService().doSyncFolder(folderId, config, wsScope, wsUserToken);
logger.info("Calling doSyncFolder on folderId: "+folderId +", config: "+config);
logger.info("Changing the context to target scope: "+clientConfig.getSelectedScope().getScopeName() +", target token: "+targetScopeUserToken.substring(0,10)+"-MASKED-TOKEN");
String targetScope = clientConfig.getSelectedScope().getScopeName();
ThSyncStatus status = getSyncService().doSyncFolder(folderId, config, targetScope, targetScopeUserToken);
logger.debug("Returning for folderId "+folderId+" the syncStatus: "+status); logger.debug("Returning for folderId "+folderId+" the syncStatus: "+status);
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, try again later"); throw new Exception("Sorry, an error occurred during synchonization phase, try again later");
}finally {
String currentScope = PortalContext.getConfiguration().getCurrentScope(this.getThreadLocalRequest());
if(originalScope!=null && originalScope.compareTo(currentScope)!=0) {
logger.info("Resetting the scope: "+originalScope + " which was original WS context");
ScopeProvider.instance.set(originalScope);
if(originalToken!=null) {
logger.info("Resetting the user token: "+originalToken.substring(0,10)+"-MASKED-TOKEN which was original WS context");
SecurityTokenProvider.instance.set(originalToken);
}
}
} }
} }
/** /**
* Gets the available THREDDS catalogues for target scope. * Gets the available THREDDS catalogues for target scope.
@ -143,14 +173,16 @@ public class ThreddsWorkspaceSyncServiceImpl extends RemoteServiceServlet implem
String originalToken = null; String originalToken = null;
List<ThCatalogueBean> listCtlgs = null; List<ThCatalogueBean> listCtlgs = null;
try { try {
GCubeUser user = PortalContext.getConfiguration().getCurrentUser(this.getThreadLocalRequest());
String wsScope = PortalContext.getConfiguration().getCurrentScope(this.getThreadLocalRequest()); PortalContext portalContext = PortalContext.getConfiguration();
String wsUserToken = PortalContext.getConfiguration().getCurrentUserToken(wsScope, user.getUsername()); final GCubeUser user = portalContext.getCurrentUser(this.getThreadLocalRequest());
final String wsScope = portalContext.getCurrentScope(this.getThreadLocalRequest());
final String wsUserToken = portalContext.getCurrentUserToken(wsScope, user.getUsername());
//Thread Local contexts //Thread Local contexts
originalScope = wsScope; originalScope = wsScope;
originalToken = wsUserToken; originalToken = wsUserToken;
String targetScopeUserToken = PortalContext.getConfiguration().getCurrentUserToken(targetFullScope, user.getUsername()); String targetScopeUserToken = portalContext.getCurrentUserToken(targetFullScope, user.getUsername());
listCtlgs = getSyncService().getAvailableCataloguesByToken(targetFullScope, wsUserToken, targetScopeUserToken); listCtlgs = getSyncService().getAvailableCataloguesByToken(targetFullScope, wsUserToken, targetScopeUserToken);
logger.debug("Retuning "+listCtlgs.size()+" Catalogues for scope: "+targetFullScope); logger.debug("Retuning "+listCtlgs.size()+" Catalogues for scope: "+targetFullScope);
@ -193,10 +225,10 @@ public class ThreddsWorkspaceSyncServiceImpl extends RemoteServiceServlet implem
//DEV MODE //DEV MODE
if (!isWithinPortal()){ if (!isWithinPortal()){
mapScopesRoles = new HashMap<String, GatewayRolesThredds>(); // mapScopesRoles = new HashMap<String, GatewayRolesThredds>();
mapScopesRoles.put("/gcube/devNext/NextNext", GatewayRolesThredds.DATA_MANAGER); //mapScopesRoles.put("/gcube/devsec/devVRE", GatewayRolesThredds.DATA_EDITOR);
// mapScopesRoles.put( "/gcube", GatewayRolesThredds.THREDDS_PUBLISHER); // mapScopesRoles.put( "/gcube", GatewayRolesThredds.THREDDS_PUBLISHER);
// mapScopesRoles.put( "/gcube/devNext/NextNext", GatewayRolesThredds.THREDDS_PUBLISHER); // mapScopesRoles.put( "/gcube/devNext/NextNext", GatewayRolesThredds.DATA_EDITOR);
return mapScopesRoles; return mapScopesRoles;
} }
@ -267,9 +299,9 @@ public class ThreddsWorkspaceSyncServiceImpl extends RemoteServiceServlet implem
// } // }
if(scopeType!=null){ if(scopeType!=null){
GatewayRolesThredds roles = WsUtil.getThreddsRoleFor(user, gCubeGroup); GatewayRolesThredds gatewayRole = WsUtil.getThreddsRoleFor(user, gCubeGroup);
//Adding only the scope where the user has the THREDDS_ADMIN role //Adding only the scope where the user has the THREDDS_ADMIN role
GcubeScope gcubeScope = checkDataManagerCapacityAndThreddsCatalogue(roles, gCubeGroup.getGroupName(), fullScope, groupManager, scopeType); GcubeScope gcubeScope = checkDataManagerCapacityAndThreddsCatalogue(gatewayRole, gCubeGroup.getGroupName(), fullScope, groupManager, scopeType);
if(gcubeScope!=null) { if(gcubeScope!=null) {
listOfScopes.add(gcubeScope); listOfScopes.add(gcubeScope);
} }
@ -386,18 +418,18 @@ public class ThreddsWorkspaceSyncServiceImpl extends RemoteServiceServlet implem
} }
/** // /**
* Register callback for id. // * Register callback for id.
* // *
* @param folderId the folder id // * @param folderId the folder id
* @throws Exception the exception // * @throws Exception the exception
*/ // */
public void registerCallbackForId(String folderId) throws Exception{ // public void registerCallbackForId(String folderId) throws Exception{
GCubeUser user = PortalContext.getConfiguration().getCurrentUser(this.getThreadLocalRequest()); // GCubeUser user = PortalContext.getConfiguration().getCurrentUser(this.getThreadLocalRequest());
String wsScope = PortalContext.getConfiguration().getCurrentScope(this.getThreadLocalRequest()); // String wsScope = PortalContext.getConfiguration().getCurrentScope(this.getThreadLocalRequest());
String wsUserToken = PortalContext.getConfiguration().getCurrentUserToken(wsScope, user.getUsername()); // String wsUserToken = PortalContext.getConfiguration().getCurrentUserToken(wsScope, user.getUsername());
getSyncService().registerCallbackForId(folderId, wsScope, wsUserToken); // getSyncService().registerCallbackForId(folderId, wsScope, wsUserToken);
} // }
/** /**

View File

@ -133,7 +133,8 @@ public class WsUtil {
for (GCubeGroup gCubeGroup : listOfGroups) { for (GCubeGroup gCubeGroup : listOfGroups) {
GatewayRolesThredds threddsRole = getThreddsRoleFor(user, gCubeGroup); GatewayRolesThredds threddsRole = getThreddsRoleFor(user, gCubeGroup);
if(threddsRole != null) { if(threddsRole != null) {
mapRoleByGroupSingleVre.put(gCubeGroup.getGroupName(), threddsRole); String toFullScope = groupManager.getInfrastructureScope(gCubeGroup.getGroupId());
mapRoleByGroupSingleVre.put(toFullScope, threddsRole);
} }
} }
@ -172,7 +173,7 @@ public class WsUtil {
threddsRoles.add(GatewayRolesThredds.DATA_EDITOR); threddsRoles.add(GatewayRolesThredds.DATA_EDITOR);
} }
} }
logger.info("For user: "+user.getUsername()+" in the scope: "+scope.getGroupName()+" read the role/s: " + threddsRoles); logger.info("For user: "+user.getUsername()+" in the scope: "+scope.getGroupName()+" read the role/s: " + threddsRoles);
GatewayRolesThredds toReturn = null; GatewayRolesThredds toReturn = null;