This is an automated email from the ASF dual-hosted git repository.

gaul pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/jclouds.git


The following commit(s) were added to refs/heads/master by this push:
     new f5806d0  JCLOUDS-1428: Support for SAS token based Authentication for 
Azure Blob Storage
f5806d0 is described below

commit f5806d0488ba0894b3f1370a23ae9ab1dafffbe7
Author: Aliaksandra Kharushka <[email protected]>
AuthorDate: Mon May 27 15:05:12 2019 +0200

    JCLOUDS-1428: Support for SAS token based Authentication for Azure Blob 
Storage
    
    removed ACL check for SAS Auth AzureBlobs
---
 .../config/AzureBlobStoreContextModule.java        | 12 ++++++--
 .../functions/BlobPropertiesToBlobMetadata.java    | 10 +++++--
 .../config/InsufficientAccessRightsException.java  | 32 ++++++++++++++++++++++
 3 files changed, 48 insertions(+), 6 deletions(-)

diff --git 
a/providers/azureblob/src/main/java/org/jclouds/azureblob/blobstore/config/AzureBlobStoreContextModule.java
 
b/providers/azureblob/src/main/java/org/jclouds/azureblob/blobstore/config/AzureBlobStoreContextModule.java
index aa5b233..68ceef3a 100644
--- 
a/providers/azureblob/src/main/java/org/jclouds/azureblob/blobstore/config/AzureBlobStoreContextModule.java
+++ 
b/providers/azureblob/src/main/java/org/jclouds/azureblob/blobstore/config/AzureBlobStoreContextModule.java
@@ -19,6 +19,7 @@ package org.jclouds.azureblob.blobstore.config;
 import java.util.concurrent.TimeUnit;
 
 import javax.inject.Singleton;
+import javax.inject.Named;
 
 import org.jclouds.azureblob.AzureBlobClient;
 import org.jclouds.azureblob.blobstore.AzureBlobRequestSigner;
@@ -27,6 +28,8 @@ import org.jclouds.azureblob.domain.PublicAccess;
 import org.jclouds.blobstore.BlobRequestSigner;
 import org.jclouds.blobstore.BlobStore;
 import org.jclouds.blobstore.attr.ConsistencyModel;
+import org.jclouds.azureblob.config.InsufficientAccessRightsException;
+
 
 import com.google.common.cache.CacheBuilder;
 import com.google.common.cache.CacheLoader;
@@ -46,12 +49,15 @@ public class AzureBlobStoreContextModule extends 
AbstractModule {
 
    @Provides
    @Singleton
-   protected final LoadingCache<String, PublicAccess> containerAcls(final 
AzureBlobClient client) {
+   protected final LoadingCache<String, PublicAccess> containerAcls(final 
AzureBlobClient client, @Named("sasAuth") final boolean sasAuthentication) {
       return CacheBuilder.newBuilder().expireAfterWrite(30, 
TimeUnit.SECONDS).build(
                new CacheLoader<String, PublicAccess>() {
                   @Override
-                  public PublicAccess load(String container) {
-                     return client.getPublicAccessForContainer(container);
+                  public PublicAccess load(String container) throws 
CacheLoader.InvalidCacheLoadException {
+                     if (!sasAuthentication) {
+                        return client.getPublicAccessForContainer(container);
+                     }
+                     throw new InsufficientAccessRightsException("SAS 
Authentication does not support getAcl and setAcl calls.");
                   }
 
                   @Override
diff --git 
a/providers/azureblob/src/main/java/org/jclouds/azureblob/blobstore/functions/BlobPropertiesToBlobMetadata.java
 
b/providers/azureblob/src/main/java/org/jclouds/azureblob/blobstore/functions/BlobPropertiesToBlobMetadata.java
index 6a1eb43..d7e0c6c 100644
--- 
a/providers/azureblob/src/main/java/org/jclouds/azureblob/blobstore/functions/BlobPropertiesToBlobMetadata.java
+++ 
b/providers/azureblob/src/main/java/org/jclouds/azureblob/blobstore/functions/BlobPropertiesToBlobMetadata.java
@@ -28,11 +28,13 @@ import org.jclouds.blobstore.domain.MutableBlobMetadata;
 import org.jclouds.blobstore.domain.StorageType;
 import org.jclouds.blobstore.domain.internal.MutableBlobMetadataImpl;
 import org.jclouds.http.HttpUtils;
+import org.jclouds.azureblob.config.InsufficientAccessRightsException;
+import org.jclouds.util.Throwables2;
 
 import com.google.common.base.Function;
-import com.google.common.cache.CacheLoader;
 import com.google.common.cache.LoadingCache;
 
+
 @Singleton
 public class BlobPropertiesToBlobMetadata implements Function<BlobProperties, 
MutableBlobMetadata> {
    private final LoadingCache<String, PublicAccess> containerAcls;
@@ -58,8 +60,10 @@ public class BlobPropertiesToBlobMetadata implements 
Function<BlobProperties, Mu
             PublicAccess containerAcl = 
containerAcls.getUnchecked(from.getContainer());
             if (containerAcl != PublicAccess.PRIVATE)
                to.setPublicUri(from.getUrl());
-         } catch (CacheLoader.InvalidCacheLoadException e) {
-            // nulls not permitted from cache loader
+         } catch (Exception ex) {
+            //AzureBlob is not a publicly accessible object, but it is 
impossible to obtain ACL using SAS Auth. 
+            InsufficientAccessRightsException iare = 
Throwables2.getFirstThrowableOfType(ex, 
InsufficientAccessRightsException.class);
+            if (iare == null) throw ex;  
          }
       if (to.getContentMetadata() != null && 
to.getContentMetadata().getContentType() != null &&
             
to.getContentMetadata().getContentType().equals("application/directory")) {
diff --git 
a/providers/azureblob/src/main/java/org/jclouds/azureblob/config/InsufficientAccessRightsException.java
 
b/providers/azureblob/src/main/java/org/jclouds/azureblob/config/InsufficientAccessRightsException.java
new file mode 100755
index 0000000..45e0cad
--- /dev/null
+++ 
b/providers/azureblob/src/main/java/org/jclouds/azureblob/config/InsufficientAccessRightsException.java
@@ -0,0 +1,32 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+ 
+ 
+/**
+ * Handles the inability of SAS Authentication string to authenticate the 
getAcl and setAcl requests.
+ * 
+ */
+ 
+package org.jclouds.azureblob.config;
+
+public class InsufficientAccessRightsException extends RuntimeException {
+
+   public InsufficientAccessRightsException(String message) {
+      super(message);
+   }
+
+}

Reply via email to