Check context on doSync

This commit is contained in:
Fabio Sinibaldi 2021-03-10 17:59:10 +01:00
parent 001390f6ac
commit 435599de5e
2 changed files with 42 additions and 31 deletions

View File

@ -13,40 +13,45 @@ import lombok.extern.slf4j.Slf4j;
public class Security { public class Security {
public static String getCurrentScope(){ public static String getCurrentScope(){
try{ try{
String token=SecurityTokenProvider.instance.get(); String token=SecurityTokenProvider.instance.get();
log.debug("Token is : "+token); log.debug("Token is : "+token);
if(token==null) throw new Exception("Security Token is null"); if(token==null) throw new Exception("Security Token is null");
AuthorizationEntry entry = authorizationService().get(token); AuthorizationEntry entry = authorizationService().get(token);
return entry.getContext(); return entry.getContext();
}catch(Exception e ){ }catch(Exception e ){
log.debug("Unable to resolve token, checking scope provider..",e); log.debug("Unable to resolve token, checking scope provider..",e);
return ScopeProvider.instance.get(); return ScopeProvider.instance.get();
}
} }
}
public static String getContext(String token) throws ObjectNotFound, Exception { public static String getContext(String token) {
log.debug("Resolving token {} ",token); try{
AuthorizationEntry entry = authorizationService().get(token); log.debug("Resolving token {} ",token);
return entry.getContext(); AuthorizationEntry entry = authorizationService().get(token);
return entry.getContext();
}catch(Exception e) {
log.warn("Unable to resolve "+token,e);
return null;
}
} }
public static String getToken() { public static String getToken() {
return SecurityTokenProvider.instance.get(); return SecurityTokenProvider.instance.get();
} }
public static String getCurrentCaller(){
try{ public static String getCurrentCaller(){
String token=SecurityTokenProvider.instance.get(); try{
log.debug("Token is : "+token); String token=SecurityTokenProvider.instance.get();
if(token==null) throw new Exception("Security Token is null"); log.debug("Token is : "+token);
AuthorizationEntry entry = authorizationService().get(token); if(token==null) throw new Exception("Security Token is null");
return entry.getClientInfo().getId(); AuthorizationEntry entry = authorizationService().get(token);
}catch(Exception e ){ return entry.getClientInfo().getId();
log.debug("Unable to resolve token, checking scope provider..",e); }catch(Exception e ){
return "Unidentified data-transfer user"; log.debug("Unable to resolve token, checking scope provider..",e);
return "Unidentified data-transfer user";
}
} }
} }
}

View File

@ -11,6 +11,7 @@ import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor; import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
import org.gcube.data.transfer.model.plugins.thredds.DataSetScan; import org.gcube.data.transfer.model.plugins.thredds.DataSetScan;
import org.gcube.data.transfer.model.plugins.thredds.ThreddsCatalog; import org.gcube.data.transfer.model.plugins.thredds.ThreddsCatalog;
import org.gcube.data.transfer.model.plugins.thredds.ThreddsInfo; import org.gcube.data.transfer.model.plugins.thredds.ThreddsInfo;
@ -139,9 +140,14 @@ public class SynchEngineImpl implements SyncEngine{
if(manager.isLocked()) throw new WorkspaceLockedException("Folder "+folderId+"is locked by an external process."); if(manager.isLocked()) throw new WorkspaceLockedException("Folder "+folderId+"is locked by an external process.");
if(!manager.isRoot()) throw new WorkspaceFolderNotRootException("Unable to launch synch operation. Folder "+folderId+" is not root configuration"); if(!manager.isRoot()) throw new WorkspaceFolderNotRootException("Unable to launch synch operation. Folder "+folderId+" is not root configuration");
//TODO check context String callerContext=Security.getCurrentScope();
//TODO set operating context log.debug("Checking context. Caller is {} ",callerContext);
// if(manager.getSynchConfiguration().get)
String configurationContext=Security.getContext(manager.getSynchConfiguration().getTargetToken());
if(!callerContext.equals(configurationContext))
throw new WorkspaceInteractionException("Cannot sync folder from context "+callerContext+". Expected context is "+configurationContext);
Process toLaunch=new Process(folderId,completionCallback); Process toLaunch=new Process(folderId,completionCallback);
localProcesses.put(folderId, toLaunch); localProcesses.put(folderId, toLaunch);