added checks and improved logs

This commit is contained in:
Francesco Mangiacrapa 2021-03-08 11:52:41 +01:00
parent f0d4347266
commit a342fa4cb7
3 changed files with 46 additions and 18 deletions

View File

@ -56,7 +56,7 @@ public class SyncronizeWithThredds {
* @param userToken the user token
*/
private void setContextParameters(String scope, String userToken) {
logger.debug("Setting context parameters, scope: "+scope +", user token: "+userToken);
logger.debug("Setting context parameters with scope: "+scope +", user token: "+userToken.substring(0,10)+"-MASKED-TOKEN");
ScopeProvider.instance.set(scope);
SecurityTokenProvider.instance.set(userToken);
}
@ -170,7 +170,6 @@ public class SyncronizeWithThredds {
* @throws Exception the exception
*/
public ThSyncFolderDescriptor checkItemSynched(String folderId, String scope, String userToken) throws ItemNotSynched, WorkspaceFolderLocked, Exception{
setContextParameters(scope, userToken);
return workspaceThreddsSynchronize.checkItemSynched(folderId);
}

View File

@ -7,7 +7,9 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
import org.gcube.common.portal.PortalContext;
import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.portal.wssynclibrary.shared.ItemNotSynched;
import org.gcube.portal.wssynclibrary.shared.WorkspaceFolderLocked;
import org.gcube.portal.wssynclibrary.shared.thredds.Sync_Status;
@ -123,29 +125,51 @@ public class ThreddsWorkspaceSyncServiceImpl extends RemoteServiceServlet implem
}
/**
* Gets the available catalogues for scope.
* Gets the available THREDDS catalogues for target scope.
*
* @param scope the scope
* @param targetScope the target scope
* @return the available catalogues for scope
* @throws Exception the exception
*/
@Override
public List<ThCatalogueBean> getAvailableCataloguesForScope(String scope) throws Exception {
public List<ThCatalogueBean> getAvailableCataloguesForScope(String targetScope) throws Exception {
if(scope==null)
if(targetScope==null)
throw new Exception("Invalid scope null");
GCubeUser user = PortalContext.getConfiguration().getCurrentUser(this.getThreadLocalRequest());
String wsScope = PortalContext.getConfiguration().getCurrentScope(this.getThreadLocalRequest());
String wsUserToken = PortalContext.getConfiguration().getCurrentUserToken(wsScope, user.getUsername());
String targetScopeUserToken = PortalContext.getConfiguration().getCurrentUserToken(scope, user.getUsername());
List<ThCatalogueBean> listCtlgs = getSyncService().getAvailableCataloguesByToken(scope, wsUserToken, targetScopeUserToken);
logger.debug("Retuning "+listCtlgs.size()+" Catalogues for scope: "+scope);
if(logger.isDebugEnabled()){
for (ThCatalogueBean thCatalogueBean : listCtlgs) {
logger.debug(thCatalogueBean.toString());
String originalScope = null;
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());
//Thread Local contexts
originalScope = wsScope;
originalToken = wsUserToken;
String targetScopeUserToken = PortalContext.getConfiguration().getCurrentUserToken(targetScope, user.getUsername());
listCtlgs = getSyncService().getAvailableCataloguesByToken(targetScope, wsUserToken, targetScopeUserToken);
logger.debug("Retuning "+listCtlgs.size()+" Catalogues for scope: "+targetScope);
if(logger.isDebugEnabled()){
for (ThCatalogueBean thCatalogueBean : listCtlgs) {
logger.debug(thCatalogueBean.toString());
}
}
}catch (Exception e) {
logger.error("Error on checking available Catalogue in the scope: "+targetScope, e);
}finally {
if(originalScope!=null && originalScope.compareTo(targetScope)!=0) {
logger.info("Resetting to original WS context the scope: "+originalScope);
ScopeProvider.instance.set(targetScope);
if(originalToken!=null) {
logger.info("Resetting to original WS context the user token: "+originalToken.substring(0,10)+"-MASKED-TOKEN");
SecurityTokenProvider.instance.set(originalToken);
}
}
}

View File

@ -154,7 +154,12 @@ public class WsUtil {
* @return the thredds role for
*/
public static GatewayRolesThredds getThreddsRoleFor(GCubeUser user, GCubeGroup scope){
logger.info("called getThreddsRoleFor user: "+user+", in the scope: "+scope.getGroupName());
if(user==null || scope==null) {
logger.warn("called getThreddsRoleFor with invalid parameter user: "+user+", in the scope: "+scope, ", returning null");
return null;
}
logger.info("called getThreddsRoleFor user: "+user.getUsername()+", in the scope: "+scope.getGroupName());
try {
RoleManager roleManager = new LiferayRoleManager();
List<GCubeRole> roles = roleManager.listRolesByUserAndGroup(user.getUserId(), scope.getGroupId());
@ -176,7 +181,7 @@ public class WsUtil {
else if (threddsRoles.contains(GatewayRolesThredds.DATA_EDITOR))
toReturn = GatewayRolesThredds.DATA_EDITOR;
logger.info("returning role: " + toReturn);
logger.info("returning highest role: " + toReturn);
return toReturn;
}catch (UserRetrievalFault | GroupRetrievalFault e) {
logger.error("An error occurred during getVreRoleForUser: "+user, e);