You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jackrabbit.apache.org by Apache Wiki <wi...@apache.org> on 2018/08/21 19:35:13 UTC

[Jackrabbit Wiki] Update of "Direct Binary Access" by MattRyan

Dear Wiki user,

You have subscribed to a wiki page or wiki category on "Jackrabbit Wiki" for change notification.

The "Direct Binary Access" page has been changed by MattRyan:
https://wiki.apache.org/jackrabbit/Direct%20Binary%20Access?action=diff&rev1=22&rev2=23

Comment:
Updated doc to match current implementation.

  = Oak Direct Binary Access =
  
  == Summary ==
- Oak Direct Binary Access is a capability of Oak where in Oak allows an authenticated client to create or download blobs directly to/from the blob store, assuming the authenticated user has appropriate permission to do so.  The primary value of this feature is that the I/O of transferring large binary files to or from the blob store can be offloaded entirely from Oak and performed directly between a client application and the blob store.  The availability of this feature is subject to certain capabilities being available in the ''!DataStore'' implementation as well as the service provider underlying that implementation.
+ Oak Direct Binary Access is a capability of Oak wherein Oak allows an authenticated client to upload or download blobs directly to/from the blob store, assuming the authenticated user has appropriate permission to do so.  The primary value of this feature is that the I/O of transferring large binary files to or from the blob store can be offloaded entirely from Oak and performed directly between a client application and the blob store.  The availability of this feature is subject to certain capabilities being available in the ''!DataStore'' implementation as well as the service provider underlying that implementation.
  
  == Javadocs ==
  
@@ -22, +22 @@

  This capability offers two basic features:  Direct Binary Download and Direct Binary Upload.
  
  === Direct Binary Download ===
- This feature allows a client application to download a binary directly from a supported storage location via a URL.  The application user must be successfully authenticated to the system and must have permission to read the binary object in question in order to obtain a ''Binary'' object.  Using this object, the client may then call a new JCR API, ''getHttpDownloadURL(Binary)'', which returns a URL that the client may then use to read the binary directly.
+ This feature allows a client application to download a binary directly from a supported storage location via a URL.  The application user must be successfully authenticated to the system and must have permission to read the binary object in question in order to obtain a ''Binary'' object.  Using this object, the client may then cast it to a ''BinaryDownload''.  If successful, the client may then call a new JCR API, ''getURI(BinaryDownloadOptions)'', which returns a URL that the client may then use to read the binary directly.
  
  This block diagram shows the main parties involved for downloading ([[attachment:oak-direct-binary-download-block-diagram.gliffy|gliffy sources]]):
  
  {{attachment:oak-direct-binary-download-block-diagram.png}}
  
  === Direct Binary Upload ===
- This feature allows a client application to upload a binary directly to a supported storage location via one or more URLs.  This is done in a three-step process.  First, the application calls a new JCR API, ''initiateHttpUpload(String, long, int)'', passing three arguments:  the path to the property where the users wishes to add the binary, the maximum expected or known size of the binary, and the maximum number of upload URLs that the client can support.  If the user has permission to add a property at the specified path, an object will be returned containing instructions to aid in completing the upload, including one or more URLs to use and an upload token that is required later.  Second, the client application may then use one or more of the provided URLs to upload the binary directly to the storage.  Multi-part uploads are supported and handled automatically if desired - all the client need do is upload chunks of the binary using the provided URLs in sequence.  When all the uploads are complete, the client then calls a new JCR API, ''completeHttpUpload(String)'', providing a signed upload token that was received in the original call to ''initiateHttpUpload()'' and returning a ''Binary''.  Calling ''completeHttpUpload()'' notifies the storage provider of the upload parts to be assembled into a single binary object, and also allows that the corresponding property need not be created until after the binary upload is complete, at which point the returned ''Binary'' can be associated to the property.
+ This feature allows a client application to upload a binary directly to a supported storage location via one or more URLs.  This is done in a three-step process.  First, the application obtains a reference to the active ''ValueFactory''.  If this is an instance of ''JackrabbitValueFactory'', the application then calls a new JCR API, ''initiateBinaryUpload(long, int)'', passing two arguments:  the maximum expected or known size of the binary, and the maximum number of upload URLs that the client can support.  A ''BinaryUpload'' object will be returned containing instructions to aid in completing the upload, including one or more URLs to use and an upload token that is required later.  Second, the client application may then use one or more of the provided URLs, which can be obtained by calling ''getUploadURIs()'' on the returned ''BinaryUpload'' object, to upload the binary directly to the storage.  Multi-part uploads are supported and handled automatically if desired - all the client need do is upload chunks of the binary using the provided URLs in sequence.  When all the uploads are complete, the client then uses the ''JackrabbitValueFactory'' to call a new JCR API, ''completeBinaryUpload(String)'', providing a signed upload token that can be obtained by calling ''getUploadToken()'' on the ''BinaryUpload'' object that was returned from the original call to ''initiateHttpUpload(long, int)'', and returning a ''Binary''.  Calling ''completeHttpUpload(String)'' notifies the storage provider of the upload parts to be assembled into a single binary object, and also allows that the corresponding property need not be created until after the binary upload is complete, at which point the returned ''Binary'' can be associated to the property.
  
  
  This block diagram shows the main parties involved for uploading ([[attachment:oak-direct-binary-upload-block-diagram.gliffy|gliffy sources]]):
