adding context switch to getConfiguration when needed
This commit is contained in:
parent
5cc52d9e3c
commit
54600fe288
|
@ -28,11 +28,12 @@ import org.gcube.vomanagement.usermanagement.model.GCubeUser;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
// TODO: Auto-generated Javadoc
|
|
||||||
/**
|
/**
|
||||||
* 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
|
||||||
*/
|
*/
|
||||||
public class SyncronizeWithThredds {
|
public class SyncronizeWithThredds {
|
||||||
|
|
||||||
|
@ -40,7 +41,7 @@ public class SyncronizeWithThredds {
|
||||||
private Logger logger = LoggerFactory.getLogger(SyncronizeWithThredds.class);
|
private Logger logger = LoggerFactory.getLogger(SyncronizeWithThredds.class);
|
||||||
|
|
||||||
/** The workspace thredds synchronize. */
|
/** The workspace thredds synchronize. */
|
||||||
private WorkspaceThreddsSynchronize workspaceThreddsSynchronize;
|
private WorkspaceThreddsSynchronize workspaceThreddsSynchronizeLib;
|
||||||
|
|
||||||
/** The Constant sdf. */
|
/** The Constant sdf. */
|
||||||
// private static final SimpleDateFormat sdf = new
|
// private static final SimpleDateFormat sdf = new
|
||||||
|
@ -54,7 +55,7 @@ public class SyncronizeWithThredds {
|
||||||
* @param httpSession the http session
|
* @param httpSession the http session
|
||||||
*/
|
*/
|
||||||
public SyncronizeWithThredds() {
|
public SyncronizeWithThredds() {
|
||||||
this.workspaceThreddsSynchronize = WorkspaceThreddsSynchronize.getInstance();
|
this.workspaceThreddsSynchronizeLib = WorkspaceThreddsSynchronize.getInstance();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -133,7 +134,7 @@ public class SyncronizeWithThredds {
|
||||||
ContainerType itemType) throws ItemNotSynched, Exception {
|
ContainerType itemType) throws ItemNotSynched, Exception {
|
||||||
|
|
||||||
setContextParameters(scope, userToken);
|
setContextParameters(scope, userToken);
|
||||||
return workspaceThreddsSynchronize.isItemSynched(folderId, itemProperties, itemType);
|
return workspaceThreddsSynchronizeLib.isItemSynched(folderId, itemProperties, itemType);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -142,25 +143,44 @@ public class SyncronizeWithThredds {
|
||||||
* @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 the
|
||||||
* {@link SyncEngine#check(String, boolean)} but it is time
|
* {@link SyncEngine#check(String, boolean)} but it is time
|
||||||
* consuming. Otherwise it callas the
|
* consuming. Otherwise it calls the
|
||||||
* {@link SyncEngine#getConfig(String)} without sync status
|
* {@link SyncEngine#getConfig(String)} without sync status
|
||||||
* @param scope the scope
|
* @param httpRequest the http request
|
||||||
* @param userToken the user token
|
* @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, String scope, String userToken)
|
public ThSyncFolderDescriptor getConfiguration(String folderId, boolean loadStatus, HttpServletRequest httpRequest, GCubeUser user)
|
||||||
throws ItemNotSynched, Exception {
|
throws ItemNotSynched, Exception {
|
||||||
|
|
||||||
ThSyncFolderDescriptor config = null;
|
ThSyncFolderDescriptor config = null;
|
||||||
|
String wsScope = PortalContext.getConfiguration().getCurrentScope(httpRequest);
|
||||||
|
String wsUserToken = PortalContext.getConfiguration().getCurrentUserToken(wsScope, user.getUsername());
|
||||||
|
String originalScope = wsScope;
|
||||||
|
String originalToken = wsUserToken;
|
||||||
|
String previousUmaToken = null;
|
||||||
|
String targetScope = null;
|
||||||
try {
|
try {
|
||||||
setContextParameters(scope, userToken);
|
|
||||||
|
setContextParameters(wsScope, wsUserToken);
|
||||||
|
|
||||||
if (loadStatus) {
|
if (loadStatus) {
|
||||||
config = workspaceThreddsSynchronize.checkItemSynched(folderId);
|
|
||||||
|
config = workspaceThreddsSynchronizeLib.getConfiguration(folderId);
|
||||||
|
// context switch for UMA token
|
||||||
|
targetScope = config.getConfiguration().getTargetContext();
|
||||||
|
previousUmaToken = changeContextForUMA(httpRequest, user, targetScope);
|
||||||
|
|
||||||
|
// context switch for gcube-token and scope
|
||||||
|
// getting token into target scope
|
||||||
|
String targetScopeUserToken = PortalContext.getConfiguration().getCurrentUserToken(targetScope,
|
||||||
|
user.getUsername());
|
||||||
|
setContextParameters(targetScope, targetScopeUserToken);
|
||||||
|
|
||||||
|
config = workspaceThreddsSynchronizeLib.checkItemSynched(folderId);
|
||||||
} else {
|
} else {
|
||||||
config = workspaceThreddsSynchronize.getConfiguration(folderId);
|
config = workspaceThreddsSynchronizeLib.getConfiguration(folderId);
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (WorkspaceNotSynchedException e) {
|
} catch (WorkspaceNotSynchedException e) {
|
||||||
|
@ -171,6 +191,22 @@ public class SyncronizeWithThredds {
|
||||||
} 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 {
|
||||||
|
|
||||||
|
if(previousUmaToken!=null) {
|
||||||
|
// resetting UMA token in the WS scope
|
||||||
|
setContextForUMA(previousUmaToken);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (originalScope != null && targetScope!=null && originalScope.compareTo(targetScope) != 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return config;
|
return config;
|
||||||
|
@ -208,7 +244,7 @@ public class SyncronizeWithThredds {
|
||||||
setContextParameters(targetScope, targetScopeUserToken);
|
setContextParameters(targetScope, targetScopeUserToken);
|
||||||
|
|
||||||
// calling the engine
|
// calling the engine
|
||||||
listCatalogues = workspaceThreddsSynchronize.getAvailableCatalogues();
|
listCatalogues = workspaceThreddsSynchronizeLib.getAvailableCatalogues();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
logger.error("Error on getting available Catalogues in the scope: " + targetScope, e);
|
logger.error("Error on getting available Catalogues in the scope: " + targetScope, e);
|
||||||
|
|
||||||
|
@ -276,7 +312,7 @@ public class SyncronizeWithThredds {
|
||||||
user.getUsername());
|
user.getUsername());
|
||||||
setContextParameters(targetScope, targetScopeUserToken);
|
setContextParameters(targetScope, targetScopeUserToken);
|
||||||
|
|
||||||
ThSyncFolderDescriptor folder = workspaceThreddsSynchronize.checkItemSynched(folderId);
|
ThSyncFolderDescriptor folder = workspaceThreddsSynchronizeLib.checkItemSynched(folderId);
|
||||||
|
|
||||||
} catch (ItemNotSynched e) {
|
} catch (ItemNotSynched e) {
|
||||||
firstSync = true;
|
firstSync = true;
|
||||||
|
@ -289,11 +325,11 @@ public class SyncronizeWithThredds {
|
||||||
|
|
||||||
if (firstSync) {
|
if (firstSync) {
|
||||||
logger.info("First sync setting the synchronized folder configuration: " + thConfig);
|
logger.info("First sync setting the synchronized folder configuration: " + thConfig);
|
||||||
workspaceThreddsSynchronize.setSynchronizedFolder(thConfig, folderId);
|
workspaceThreddsSynchronizeLib.setSynchronizedFolder(thConfig, folderId);
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.info("Calling do sync on folder id: " + folderId);
|
logger.info("Calling do sync on folder id: " + folderId);
|
||||||
return workspaceThreddsSynchronize.doSync(folderId);
|
return workspaceThreddsSynchronizeLib.doSync(folderId);
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
logger.error("Error on do sync: ", e);
|
logger.error("Error on do sync: ", e);
|
||||||
|
@ -362,7 +398,7 @@ public class SyncronizeWithThredds {
|
||||||
user.getUsername());
|
user.getUsername());
|
||||||
setContextParameters(targetScope, targetScopeUserToken);
|
setContextParameters(targetScope, targetScopeUserToken);
|
||||||
|
|
||||||
return workspaceThreddsSynchronize.doUnSync(folderId, deleteRemoteContent);
|
return workspaceThreddsSynchronizeLib.doUnSync(folderId, deleteRemoteContent);
|
||||||
|
|
||||||
} catch (ItemNotSynched e) {
|
} catch (ItemNotSynched e) {
|
||||||
throw new Exception("The item with id: " + folderId + " is not synched");
|
throw new Exception("The item with id: " + folderId + " is not synched");
|
||||||
|
@ -401,7 +437,7 @@ public class SyncronizeWithThredds {
|
||||||
throws ItemNotSynched, Exception {
|
throws ItemNotSynched, Exception {
|
||||||
|
|
||||||
setContextParameters(scope, userToken);
|
setContextParameters(scope, userToken);
|
||||||
return workspaceThreddsSynchronize.monitorSyncStatus(itemId);
|
return workspaceThreddsSynchronizeLib.monitorSyncStatus(itemId);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -414,7 +450,7 @@ public class SyncronizeWithThredds {
|
||||||
*/
|
*/
|
||||||
protected void registerCallbackForId(String folderId, String scope, String userToken) throws Exception {
|
protected void registerCallbackForId(String folderId, String scope, String userToken) throws Exception {
|
||||||
setContextParameters(scope, userToken);
|
setContextParameters(scope, userToken);
|
||||||
workspaceThreddsSynchronize.registerCallbackForId(folderId);
|
workspaceThreddsSynchronizeLib.registerCallbackForId(folderId);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -130,11 +130,7 @@ public class ThreddsWorkspaceSyncServiceImpl extends RemoteServiceServlet implem
|
||||||
|
|
||||||
try {
|
try {
|
||||||
GCubeUser user = PortalContext.getConfiguration().getCurrentUser(this.getThreadLocalRequest());
|
GCubeUser user = PortalContext.getConfiguration().getCurrentUser(this.getThreadLocalRequest());
|
||||||
String wsScope = PortalContext.getConfiguration().getCurrentScope(this.getThreadLocalRequest());
|
ThSyncFolderDescriptor theConfig = getSyncService().getConfiguration(folderId, loadStatus, this.getThreadLocalRequest(), user);
|
||||||
String wsUserToken = PortalContext.getConfiguration().getCurrentUserToken(wsScope, user.getUsername());
|
|
||||||
|
|
||||||
ThSyncFolderDescriptor theConfig = getSyncService().getConfiguration(folderId, loadStatus, wsScope,
|
|
||||||
wsUserToken);
|
|
||||||
|
|
||||||
if (theConfig != null) {
|
if (theConfig != null) {
|
||||||
logger.info("Folder id: " + folderId + " is synched");
|
logger.info("Folder id: " + folderId + " is synched");
|
||||||
|
@ -208,9 +204,7 @@ public class ThreddsWorkspaceSyncServiceImpl extends RemoteServiceServlet implem
|
||||||
|
|
||||||
try {
|
try {
|
||||||
GCubeUser user = PortalContext.getConfiguration().getCurrentUser(this.getThreadLocalRequest());
|
GCubeUser user = PortalContext.getConfiguration().getCurrentUser(this.getThreadLocalRequest());
|
||||||
String wsScope = PortalContext.getConfiguration().getCurrentScope(this.getThreadLocalRequest());
|
ThSyncFolderDescriptor foldeDesr = getSyncService().getConfiguration(folderId, false, this.getThreadLocalRequest(), user);
|
||||||
String wsUserToken = PortalContext.getConfiguration().getCurrentUserToken(wsScope, user.getUsername());
|
|
||||||
ThSyncFolderDescriptor foldeDesr = getSyncService().getConfiguration(folderId, false, wsScope, wsUserToken);
|
|
||||||
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) {
|
||||||
|
|
Loading…
Reference in New Issue