starting work on Feature #20979

feature_20979
Francesco Mangiacrapa 3 years ago
parent 660d869ab5
commit ec3c24f78b

@ -3,10 +3,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.3.0-SNAPSHOT] - 2021-03-03
## [v1.3.0-SNAPSHOT] - 2021-03-16
[#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
[#19676] Migrated to git/jenkins

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

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

@ -2,7 +2,6 @@ package org.gcube.portlets.widgets.wsthreddssync.server;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
@ -100,31 +99,62 @@ public class ThreddsWorkspaceSyncServiceImpl extends RemoteServiceServlet implem
public ThSyncStatus doSyncFolder(final String folderId, WsThreddsSynchFolderConfiguration clientConfig) throws Exception{
logger.info("Performing doSyncFolder method on id: "+folderId +", config: "+clientConfig);
String originalScope = null;
String originalToken = null;
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;
ThSynchFolderConfiguration config = 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);
logger.debug("Creating server config "+config);
}
/* Commented because Feature #20979
logger.info("Calling doSyncFolder on folderId: "+folderId +", config: "+config);
String wsScope = PortalContext.getConfiguration().getCurrentScope(this.getThreadLocalRequest());
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);
return status;
}catch (Exception e) {
logger.error("Do sync Folder error: ",e);
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.
@ -143,14 +173,16 @@ public class ThreddsWorkspaceSyncServiceImpl extends RemoteServiceServlet implem
String originalToken = null;
List<ThCatalogueBean> listCtlgs = null;
try {
GCubeUser user = PortalContext.getConfiguration().getCurrentUser(this.getThreadLocalRequest());
String wsScope = PortalContext.getConfiguration().getCurrentScope(this.getThreadLocalRequest());
String wsUserToken = PortalContext.getConfiguration().getCurrentUserToken(wsScope, user.getUsername());
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 = PortalContext.getConfiguration().getCurrentUserToken(targetFullScope, user.getUsername());
String targetScopeUserToken = portalContext.getCurrentUserToken(targetFullScope, user.getUsername());
listCtlgs = getSyncService().getAvailableCataloguesByToken(targetFullScope, wsUserToken, targetScopeUserToken);
logger.debug("Retuning "+listCtlgs.size()+" Catalogues for scope: "+targetFullScope);
@ -193,10 +225,10 @@ public class ThreddsWorkspaceSyncServiceImpl extends RemoteServiceServlet implem
//DEV MODE
if (!isWithinPortal()){
mapScopesRoles = new HashMap<String, GatewayRolesThredds>();
mapScopesRoles.put("/gcube/devNext/NextNext", GatewayRolesThredds.DATA_MANAGER);
// mapScopesRoles = new HashMap<String, GatewayRolesThredds>();
//mapScopesRoles.put("/gcube/devsec/devVRE", GatewayRolesThredds.DATA_EDITOR);
// mapScopesRoles.put( "/gcube", GatewayRolesThredds.THREDDS_PUBLISHER);
// mapScopesRoles.put( "/gcube/devNext/NextNext", GatewayRolesThredds.THREDDS_PUBLISHER);
// mapScopesRoles.put( "/gcube/devNext/NextNext", GatewayRolesThredds.DATA_EDITOR);
return mapScopesRoles;
}
@ -267,9 +299,9 @@ public class ThreddsWorkspaceSyncServiceImpl extends RemoteServiceServlet implem
// }
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
GcubeScope gcubeScope = checkDataManagerCapacityAndThreddsCatalogue(roles, gCubeGroup.getGroupName(), fullScope, groupManager, scopeType);
GcubeScope gcubeScope = checkDataManagerCapacityAndThreddsCatalogue(gatewayRole, gCubeGroup.getGroupName(), fullScope, groupManager, scopeType);
if(gcubeScope!=null) {
listOfScopes.add(gcubeScope);
}
@ -386,18 +418,18 @@ public class ThreddsWorkspaceSyncServiceImpl extends RemoteServiceServlet implem
}
/**
* Register callback for id.
*
* @param folderId the folder id
* @throws Exception the exception
*/
public void registerCallbackForId(String folderId) throws Exception{
GCubeUser user = PortalContext.getConfiguration().getCurrentUser(this.getThreadLocalRequest());
String wsScope = PortalContext.getConfiguration().getCurrentScope(this.getThreadLocalRequest());
String wsUserToken = PortalContext.getConfiguration().getCurrentUserToken(wsScope, user.getUsername());
getSyncService().registerCallbackForId(folderId, wsScope, wsUserToken);
}
// /**
// * Register callback for id.
// *
// * @param folderId the folder id
// * @throws Exception the exception
// */
// public void registerCallbackForId(String folderId) throws Exception{
// GCubeUser user = PortalContext.getConfiguration().getCurrentUser(this.getThreadLocalRequest());
// String wsScope = PortalContext.getConfiguration().getCurrentScope(this.getThreadLocalRequest());
// String wsUserToken = PortalContext.getConfiguration().getCurrentUserToken(wsScope, user.getUsername());
// getSyncService().registerCallbackForId(folderId, wsScope, wsUserToken);
// }
/**

@ -133,7 +133,8 @@ public class WsUtil {
for (GCubeGroup gCubeGroup : listOfGroups) {
GatewayRolesThredds threddsRole = getThreddsRoleFor(user, gCubeGroup);
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);
}
}
logger.info("For user: "+user.getUsername()+" in the scope: "+scope.getGroupName()+" read the role/s: " + threddsRoles);
GatewayRolesThredds toReturn = null;

Loading…
Cancel
Save