【问题标题】:Authentication issue while connecting to Azure Blob using Camel使用 Camel 连接到 Azure Blob 时的身份验证问题
【发布时间】:2022-01-27 23:19:43
【问题描述】:

我的目标是监视 hello 目录中的任何新文件创建。创建新文件后,它应该触发 API 并将在 hello 目录中创建的文件上传到 azure。我越来越低于异常。有人可以帮我吗?

WatcherRoute.java

 @Service
    public class WatcherRoute extends RouteBuilder {
    
      @Override
      public void configure() {
    
        String accessKey = "key";
        String baseUrl = "base/url";
    
    
        from("file-watch:hello?events=CREATE&antInclude=**/*.txt&recursive=true")
            .to("direct:start","direct:uploadFileToBlob")
            .end();
    
        from("direct:uploadFileToBlob")
            .to("azure-storage-blob://storage-account-name/containerName?blobName=test.txt&accessKey="+getBase64EncodedCipherText(accessKey))
            .end();
    
        from("direct:start")
            .setHeader(Exchange.HTTP_METHOD, constant("GET"))
            .setHeader("Content-Type",constant("application/json"))
            .to(baseUrl)
            .process(logResponse)
            .end();
      }
    
       private String getBase64EncodedCipherText(String cipherText) {
        byte[] cText = cipherText.getBytes();
        return Base64.getEncoder().encodeToString(cText);
      }
    }

异常跟踪:

2021-12-29 09:33:59.604 ERROR 78488 --- [elFileWatchPoll] o.a.c.p.e.DefaultErrorHandler            : Failed delivery for (MessageId: 18CB93B18D0D95B-0000000000000001 on ExchangeId: 18CB93B18D0D95B-0000000000000001). Exhausted after delivery attempt: 1 caught: com.azure.storage.blob.models.BlobStorageException: If you are using a StorageSharedKeyCredential, and the server returned an error message that says 'Signature did not match', you can compare the string to sign with the one generated by the SDK. To log the string to sign, pass in the context key value pair 'Azure-Storage-Log-String-To-Sign': true to the appropriate method call.
If you are using a SAS token, and the server returned an error message that says 'Signature did not match', you can compare the string to sign with the one generated by the SDK. To log the string to sign, pass in the context key value pair 'Azure-Storage-Log-String-To-Sign': true to the appropriate generateSas method call.
Please remember to disable 'Azure-Storage-Log-String-To-Sign' before going to production as this string can potentially contain PII.
Status code 403, "<?xml version="1.0" encoding="utf-8"?><Error><Code>AuthenticationFailed</Code><Message>Server failed to authenticate the request. Make sure the value of Authorization header is formed correctly including the signature.
RequestId:{id}
Time:2021-12-29T15:33:59.4459965Z</Message><AuthenticationErrorDetail>The MAC signature found in the HTTP request 'example' is not the same as any computed signature. Server used following string to sign: 'GET

【问题讨论】:

    标签: spring-boot apache-camel azure-blob-storage spring-camel


    【解决方案1】:

    您可以尝试使用以下解决方案:

    解决方案 1: 如果您使用了主要连接字符串,请尝试将连接字符串更改为次要

    解决方案 2: Azure 存储的身份验证不仅仅是提供访问密钥的问题(这不是很安全)。您需要创建一个表示给定请求的签名字符串,使用 HMAC-SHA256 算法(使用您的存储密钥进行签名)对字符串进行签名,然后编码以 64 为底的结果。详情请见https://msdn.microsoft.com/en-us/library/azure/dd179428.aspx

    解决方案 3: 如果您使用 共享访问签名 (SAS) 进行身份验证,请检查其是否已过期并重新创建并再次运行。

    更多详情请参考SO Thread:

    【讨论】:

      猜你喜欢
      • 2022-09-27
      • 1970-01-01
      • 1970-01-01
      • 2018-08-23
      • 2021-01-28
      • 1970-01-01
      • 1970-01-01
      • 2021-11-22
      • 1970-01-01
      相关资源
      最近更新 更多