diff --git a/src/main/java/org/gcube/data/access/storagehub/services/ACLManager.java b/src/main/java/org/gcube/data/access/storagehub/services/ACLManager.java index 4862ad1..b087fbc 100644 --- a/src/main/java/org/gcube/data/access/storagehub/services/ACLManager.java +++ b/src/main/java/org/gcube/data/access/storagehub/services/ACLManager.java @@ -47,8 +47,14 @@ import org.glassfish.jersey.media.multipart.FormDataParam; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import com.webcohesion.enunciate.metadata.rs.RequestHeader; +import com.webcohesion.enunciate.metadata.rs.RequestHeaders; + @Path("items") @ManagedBy(StorageHubAppllicationManager.class) +@RequestHeaders({ + @RequestHeader( name = "Authorization", description = "Bearer token, see https://dev.d4science.org/how-to-access-resources"), + }) public class ACLManager extends Impersonable { private static final Logger log = LoggerFactory.getLogger(ACLManager.class); diff --git a/src/main/java/org/gcube/data/access/storagehub/services/GroupManager.java b/src/main/java/org/gcube/data/access/storagehub/services/GroupManager.java index 8a716c7..9a7eb87 100644 --- a/src/main/java/org/gcube/data/access/storagehub/services/GroupManager.java +++ b/src/main/java/org/gcube/data/access/storagehub/services/GroupManager.java @@ -73,8 +73,14 @@ import org.glassfish.jersey.media.multipart.FormDataParam; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import com.webcohesion.enunciate.metadata.rs.RequestHeader; +import com.webcohesion.enunciate.metadata.rs.RequestHeaders; + @Path("groups") @ManagedBy(StorageHubAppllicationManager.class) +@RequestHeaders({ + @RequestHeader( name = "Authorization", description = "Bearer token, see https://dev.d4science.org/how-to-access-resources"), + }) public class GroupManager { diff --git a/src/main/java/org/gcube/data/access/storagehub/services/ItemSharing.java b/src/main/java/org/gcube/data/access/storagehub/services/ItemSharing.java index 8050dae..f449590 100644 --- a/src/main/java/org/gcube/data/access/storagehub/services/ItemSharing.java +++ b/src/main/java/org/gcube/data/access/storagehub/services/ItemSharing.java @@ -55,9 +55,15 @@ import org.glassfish.jersey.media.multipart.FormDataParam; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import com.webcohesion.enunciate.metadata.rs.RequestHeader; +import com.webcohesion.enunciate.metadata.rs.RequestHeaders; + @Path("items") +@RequestHeaders({ + @RequestHeader( name = "Authorization", description = "Bearer token, see https://dev.d4science.org/how-to-access-resources"), + }) public class ItemSharing extends Impersonable{ private static final Logger log = LoggerFactory.getLogger(ItemSharing.class); diff --git a/src/main/java/org/gcube/data/access/storagehub/services/ItemsCreator.java b/src/main/java/org/gcube/data/access/storagehub/services/ItemsCreator.java index 8cbcdf2..dbc8c45 100644 --- a/src/main/java/org/gcube/data/access/storagehub/services/ItemsCreator.java +++ b/src/main/java/org/gcube/data/access/storagehub/services/ItemsCreator.java @@ -38,45 +38,50 @@ import org.glassfish.jersey.media.multipart.FormDataParam; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import com.webcohesion.enunciate.metadata.rs.RequestHeader; +import com.webcohesion.enunciate.metadata.rs.RequestHeaders; @Path("items") @ManagedBy(StorageHubAppllicationManager.class) -public class ItemsCreator extends Impersonable{ +@RequestHeaders({ + @RequestHeader(name = "Authorization", description = "Bearer token, see https://dev.d4science.org/how-to-access-resources"), }) +public class ItemsCreator extends Impersonable { private static final Logger log = LoggerFactory.getLogger(ItemsCreator.class); - + @Context ServletContext context; - + RepositoryInitializer repository = StorageHubAppllicationManager.repository; - + @Inject ItemHandler itemHandler; @POST @Consumes(MediaType.APPLICATION_FORM_URLENCODED) @Path("/{id}/create/FOLDER") - public Response createFolder(@PathParam("id") String id, @FormParam("name") String name, + public Response createFolder(@PathParam("id") String id, @FormParam("name") String name, @FormParam("description") String description, @FormParam("hidden") boolean hidden) { InnerMethodName.instance.set("createItem(FOLDER)"); log.info("create folder item called"); Session ses = null; String toReturn = null; - try{ + try { ses = repository.getRepository().login(CredentialHandler.getAdminCredentials(context)); - ItemsParameterBuilder builder = FolderCreationParameters.builder().name(name).description(description).hidden(hidden).on(id).with(ses).author(currentUser); - toReturn = itemHandler.create(builder.build()); - }catch(StorageHubException she ){ + ItemsParameterBuilder builder = FolderCreationParameters.builder().name(name) + .description(description).hidden(hidden).on(id).with(ses).author(currentUser); + toReturn = itemHandler.create(builder.build()); + } catch (StorageHubException she) { log.error(she.getErrorMessage(), she); GXOutboundErrorResponse.throwException(she, Response.Status.fromStatusCode(she.getStatus())); - }catch(RepositoryException re ){ + } catch (RepositoryException re) { log.error("jcr error creating item", re); GXOutboundErrorResponse.throwException(new BackendGenericError("jcr error creating item", re)); - }catch(Throwable e ){ + } catch (Throwable e) { log.error("unexpected error", e); GXOutboundErrorResponse.throwException(new BackendGenericError(e)); - }finally{ - if (ses!=null) + } finally { + if (ses != null) ses.logout(); } @@ -86,69 +91,70 @@ public class ItemsCreator extends Impersonable{ @POST @Consumes(MediaType.APPLICATION_FORM_URLENCODED) @Path("/{id}/create/EXTERNALFOLDER") - public Response createExternalFolder(@PathParam("id") String id, @FormParam("name") String name, + public Response createExternalFolder(@PathParam("id") String id, @FormParam("name") String name, @FormParam("description") String description, @FormParam("hidden") boolean hidden, - @FormParam("pluginName") String pluginName, - @FormParam("parameters") String pluginParameters) { + @FormParam("pluginName") String pluginName, @FormParam("parameters") String pluginParameters) { InnerMethodName.instance.set("createItem(EXTERNALFOLDER)"); log.info("create folder item called"); Session ses = null; String toReturn = null; - try{ - //TODO + try { + // TODO ses = repository.getRepository().login(CredentialHandler.getAdminCredentials(context)); ItemsParameterBuilder builder = FolderCreationParameters.builder().name(name) - .description(description).onRepository(pluginName).withParameters(null).hidden(hidden).on(id).with(ses).author(currentUser); - toReturn = itemHandler.create(builder.build()); - }catch(StorageHubException she ){ + .description(description).onRepository(pluginName).withParameters(null).hidden(hidden).on(id) + .with(ses).author(currentUser); + toReturn = itemHandler.create(builder.build()); + } catch (StorageHubException she) { log.error(she.getErrorMessage(), she); GXOutboundErrorResponse.throwException(she, Response.Status.fromStatusCode(she.getStatus())); - }catch(RepositoryException re ){ + } catch (RepositoryException re) { log.error("jcr error creating item", re); GXOutboundErrorResponse.throwException(new BackendGenericError("jcr error creating item", re)); - }catch(Throwable e ){ + } catch (Throwable e) { log.error("unexpected error", e); GXOutboundErrorResponse.throwException(new BackendGenericError(e)); - }finally{ - if (ses!=null) + } finally { + if (ses != null) ses.logout(); } return Response.ok(toReturn).build(); } - + @POST @Consumes(MediaType.APPLICATION_FORM_URLENCODED) @Path("/{id}/create/URL") - public Response createURL(@PathParam("id") String id, @FormParam("name") String name, @FormParam("description") String description, @FormParam("value") URL value) { + public Response createURL(@PathParam("id") String id, @FormParam("name") String name, + @FormParam("description") String description, @FormParam("value") URL value) { InnerMethodName.instance.set("createItem(URL)"); log.info("create url called"); Session ses = null; String toReturn = null; - try{ + try { ses = repository.getRepository().login(CredentialHandler.getAdminCredentials(context)); - - ItemsParameterBuilder builder = URLCreationParameters.builder().name(name).description(description).url(value).on(id).with(ses).author(currentUser); - toReturn = itemHandler.create(builder.build()); - }catch(StorageHubException she ){ + ItemsParameterBuilder builder = URLCreationParameters.builder().name(name) + .description(description).url(value).on(id).with(ses).author(currentUser); + + toReturn = itemHandler.create(builder.build()); + } catch (StorageHubException she) { log.error(she.getErrorMessage(), she); GXOutboundErrorResponse.throwException(she, Response.Status.fromStatusCode(she.getStatus())); - }catch(RepositoryException re ){ + } catch (RepositoryException re) { log.error("jcr error creating item", re); GXOutboundErrorResponse.throwException(new BackendGenericError("jcr error creating item", re)); - }catch(Throwable e ){ + } catch (Throwable e) { log.error("unexpected error", e); GXOutboundErrorResponse.throwException(new BackendGenericError(e)); - }finally{ - if (ses!=null) + } finally { + if (ses != null) ses.logout(); } return Response.ok(toReturn).build(); } - - + @POST @Consumes(MediaType.APPLICATION_JSON) @Path("/{id}/create/GCUBEITEM") @@ -158,58 +164,58 @@ public class ItemsCreator extends Impersonable{ Session ses = null; String toReturn = null; - try{ + try { ses = repository.getRepository().login(CredentialHandler.getAdminCredentials(context)); - ItemsParameterBuilder builder = GCubeItemCreationParameters.builder().item(item).on(id).with(ses).author(currentUser); - - toReturn = itemHandler.create(builder.build()); - }catch(StorageHubException she ){ + ItemsParameterBuilder builder = GCubeItemCreationParameters.builder() + .item(item).on(id).with(ses).author(currentUser); + + toReturn = itemHandler.create(builder.build()); + } catch (StorageHubException she) { log.error(she.getErrorMessage(), she); GXOutboundErrorResponse.throwException(she, Response.Status.fromStatusCode(she.getStatus())); - }catch(RepositoryException re ){ + } catch (RepositoryException re) { log.error("jcr error creating item", re); GXOutboundErrorResponse.throwException(new BackendGenericError("jcr error creating item", re)); - }catch(Throwable e ){ + } catch (Throwable e) { log.error("unexpected error", e); GXOutboundErrorResponse.throwException(new BackendGenericError(e)); - }finally{ - if (ses!=null) + } finally { + if (ses != null) ses.logout(); } return toReturn; } - @POST @Consumes(MediaType.MULTIPART_FORM_DATA) @Path("/{id}/create/FILE") public String createFileItem(@PathParam("id") String id, @FormDataParam("name") String name, - @FormDataParam("description") String description, - @FormDataParam("file") InputStream stream, - @FormDataParam("file") FormDataContentDisposition fileDetail){ + @FormDataParam("description") String description, @FormDataParam("file") InputStream stream, + @FormDataParam("file") FormDataContentDisposition fileDetail) { InnerMethodName.instance.set("createItem(FILE)"); Session ses = null; String toReturn = null; - try{ - + try { + ses = repository.getRepository().login(CredentialHandler.getAdminCredentials(context)); - ItemsParameterBuilder builder = FileCreationParameters.builder().name(name).description(description).stream(stream).fileDetails(fileDetail) - .on(id).with(ses).author(currentUser); - - toReturn = itemHandler.create(builder.build()); - - }catch(RepositoryException re ){ + ItemsParameterBuilder builder = FileCreationParameters.builder().name(name) + .description(description).stream(stream).fileDetails(fileDetail).on(id).with(ses) + .author(currentUser); + + toReturn = itemHandler.create(builder.build()); + + } catch (RepositoryException re) { log.error("jcr error creating file item", re); GXOutboundErrorResponse.throwException(new BackendGenericError("jcr error creating file item", re)); - }catch(StorageHubException she ){ + } catch (StorageHubException she) { log.error(she.getErrorMessage(), she); GXOutboundErrorResponse.throwException(she, Response.Status.fromStatusCode(she.getStatus())); - }catch(Throwable e ){ + } catch (Throwable e) { log.error("unexpected error", e); GXOutboundErrorResponse.throwException(new BackendGenericError(e)); - }finally{ - if (ses!=null && ses.isLive()) { + } finally { + if (ses != null && ses.isLive()) { log.info("session closed"); ses.logout(); } @@ -218,47 +224,39 @@ public class ItemsCreator extends Impersonable{ } - - - - - @POST @Consumes(MediaType.MULTIPART_FORM_DATA) @Path("/{id}/create/ARCHIVE") public String uploadArchive(@PathParam("id") String id, @FormDataParam("parentFolderName") String parentFolderName, - @FormDataParam("file") InputStream stream, - @FormDataParam("file") FormDataContentDisposition fileDetail){ + @FormDataParam("file") InputStream stream, @FormDataParam("file") FormDataContentDisposition fileDetail) { InnerMethodName.instance.set("createItem(ARCHIVE)"); Session ses = null; String toReturn = null; - try{ + try { ses = repository.getRepository().login(CredentialHandler.getAdminCredentials(context)); - ItemsParameterBuilder builder = ArchiveStructureCreationParameter.builder().parentName(parentFolderName).stream(stream).fileDetails(fileDetail) - .on(id).with(ses).author(currentUser); - - toReturn = itemHandler.create(builder.build()); + ItemsParameterBuilder builder = ArchiveStructureCreationParameter + .builder().parentName(parentFolderName).stream(stream).fileDetails(fileDetail).on(id).with(ses) + .author(currentUser); - }catch(RepositoryException | ArchiveException | IOException re){ + toReturn = itemHandler.create(builder.build()); + + } catch (RepositoryException | ArchiveException | IOException re) { log.error("jcr error extracting archive", re); GXOutboundErrorResponse.throwException(new BackendGenericError("jcr error extracting archive", re)); - }catch(StorageHubException she ){ + } catch (StorageHubException she) { log.error(she.getErrorMessage(), she); GXOutboundErrorResponse.throwException(she, Response.Status.fromStatusCode(she.getStatus())); - }catch(Throwable e ){ + } catch (Throwable e) { log.error("unexpected error", e); GXOutboundErrorResponse.throwException(new BackendGenericError(e)); - } finally{ - if (ses!=null) + } finally { + if (ses != null) ses.logout(); } return toReturn; } - - - } diff --git a/src/main/java/org/gcube/data/access/storagehub/services/ItemsManager.java b/src/main/java/org/gcube/data/access/storagehub/services/ItemsManager.java index aad2502..d214405 100644 --- a/src/main/java/org/gcube/data/access/storagehub/services/ItemsManager.java +++ b/src/main/java/org/gcube/data/access/storagehub/services/ItemsManager.java @@ -94,9 +94,15 @@ import org.gcube.smartgears.utils.InnerMethodName; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import com.webcohesion.enunciate.metadata.rs.RequestHeader; +import com.webcohesion.enunciate.metadata.rs.RequestHeaders; + @Path("items") @ManagedBy(StorageHubAppllicationManager.class) +@RequestHeaders({ + @RequestHeader( name = "Authorization", description = "Bearer token, see https://dev.d4science.org/how-to-access-resources"), + }) public class ItemsManager extends Impersonable{ private static final Logger log = LoggerFactory.getLogger(ItemsManager.class); diff --git a/src/main/java/org/gcube/data/access/storagehub/services/MessageManager.java b/src/main/java/org/gcube/data/access/storagehub/services/MessageManager.java index 2cdf55f..525d19f 100644 --- a/src/main/java/org/gcube/data/access/storagehub/services/MessageManager.java +++ b/src/main/java/org/gcube/data/access/storagehub/services/MessageManager.java @@ -63,8 +63,14 @@ import org.gcube.smartgears.utils.InnerMethodName; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import com.webcohesion.enunciate.metadata.rs.RequestHeader; +import com.webcohesion.enunciate.metadata.rs.RequestHeaders; + @Path("messages") @ManagedBy(StorageHubAppllicationManager.class) +@RequestHeaders({ + @RequestHeader( name = "Authorization", description = "Bearer token, see https://dev.d4science.org/how-to-access-resources"), + }) public class MessageManager extends Impersonable{ private static final Logger log = LoggerFactory.getLogger(MessageManager.class); diff --git a/src/main/java/org/gcube/data/access/storagehub/services/UserManager.java b/src/main/java/org/gcube/data/access/storagehub/services/UserManager.java index 6ee2fbe..58153c9 100644 --- a/src/main/java/org/gcube/data/access/storagehub/services/UserManager.java +++ b/src/main/java/org/gcube/data/access/storagehub/services/UserManager.java @@ -58,8 +58,14 @@ import org.gcube.smartgears.utils.InnerMethodName; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import com.webcohesion.enunciate.metadata.rs.RequestHeader; +import com.webcohesion.enunciate.metadata.rs.RequestHeaders; + @Path("users") @ManagedBy(StorageHubAppllicationManager.class) +@RequestHeaders({ + @RequestHeader( name = "Authorization", description = "Bearer token, see https://dev.d4science.org/how-to-access-resources"), + }) public class UserManager { private static final String INFRASTRUCTURE_MANAGER_ROLE = "Infrastructure-Manager"; diff --git a/src/main/java/org/gcube/data/access/storagehub/services/WorkspaceManager.java b/src/main/java/org/gcube/data/access/storagehub/services/WorkspaceManager.java index f5cf456..5642808 100644 --- a/src/main/java/org/gcube/data/access/storagehub/services/WorkspaceManager.java +++ b/src/main/java/org/gcube/data/access/storagehub/services/WorkspaceManager.java @@ -55,10 +55,16 @@ import org.gcube.smartgears.utils.InnerMethodName; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import com.webcohesion.enunciate.metadata.rs.RequestHeader; +import com.webcohesion.enunciate.metadata.rs.RequestHeaders; + @Path("/") @ManagedBy(StorageHubAppllicationManager.class) +@RequestHeaders({ + @RequestHeader( name = "Authorization", description = "Bearer token, see https://dev.d4science.org/how-to-access-resources"), + }) public class WorkspaceManager extends Impersonable{ private static final Logger log = LoggerFactory.getLogger(WorkspaceManager.class); diff --git a/src/main/java/org/gcube/data/access/storagehub/services/admin/ScriptManager.java b/src/main/java/org/gcube/data/access/storagehub/services/admin/ScriptManager.java index 1d1fd00..f95bdf9 100644 --- a/src/main/java/org/gcube/data/access/storagehub/services/admin/ScriptManager.java +++ b/src/main/java/org/gcube/data/access/storagehub/services/admin/ScriptManager.java @@ -40,7 +40,13 @@ import org.glassfish.jersey.media.multipart.FormDataParam; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import com.webcohesion.enunciate.metadata.rs.RequestHeader; +import com.webcohesion.enunciate.metadata.rs.RequestHeaders; + @Path("admin/script") +@RequestHeaders({ + @RequestHeader( name = "Authorization", description = "Bearer token, see https://dev.d4science.org/how-to-access-resources"), + }) public class ScriptManager {