|
|
|
@ -5,8 +5,14 @@ package org.gcube.portlets.widgets.wsthreddssync.server;
|
|
|
|
|
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
|
|
|
|
|
|
|
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.scope.api.ScopeProvider;
|
|
|
|
|
import org.gcube.oidc.rest.JWTToken;
|
|
|
|
|
import org.gcube.portal.oidc.lr62.OIDCUmaUtil;
|
|
|
|
|
import org.gcube.portal.wssynclibrary.shared.ItemNotSynched;
|
|
|
|
|
import org.gcube.portal.wssynclibrary.shared.WorkspaceFolderLocked;
|
|
|
|
|
import org.gcube.portal.wssynclibrary.shared.thredds.Sync_Status;
|
|
|
|
@ -15,9 +21,11 @@ import org.gcube.portal.wssynclibrary.shared.thredds.ThSyncFolderDescriptor;
|
|
|
|
|
import org.gcube.portal.wssynclibrary.shared.thredds.ThSyncStatus;
|
|
|
|
|
import org.gcube.portal.wssynclibrary.shared.thredds.ThSynchFolderConfiguration;
|
|
|
|
|
import org.gcube.portal.wssynclibrary.thredds.WorkspaceThreddsSynchronize;
|
|
|
|
|
import org.gcube.vomanagement.usermanagement.model.GCubeUser;
|
|
|
|
|
import org.slf4j.Logger;
|
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
|
|
|
|
|
// TODO: Auto-generated Javadoc
|
|
|
|
|
/**
|
|
|
|
|
* The Class SyncronizeWithThredds.
|
|
|
|
|
*
|
|
|
|
@ -61,6 +69,54 @@ public class SyncronizeWithThredds {
|
|
|
|
|
SecurityTokenProvider.instance.set(userToken);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Change context for UMA.
|
|
|
|
|
*
|
|
|
|
|
* @param httpRequest the http request
|
|
|
|
|
* @param user the user
|
|
|
|
|
* @param targetScope the target scope
|
|
|
|
|
* @return the string representing the previous UMA Token read from {@link UmaJWTProvider#get()}
|
|
|
|
|
*/
|
|
|
|
|
private String changeContextForUMA(HttpServletRequest httpRequest, GCubeUser user, String targetScope) {
|
|
|
|
|
logger.debug("Setting UMA context with target scope: "+targetScope +", user: "+user.getUsername());
|
|
|
|
|
String previousUMAToken = null;
|
|
|
|
|
try {
|
|
|
|
|
previousUMAToken=UmaJWTProvider.instance.get();
|
|
|
|
|
JWTToken umaToken = OIDCUmaUtil.getUMAToken(httpRequest, user.getUsername(), targetScope);
|
|
|
|
|
setContextForUMA(umaToken.getRaw());
|
|
|
|
|
}catch (Exception e) {
|
|
|
|
|
logger.warn("Error on set context for UMA: ",e);
|
|
|
|
|
if(previousUMAToken!=null) {
|
|
|
|
|
logger.info("Setting previous UMA Token: "+previousUMAToken.substring(0,10)+"-MASKED-TOKEN");
|
|
|
|
|
setContextForUMA(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");
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Do sync folder.
|
|
|
|
@ -225,19 +281,57 @@ public class SyncronizeWithThredds {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Gets the available catalogues by token.
|
|
|
|
|
* Gets the available catalogues.
|
|
|
|
|
*
|
|
|
|
|
* @param scope the scope
|
|
|
|
|
* @param userToken the user token
|
|
|
|
|
* @param targetToken the target token
|
|
|
|
|
* @return the available catalogues by token
|
|
|
|
|
* @param httpRequest the http request
|
|
|
|
|
* @param user the user
|
|
|
|
|
* @param targetScope the target scope
|
|
|
|
|
* @return the available catalogues
|
|
|
|
|
* @throws Exception the exception
|
|
|
|
|
*/
|
|
|
|
|
public List<ThCatalogueBean> getAvailableCataloguesByToken(String scope, String userToken, String targetToken) throws Exception {
|
|
|
|
|
setContextParameters(scope, userToken);
|
|
|
|
|
return workspaceThreddsSynchronize.getAvailableCataloguesByToken(targetToken);
|
|
|
|
|
public List<ThCatalogueBean> getAvailableCatalogues(HttpServletRequest httpRequest, GCubeUser user,
|
|
|
|
|
String targetScope) throws Exception {
|
|
|
|
|
String originalScope = null;
|
|
|
|
|
String originalToken = null;
|
|
|
|
|
String previousUmaToken = null;
|
|
|
|
|
List<ThCatalogueBean> listCatalogues = null;
|
|
|
|
|
try {
|
|
|
|
|
// context switch for Uma token
|
|
|
|
|
previousUmaToken = changeContextForUMA(httpRequest, user, targetScope);
|
|
|
|
|
|
|
|
|
|
// context switch for gcube-token and scope
|
|
|
|
|
PortalContext pConfig = PortalContext.getConfiguration();
|
|
|
|
|
String wsScope = pConfig.getCurrentScope(httpRequest);
|
|
|
|
|
String wsUserToken = pConfig.getCurrentUserToken(wsScope, user.getUsername());
|
|
|
|
|
// Thread Local contexts
|
|
|
|
|
originalScope = wsScope;
|
|
|
|
|
originalToken = wsUserToken;
|
|
|
|
|
// getting token into target scope
|
|
|
|
|
String targetScopeUserToken = PortalContext.getConfiguration().getCurrentUserToken(targetScope,
|
|
|
|
|
user.getUsername());
|
|
|
|
|
setContextParameters(targetScope, targetScopeUserToken);
|
|
|
|
|
|
|
|
|
|
// calling the engine
|
|
|
|
|
listCatalogues = workspaceThreddsSynchronize.getAvailableCatalogues();
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
logger.error("Error on getting available Catalogues in the scope: " + targetScope, e);
|
|
|
|
|
} finally {
|
|
|
|
|
|
|
|
|
|
// resetting UMA token in the WS scope
|
|
|
|
|
setContextForUMA(previousUmaToken);
|
|
|
|
|
|
|
|
|
|
if (originalScope != 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 listCatalogues;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|