【问题标题】:AccessControlException while trying to create a directory on Azure尝试在 Azure 上创建目录时出现 AccessControlException
【发布时间】:2019-01-14 08:02:32
【问题描述】:

我正在尝试使用天蓝色数据湖依赖项在 azureDataLake 中创建目录

<dependency>
            <groupId>com.microsoft.azure</groupId>
            <artifactId>azure-data-lake-store-sdk</artifactId>
            <version>2.1.5</version>
</dependency>

使用以下方法:

private ADLStoreClient client; 
public boolean createDirectory(String path) {
        try {

            // create directory
            client.createDirectory(path);

        } catch (ADLException ex) {
            printExceptionDetails(ex);
            return false;
        } catch (Exception ex) {
            log.error(" Exception in createDirectory : {}", ex);
            return false;
        }
        return true;
    } 

我得到了这个例外:

Error creating directory /gx-zweappdhd004/home/azhdipaasssh2/ADH/Compta/1458/1533632735200/RAPPORTS/
Operation MKDIRS failed with HTTP403 : AccessControlException 

我检查了权限,我都有,所以和权限无关。

更新

为了更具体地说明方法 isSuccessfulResponse() 内部发生的问题,确切地说是在这一行 HttpTransport.java#L137 因为 httpResponseCode 等于 403,任何人都可以解释一下。

更新2

我发现这条线正在返回 403 状态:HttpTransport.java#L288,我还尝试评估 conn.getErrorStream().read() 并得到了这个 stream is closed,仅供参考,这是错误有时而不是总是发生。

【问题讨论】:

    标签: java azure azure-storage azure-data-lake


    【解决方案1】:

    我没有重现你的问题,你可以参考我的工作代码:

    import com.microsoft.aad.adal4j.AuthenticationContext;
    import com.microsoft.aad.adal4j.AuthenticationResult;
    import com.microsoft.aad.adal4j.ClientCredential;
    import com.microsoft.azure.datalake.store.ADLStoreClient;
    
    import java.io.IOException;
    import java.util.concurrent.ExecutionException;
    import java.util.concurrent.ExecutorService;
    import java.util.concurrent.Executors;
    import java.util.concurrent.Future;
    
    public class CreateDirectory {
    
        static ADLStoreClient client;
    
        public static void main(String[] args) throws InterruptedException, ExecutionException, IOException {
            setup();
        }
    
        public static void setup() throws IOException, ExecutionException, InterruptedException {
            String APP_ID = "<your app id>";
            String APP_SECRET = "<your app secret>";
            String dirName = "/jay";
            String StoreAcct = "jaygong";
    
            String authority = "https://login.microsoftonline.com/<your tenant id>";
            String resourcUrl = "https://management.core.windows.net/";
            ExecutorService service = Executors.newFixedThreadPool(1);
    
            AuthenticationContext context = new AuthenticationContext(authority, true, service);
    
            // Acquire Token
            Future<AuthenticationResult> result = context.acquireToken(
                    resourcUrl,
                    new ClientCredential(APP_ID, APP_SECRET),
                    null
            );
            String token = result.get().getAccessToken();
            System.out.println(token);
    
            String account = StoreAcct + ".azuredatalakestore.net";
            client = ADLStoreClient.createClient(account, token);
    
            client.createDirectory(dirName);
            System.out.println("finish.....");
    
        }
    }
    

    不要忘记向您的客户授予访问 ADL 权限。

    希望对你有所帮助。

    【讨论】:

    • 感谢您的回复,我已经设置了配置并且它正在工作,我只是对这一行有问题github.com/Azure/azure-data-lake-store-java/blob/master/src/… 有时它会返回 403,而且这个问题并不总是会发生,有时它会创建文件夹但有时它会出错。
    • @Svg_af 抱歉,我无法重现您的反复无常的错误。我假设您的资源是公开的,因此权限有任何更新。如果您采纳我的上述答案,您可以投票并标记它。谢谢。
    • @Jay_Gong 对不起,我已经有了这个配置,这并没有解决我的问题。
    • @jay 我可以使用此代码接收访问令牌,但在线程“main”com.microsoft.azure.datalake.store.ADLException 中出现以下异常:创建目录/adi 操作时出错MKDIRS 因 HTTP403 失败:AccessControlException 在 1 次尝试后最后遇到异常。 [HTTP403(AccessControlException)]
    猜你喜欢
    • 2010-09-21
    • 1970-01-01
    • 1970-01-01
    • 2011-08-25
    • 2016-09-26
    • 1970-01-01
    • 2022-06-13
    • 2022-08-14
    • 1970-01-01
    相关资源
    最近更新 更多