@@ -40, +40 @@

  
  {{attachment:oak-direct-binary-upload-sequence-diagram.svg}}
  
- == API ==
-  * ''oak-jcr''
-   * ''!HttpBinaryProvider'' (new interface)
-    * ''initiateHttpUpload(String binaryPath, long maxSizeInBytes, int maxUploadURLs)''
-     * Begins the process of doing a direct HTTP upload (''PUT'') to storage.
-     * Parameters:
-      * ''binaryPath'' (''String'') - The path in the node store to the property that will hold the ''Binary'' to be uploaded.
-      * ''maxSizeInBytes'' (''long'') - The known size of the binary, if known, or the maximum expected size of the binary otherwise.
-      * ''maxUploadURLs'' (''int'') - The maximum number of upload URLs that the client can handle (for example, if the client has a limitation on response payload size).
-     * Returns:
-      * A ''!BinaryHttpUpload'' object containing instructions on how to complete the upload.
-    * ''completeHttpUpload(String uploadToken)''
-     * Indicates the completion of a direct HTTP upload to storage.
-     * Parameters:
-      * ''uploadToken'' (''String'') - A signed token that uniquely identifies this upload, as received in the ''!BinaryHttpUpload'' object.
-     * Returns:
-      * A ''Binary'' that can be stored in the node store as a property.
-    * ''getHttpDownloadURL(Binary binary)'' - Obtains a ''URL'' for the supplied ''Binary'' for directly downloading the object.
-     * Parameters:
-      * ''binary'' (''Binary'') - The binary object to be downloaded.  Must have been obtained via prior JCR calls (i.e. must be instanceof ''!BinaryImpl'').
-     * Returns:
-      * A ''URL'' that can be used to directly download the binary object.
-   * ''!BinaryHttpUpload'' (new interface)
-    * Used to represent a single upload transaction.  An instance of this interface is returned from a successful call to ''initiateHttpUpload()''.
-    * ''getUploadToken()'' - Returns the signed upload token that uniquely identifies this upload.
-    * ''getMinPartSize()'' - Informs the caller of the minimum size of a file part that can be uploaded as a single part.  Does not apply to the last part of a multi-part upload, or to a single-put upload.
-    * ''getMaxPartSize()'' - Informs the caller of the maximum size of a file part that can be uploaded as a single part.  This is usually a service provider or implementation limitation; files larger than this must be uploaded using multi-part upload.
-    * ''getURLParts()'' - Returns an ordered collection of URLs that can be used for uploading.  The client does not necessarily need to use them all, so long as each upload part (except the last) is within the range of ''getMinPartSize()'' and ''getMaxPartSize()'', but if multiple ''URL''s are used they should be used in sequence, not reusing any ''URL''.
-   * ''!SessionImpl'' - updated to implement ''!HttpBinaryProvider''
-  * ''oak-store-spi''
-   * Changes to ''!ValueFactoryImpl'':
-    * ''createBinary(Blob blob)'' - Using a ''Blob'' object as input, return the corresponding ''Binary'' object.
-    * ''getBlobId(Binary binary)'' - Using a ''Binary'' object as input, return the blob content identity for the corresponding ''Blob'' object.
-  * ''oak-api''
-   * ''!HttpBlobProvider'' (new interface)
-    * This interface is the counterpart to the new ''oak-jcr'' ''!HttpBinaryProvider'', working with ''Blob'' instances instead of ''Binary'' instances.
-    * ''initiateHttpUpload(long maxSizeInBytes, int maxUploadURLs)'' - Called by ''!HttpBinaryProvider.initiateHttpUpload()''.  The ''binaryPath'' is only needed at the ''oak-jcr'' layer to do the permissions check and so is not passed along to the ''oak-api'' layer.  Returns a ''BlobHttpUpload'' instance.
-    * ''completeHttpUpload(String uploadToken)'' - Called by '!HttpBinaryProvider.completeHttpUpload()'.  ''!ValueFactoryImpl.createBinary(Blob)'' is used to convert the ''Blob'' returned by this call into a ''Binary'' used at the ''oak-jcr'' layer above. 
-    * ''getHttpDownloadURL(String blobId)'' - Called by ''!HttpBinaryProvider.getHttpDownloadURL()''.  ''!ValueFactoryImpl.getBlobId(Binary)'' is used to get the correct blob ID for this call.
-   * ''!BlobHttpUpload'' (new interface)
-    * This interface is the counterpart to the new ''oak-jcr'' ''!BinaryHttpUpload'', working with ''Blob'' instances instead of ''Binary'' instances.
-  * ''oak-core''
-   * ''!MutableRoot'' - updated to implement ''!HttpBlobProvider''
-  * ''oak-segment-tar''
-   * ''!SegmentNodeStore'' - updated to implement '!HttpBlobProvider''
-  * ''oak-store-document''
-   * ''!DocumentNodeStore'' - updated to implement '!HttpBlobProvider''
-  * ''oak-blob-plugins''
-   * ''!DataStoreBlobStore'' - updated to implement ''!HttpBlobProvider''
-   * ''!HttpDataRecordProvider'' (new interface)
-    * This interface is the counterpart to the new ''oak-api'' ''!HttpBlobProvider'', working with ''!DataRecord'' instances instead of ''Blob'' instances.
-   * ''!DataRecordHttpUpload'' (new interface)
-    * This interface is the counterpart to the new ''oak-api'' ''!BlobHttpUpload'', working with ''!DataRecord'' instances instead of ''Blob'' instances.
-  * ''oak-blob-cloud''
-   * ''!S3DataStore'' - changed to implement ''!HttpDataRecordProvider''
-  * ''oak-blob-cloud-azure''
-   * ''!AzureDataStore'' - changed to implement ''!HttpDataRecordProvider''
- 
- === Oak Layers ===
- 
- For handling binaries, Oak has multiple layers. That's why the feature had to be added on multiple APIs and SPIs: JCR ({{{HttpBinaryProvider}}}), Oak API and internal SPIs NodeStore and BlobStore ({{{HttpBlobProvider}}}) & DataStore ({{{HttpDataRecordProvider}}}). The following diagram outlines the layers (without this patch):
- 
- {{attachment:oak-binary-layer-overview.png||width=200}}
  
  == Security ==
  There are a number of security-related aspects to be considered for this capability.
