This commit is contained in:
Fabio Sinibaldi 2021-03-10 15:49:11 +01:00
parent aa5147bb48
commit 37ca2485af
11 changed files with 144 additions and 56 deletions

View File

@ -1,36 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" output="target/classes" path="src/main/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/classes"/>
</classpath>

View File

@ -1,5 +0,0 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
org.eclipse.jdt.core.compiler.source=1.8

View File

@ -2,7 +2,9 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
# Changelog for org.gcube.spatial.data.sdi-service # Changelog for org.gcube.spatial.data.sdi-service
## [v1.4.2-SNAPSHOT] 2020-05-15 ## [v1.0.0-SNAPSHOT] 2020-05-15
### Fixes ### Fixes

View File

@ -8,7 +8,7 @@
</parent> </parent>
<groupId>org.gcube.spatial.data</groupId> <groupId>org.gcube.spatial.data</groupId>
<artifactId>ws-thredds</artifactId> <artifactId>ws-thredds</artifactId>
<version>0.2.3-SNAPSHOT</version> <version>1.0.0-SNAPSHOT</version>
<name>ws-thredds</name> <name>ws-thredds</name>
<description>prototype of WS integration with data-transfer for Thredds pubblication</description> <description>prototype of WS integration with data-transfer for Thredds pubblication</description>

View File

