Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for TokenCredentials configuration #43426

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions sdk/storage/azure-storage-blob-nio/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## 12.0.0-beta.29 (Unreleased)

### Features Added
- Added support for TokenCredentials configurations for Authentication against Microsoft EntraID

### Breaking Changes

Expand Down
5 changes: 5 additions & 0 deletions sdk/storage/azure-storage-blob-nio/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -105,5 +105,10 @@
<version>1.15.5</version> <!-- {x-version-update;testdep_net.bytebuddy:byte-buddy-agent;external_dependency} -->
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-identity</artifactId>
<version>1.14.2</version>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
package com.azure.storage.blob.nio;

import com.azure.core.credential.AzureSasCredential;
import com.azure.core.credential.TokenCredential;
import com.azure.core.http.HttpClient;
import com.azure.core.http.policy.HttpLogDetailLevel;
import com.azure.core.http.policy.HttpPipelinePolicy;
Expand Down Expand Up @@ -67,6 +68,11 @@ public final class AzureFileSystem extends FileSystem {
*/
public static final String AZURE_STORAGE_SAS_TOKEN_CREDENTIAL = "AzureStorageSasTokenCredential";

/**
* Expected type: String
*/
public static final String AZURE_STORAGE_TOKEN_CREDENTIAL = "AzureStorageTokenCredential";

/**
* Expected type: com.azure.core.http.policy.HttpLogLevelDetail
*/
Expand Down Expand Up @@ -399,12 +405,15 @@ private BlobServiceClient buildBlobServiceClient(String endpoint, Map<String, ?>
builder.credential((StorageSharedKeyCredential) config.get(AZURE_STORAGE_SHARED_KEY_CREDENTIAL));
} else if (config.containsKey(AZURE_STORAGE_SAS_TOKEN_CREDENTIAL)) {
builder.credential((AzureSasCredential) config.get(AZURE_STORAGE_SAS_TOKEN_CREDENTIAL));
} else if (config.containsKey(AZURE_STORAGE_TOKEN_CREDENTIAL)) {
builder.credential((TokenCredential) config.get(AZURE_STORAGE_TOKEN_CREDENTIAL));
} else {
throw LoggingUtility
.logError(LOGGER,
new IllegalArgumentException(String.format("No credentials were "
+ "provided. Please specify one of the following when constructing an AzureFileSystem: %s, %s.",
AZURE_STORAGE_SHARED_KEY_CREDENTIAL, AZURE_STORAGE_SAS_TOKEN_CREDENTIAL)));
AZURE_STORAGE_SHARED_KEY_CREDENTIAL, AZURE_STORAGE_SAS_TOKEN_CREDENTIAL,
AZURE_STORAGE_TOKEN_CREDENTIAL)));
}

// Configure options and client.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
package com.azure.storage.blob.nio;

import com.azure.core.credential.AzureSasCredential;
import com.azure.core.test.utils.MockTokenCredential;
import com.azure.core.util.CoreUtils;
import com.azure.storage.common.sas.AccountSasPermission;
import com.azure.storage.common.sas.AccountSasResourceType;
Expand Down Expand Up @@ -91,6 +92,21 @@ public void createFailIa(boolean credential, boolean containers) {
() -> new AzureFileSystem(new AzureFileSystemProvider(), ENV.getPrimaryAccount().getName(), config));
}

@Test
public void createWithTokenCredential() throws IOException {
String containerName = generateContainerName();
config.put(AzureFileSystem.AZURE_STORAGE_FILE_STORES, containerName);
config.put(AzureFileSystem.AZURE_STORAGE_TOKEN_CREDENTIAL, new MockTokenCredential());
AzureFileSystem azureFileSystem
= new AzureFileSystem(new AzureFileSystemProvider(), ENV.getPrimaryAccount().getBlobEndpoint(), config);

List<String> actualContainerNames = new ArrayList<>();
azureFileSystem.getFileStores().forEach(fs -> actualContainerNames.add(fs.name()));

assertEquals(1, actualContainerNames.size());
assertTrue(actualContainerNames.contains(containerName));
}

@Test
public void createFailContainerCheck() {
config
Expand Down
Loading