@@ -121, +58 @@

  === Authorization ===
  To obtain a download URL, a valid ''Binary'' object must be obtained which is an instance of ''!BinaryImpl''.  This can be obtained via an authenticated session calling into the JCR API ot request a ''Binary'' for an existing object.  Because the binary must be obtained first from the JCR, it has already been established that the user represented by the session has permission to read the binary, so giving the URL for use by this user is acceptable.
  
- To perform a direct upload, an authenticated session must first call ''!HttpBinaryProvider.initiateHttpUpload()'' and provide the path to the location where the client wishes to create the binary property.  A permission check is then performed to ensure that the session has permission to create a binary property at the provided path.  Thus it is not possible to complete a successful call to ''!HttpBinaryProvider.initiateHttpUpload()'' without a session that has permission to create the binary property as specified.  The ''!BinaryHttpUpload'' object returned from a successful call to ''!HttpBinaryProvider.initiateHttpUpload()'' contains a signed upload token that must be supplied to a subsequent call to ''!HttpBinaryProvider.completeHttpUpload()''.  Without the signed token the upload cannot be completed successfully, and thus no ''Binary'' object will be returned and thus will never become a part of the content repository.  The uploaded data will eventually be garbage collected.  Similarly, if the upload token is modified in any way in an attempt to change the upload from what was originally approved, the signature will not match and the upload will not be completed successfully.  Thus a binary upload can only be completed by an authenticated and authorized user.
+ Once a binary is uploaded (direct or otherwise), an authenticated session must have the correct permission to associate the ''Binary'' with a binary property in the JCR.  Thus it is not possible to add a binary to the repository by using direct binary upload unless sufficient permissions exist to add the property.  Note that may be possible to upload the binary to blob storage this way; however, this is also possible to do using the traditional upload mechanism.  Such unreferenced binaries are not considered part of the repository and will be garbage collected.  If a client wishes to avoid uploading a binary when no permission exists to add the binary to a property, the client should first check for adequate permission at the property path and then perform the upload.
  
  == Other Approaches ==