有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

尝试在Azure上创建目录时发生java AccessControlException

我正在尝试使用azure data lake依赖项在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,仅供参考,这个错误有时会发生,但并不总是发生


共 (1) 个答案

  1. # 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.....");
    
        }
    }
    

    enter image description here

    别忘了向你的客户授予访问ADL许可

    enter image description here

    enter image description here

    希望对你有帮助