@ -59,14 +59,15 @@ public class Process {
private CompletionCallback callback=null; private CompletionCallback callback=null;
public Process(String folderId,CompletionCallback callback) throws WorkspaceInteractionException, InternalException { public Process(String folderId,CompletionCallback callback) throws WorkspaceInteractionException, InternalException {
log.debug("Created Process with id {} ",processId); String operator=Security.getToken();
log.debug("Created Process with id {}, operator {} ",processId,operator);
// this.folderId=folderId; // this.folderId=folderId;
manager=new WorkspaceFolderManager(folderId); manager=new WorkspaceFolderManager(folderId);
manager.lock(processId); manager.lock(processId);
SynchFolderConfiguration folderConfig=manager.getSynchConfiguration(); SynchFolderConfiguration folderConfig=manager.getSynchConfiguration();
try { try {
descriptor=new ProcessDescriptor(folderId, manager.getTheFolder().get().getPath(),System.currentTimeMillis(),processId,folderConfig); descriptor=new ProcessDescriptor(folderId, manager.getTheFolder().get().getPath(),System.currentTimeMillis(),processId,operator,folderConfig);
}catch(Exception e) { }catch(Exception e) {
throw new WorkspaceInteractionException("Unable to read path from folder "+folderId,e); throw new WorkspaceInteractionException("Unable to read path from folder "+folderId,e);
} }
@ -225,7 +226,7 @@ public class Process {
} }
String relativePath=toScanFolder.get().getMetadata().getMap().get(Constants.WorkspaceProperties.REMOTE_PATH)+""; String relativePath=toScanFolder.get().getMetadata().getMap().get(Constants.WorkspaceProperties.REMOTE_PATH)+"";
ThreddsController folderController=new ThreddsController(relativePath,config.getTargetToken()); ThreddsController folderController=new ThreddsController(relativePath,ownerProcess.getDescriptor().getOperator());
RemoteFileDescriptor folderDesc=null; RemoteFileDescriptor folderDesc=null;
try{ try{
@ -305,7 +306,7 @@ public class Process {
}catch(ItemNotFoundException e) { }catch(ItemNotFoundException e) {
log.info("Creating folder {} under {} ",item,folderPath); log.info("Creating folder {} under {} ",item,folderPath);
folder=toScanFolder.newFolder(item, "Imported from thredds"); folder=toScanFolder.newFolder(item, "Imported from thredds");
WorkspaceUtils.initProperties(folder,relativePath+"/"+item , config.getFilter(), config.getTargetToken(),config.getToCreateCatalogName(),config.getValidateMetadata(),config.getRootFolderId()); WorkspaceUtils.initProperties(folder,relativePath+"/"+item , config.getFilter(), ownerProcess.getDescriptor().getOperator(),config.getToCreateCatalogName(),config.getValidateMetadata(),config.getRootFolderId());
generateRequests(ownerProcess, service, folder); generateRequests(ownerProcess, service, folder);
} }

View File

@ -14,6 +14,8 @@ public class ProcessDescriptor implements Cloneable{
private long launchTime; private long launchTime;
private String processId; private String processId;
private String operator;
private SynchFolderConfiguration synchConfiguration; private SynchFolderConfiguration synchConfiguration;
@Override @Override

View File

@ -0,0 +1,52 @@
package org.gcube.usecases.ws.thredds.engine.impl;
import static org.gcube.common.authorization.client.Constants.authorizationService;
import org.gcube.common.authorization.client.exceptions.ObjectNotFound;
import org.gcube.common.authorization.library.AuthorizationEntry;
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
import org.gcube.common.scope.api.ScopeProvider;
import lombok.extern.slf4j.Slf4j;
@Slf4j
public class Security {
public static String getCurrentScope(){
try{
String token=SecurityTokenProvider.instance.get();
log.debug("Token is : "+token);
if(token==null) throw new Exception("Security Token is null");
AuthorizationEntry entry = authorizationService().get(token);
return entry.getContext();
}catch(Exception e ){
log.debug("Unable to resolve token, checking scope provider..",e);
return ScopeProvider.instance.get();
}
}
public static String getContext(String token) throws ObjectNotFound, Exception {
log.debug("Resolving token {} ",token);
AuthorizationEntry entry = authorizationService().get(token);
return entry.getContext();
}
public static String getToken() {
return SecurityTokenProvider.instance.get();
}
public static String getCurrentCaller(){
try{
String token=SecurityTokenProvider.instance.get();
log.debug("Token is : "+token);
if(token==null) throw new Exception("Security Token is null");
AuthorizationEntry entry = authorizationService().get(token);
return entry.getClientInfo().getId();
}catch(Exception e ){
log.debug("Unable to resolve token, checking scope provider..",e);
return "Unidentified data-transfer user";
}
}
}

View File

@ -138,6 +138,11 @@ public class SynchEngineImpl implements SyncEngine{
if (!manager.isSynched()) throw new WorkspaceNotSynchedException("Folder "+folderId+" is not configured for synchronization."); if (!manager.isSynched()) throw new WorkspaceNotSynchedException("Folder "+folderId+" is not configured for synchronization.");
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
//TODO set operating context
// if(manager.getSynchConfiguration().get)
Process toLaunch=new Process(folderId,completionCallback); Process toLaunch=new Process(folderId,completionCallback);
localProcesses.put(folderId, toLaunch); localProcesses.put(folderId, toLaunch);
initializationExecutor.submit(new ProcessInitializationThread(toLaunch,synchronizationExecutor)); initializationExecutor.submit(new ProcessInitializationThread(toLaunch,synchronizationExecutor));

View File

@ -51,9 +51,27 @@ public class WorkspaceFolderManager {
private StorageHubClient sc; private StorageHubClient sc;
private String operator=null;
private String getToken() {
if(operator==null) {
log.warn("******************Using config operator**********");
return config.getTargetToken();
}
else return operator;
}
public WorkspaceFolderManager(String folderId) throws WorkspaceInteractionException { public WorkspaceFolderManager(String folderId) throws WorkspaceInteractionException {
try{ try{
// ws = HomeLibrary.getHomeManagerFactory().getHomeManager().getHome().getWorkspace(); // ws = HomeLibrary.getHomeManagerFactory().getHomeManager().getHome().getWorkspace();
String operator=Security.getToken();
log.debug("Setting operator "+operator);
this.operator=operator;
sc=WorkspaceUtils.getClient(); sc=WorkspaceUtils.getClient();
theFolder=sc.open(folderId).asFolder(); theFolder=sc.open(folderId).asFolder();
this.folderId=folderId; this.folderId=folderId;
@ -70,7 +88,7 @@ public class WorkspaceFolderManager {
public ThreddsController getThreddsController() throws WorkspaceNotSynchedException, WorkspaceInteractionException, InternalException { public ThreddsController getThreddsController() throws WorkspaceNotSynchedException, WorkspaceInteractionException, InternalException {
if(threddsController==null) { if(threddsController==null) {
SynchFolderConfiguration config=getSynchConfiguration(); SynchFolderConfiguration config=getSynchConfiguration();
threddsController=new ThreddsController(config.getRemotePath(),config.getTargetToken()); threddsController=new ThreddsController(config.getRemotePath(),getToken());
} }
return threddsController; return threddsController;
} }
@ -79,7 +97,7 @@ public class WorkspaceFolderManager {
try { try {
FolderContainer root=sc.open(getSynchConfiguration().getRootFolderId()).asFolder(); FolderContainer root=sc.open(getSynchConfiguration().getRootFolderId()).asFolder();
SynchFolderConfiguration rootConfig=WorkspaceUtils.loadConfiguration(root); SynchFolderConfiguration rootConfig=WorkspaceUtils.loadConfiguration(root);
return new ThreddsController(rootConfig.getRemotePath(),rootConfig.getTargetToken()); return new ThreddsController(rootConfig.getRemotePath(),getToken());
}catch(StorageHubException e) { }catch(StorageHubException e) {
throw new WorkspaceInteractionException(e); throw new WorkspaceInteractionException(e);
} }
@ -116,7 +134,7 @@ public class WorkspaceFolderManager {
SynchFolderConfiguration config=getSynchConfiguration(); SynchFolderConfiguration config=getSynchConfiguration();
try{ try{
checkFolder(theFolder,recursively,config,null,theFolder.getId(),WorkspaceUtils.safelyGetLastUpdate(theFolder.get())); checkFolder(theFolder,recursively,config,null,theFolder.getId(),WorkspaceUtils.safelyGetLastUpdate(theFolder.get()),getToken());
return new SyncFolderDescriptor(this.folderId,this.theFolder.get().getPath(),config); return new SyncFolderDescriptor(this.folderId,this.theFolder.get().getPath(),config);
}catch(StorageHubException e) { }catch(StorageHubException e) {
throw new WorkspaceInteractionException(e); throw new WorkspaceInteractionException(e);
@ -151,7 +169,7 @@ public class WorkspaceFolderManager {
try { try {
String catalogName=toSet.getToCreateCatalogName(); String catalogName=toSet.getToCreateCatalogName();
ThreddsController controller= new ThreddsController(toSet.getRemotePath(),toSet.getTargetToken()); ThreddsController controller= new ThreddsController(toSet.getRemotePath(),getToken());
if(!controller.existsThreddsFile(null)) { if(!controller.existsThreddsFile(null)) {
log.info("Folder not found, creating it.."); log.info("Folder not found, creating it..");
controller.createEmptyFolder(null); controller.createEmptyFolder(null);
@ -241,7 +259,7 @@ public class WorkspaceFolderManager {
private static void checkFolder(FolderContainer folder,boolean recursive, SynchFolderConfiguration rootConfig, String relativePathFromRootFolder, String rootFolderId,Date lastUpdatedRoutine) throws StorageHubException, InternalException { private static void checkFolder(FolderContainer folder,boolean recursive, SynchFolderConfiguration rootConfig, String relativePathFromRootFolder, String rootFolderId,Date lastUpdatedRoutine, String toUseToken) throws StorageHubException, InternalException {
// Check folder configuration // Check folder configuration
log.trace("Checking folder {} ",folder.get().getPath()); log.trace("Checking folder {} ",folder.get().getPath());
log.debug("Configuration is {}, relativePath is {} ",rootConfig,relativePathFromRootFolder); log.debug("Configuration is {}, relativePath is {} ",rootConfig,relativePathFromRootFolder);
@ -252,7 +270,7 @@ public class WorkspaceFolderManager {
ThreddsController controller=new ThreddsController(currentRemotePath, rootConfig.getTargetToken()); ThreddsController controller=new ThreddsController(currentRemotePath, toUseToken);
HashSet<String> currentFolderExistingItem=new HashSet<String>(); HashSet<String> currentFolderExistingItem=new HashSet<String>();
@ -269,7 +287,7 @@ public class WorkspaceFolderManager {
String itemRemotePath=currentRemotePath+"/"+itemName; String itemRemotePath=currentRemotePath+"/"+itemName;
if(item.getType().equals(ContainerType.FOLDER)) { if(item.getType().equals(ContainerType.FOLDER)) {
if(recursive) if(recursive)
checkFolder((FolderContainer) item,recursive,rootConfig,itemRelativePath,rootFolderId,lastUpdatedRoutine); checkFolder((FolderContainer) item,recursive,rootConfig,itemRelativePath,rootFolderId,lastUpdatedRoutine,toUseToken);
else WorkspaceUtils.initProperties(item, itemRemotePath, rootConfig.getFilter(), rootConfig.getTargetToken(),rootConfig.getToCreateCatalogName(),rootConfig.getValidateMetadata(),rootFolderId); else WorkspaceUtils.initProperties(item, itemRemotePath, rootConfig.getFilter(), rootConfig.getTargetToken(),rootConfig.getToCreateCatalogName(),rootConfig.getValidateMetadata(),rootFolderId);
}else if(rootConfig.matchesFilter(itemName)) { }else if(rootConfig.matchesFilter(itemName)) {
if(!WorkspaceUtils.isConfigured(item.get())) if(!WorkspaceUtils.isConfigured(item.get()))

View File

@ -73,7 +73,7 @@ public class SynchronizationThread implements Runnable {
FolderContainer parentFolder=client.open(parentFolderItem.getId()).asFolder(); FolderContainer parentFolder=client.open(parentFolderItem.getId()).asFolder();
checkCancelledProcess(); checkCancelledProcess();
SynchFolderConfiguration synchConfig=WorkspaceUtils.loadConfiguration(parentFolder); SynchFolderConfiguration synchConfig=WorkspaceUtils.loadConfiguration(parentFolder);
ThreddsController controller=new ThreddsController(synchConfig.getRemotePath(), synchConfig.getTargetToken()); ThreddsController controller=new ThreddsController(synchConfig.getRemotePath(), theRequest.getProcess().getDescriptor().getOperator());
if(theRequest instanceof TransferToThreddsRequest) { if(theRequest instanceof TransferToThreddsRequest) {
TransferToThreddsRequest request=(TransferToThreddsRequest) theRequest; TransferToThreddsRequest request=(TransferToThreddsRequest) theRequest;

View File

@ -0,0 +1,49 @@
package org.gcube.usecases.ws.thredds.faults;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
@Getter
@Setter
@ToString(callSuper = true)
public class GenericWebException extends Exception{
/**
*
*/
private static final long serialVersionUID = 5200927893712698886L;
private String remoteMessage=null;
private Integer responseHTTPCode=0;
public GenericWebException() {
super();
// TODO Auto-generated constructor stub
}
public GenericWebException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
super(message, cause, enableSuppression, writableStackTrace);
// TODO Auto-generated constructor stub
}
public GenericWebException(String message, Throwable cause) {
super(message, cause);
// TODO Auto-generated constructor stub
}
public GenericWebException(String message) {
super(message);
// TODO Auto-generated constructor stub
}
public GenericWebException(Throwable cause) {
super(cause);
// TODO Auto-generated constructor stub
}
}