Skip to content

Commit f38ba08

Browse files
authored
Enabling bearer challenges for file share (#41555)
* added support for bearer challenges in file share * fixing accidental pom change * style
1 parent dbe0b07 commit f38ba08

File tree

8 files changed

+37
-27
lines changed

8 files changed

+37
-27
lines changed

sdk/storage/azure-storage-file-share/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
## 12.27.0-beta.2 (Unreleased)
44

55
### Features Added
6+
- Added support for bearer token challenges.
67

78
### Breaking Changes
89

sdk/storage/azure-storage-file-share/src/main/java/com/azure/storage/file/share/implementation/util/BuilderHelper.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
import com.azure.core.http.policy.AddDatePolicy;
1414
import com.azure.core.http.policy.AddHeadersPolicy;
1515
import com.azure.core.http.policy.AzureSasCredentialPolicy;
16-
import com.azure.core.http.policy.BearerTokenAuthenticationPolicy;
1716
import com.azure.core.http.policy.HttpLogOptions;
1817
import com.azure.core.http.policy.HttpLoggingPolicy;
1918
import com.azure.core.http.policy.HttpPipelinePolicy;
@@ -37,6 +36,7 @@
3736
import com.azure.storage.common.policy.RequestRetryOptions;
3837
import com.azure.storage.common.policy.ResponseValidationPolicyBuilder;
3938
import com.azure.storage.common.policy.ScrubEtagPolicy;
39+
import com.azure.storage.common.policy.StorageBearerTokenChallengeAuthorizationPolicy;
4040
import com.azure.storage.common.policy.StorageSharedKeyCredentialPolicy;
4141
import com.azure.storage.common.sas.CommonSasQueryParameters;
4242
import com.azure.storage.file.share.models.ShareAudience;
@@ -124,7 +124,7 @@ public static HttpPipeline buildPipeline(StorageSharedKeyCredential storageShare
124124
String scope = audience != null
125125
? ((audience.toString().endsWith("/") ? audience + ".default" : audience + "/.default"))
126126
: Constants.STORAGE_SCOPE;
127-
credentialPolicy = new BearerTokenAuthenticationPolicy(tokenCredential, scope);
127+
credentialPolicy = new StorageBearerTokenChallengeAuthorizationPolicy(tokenCredential, scope);
128128
} else if (azureSasCredential != null) {
129129
credentialPolicy = new AzureSasCredentialPolicy(azureSasCredential, false);
130130
} else if (sasToken != null) {

sdk/storage/azure-storage-file-share/src/test/java/com/azure/storage/file/share/DirectoryApiTests.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import com.azure.storage.common.StorageSharedKeyCredential;
1111
import com.azure.storage.common.implementation.Constants;
1212
import com.azure.storage.common.policy.RequestRetryOptions;
13+
import com.azure.storage.common.test.shared.extensions.LiveOnly;
1314
import com.azure.storage.common.test.shared.extensions.RequiredServiceVersion;
1415
import com.azure.storage.file.share.models.NfsFileType;
1516
import com.azure.storage.file.share.models.CloseHandlesInfo;
@@ -1719,8 +1720,10 @@ public void storageAccountAudience() {
17191720
assertTrue(aadDirClient.exists());
17201721
}
17211722

1723+
@RequiredServiceVersion(clazz = ShareServiceVersion.class, min = "2024-11-04")
1724+
@LiveOnly
17221725
@Test
1723-
public void audienceError() {
1726+
public void audienceErrorBearerChallengeRetry() {
17241727
String dirName = generatePathName();
17251728
ShareDirectoryClient dirClient = directoryBuilderHelper(shareName, dirName).buildDirectoryClient();
17261729
dirClient.create();
@@ -1729,8 +1732,7 @@ public void audienceError() {
17291732
.audience(ShareAudience.createShareServiceAccountAudience("badAudience")));
17301733

17311734
ShareDirectoryClient aadDirClient = oAuthServiceClient.getShareClient(shareName).getDirectoryClient(dirName);
1732-
ShareStorageException e = assertThrows(ShareStorageException.class, aadDirClient::exists);
1733-
assertEquals(ShareErrorCode.INVALID_AUTHENTICATION_INFO, e.getErrorCode());
1735+
assertNotNull(aadDirClient.exists());
17341736
}
17351737

17361738
@Test

sdk/storage/azure-storage-file-share/src/test/java/com/azure/storage/file/share/DirectoryAsyncApiTests.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import com.azure.core.http.rest.Response;
77
import com.azure.storage.common.StorageSharedKeyCredential;
88
import com.azure.storage.common.implementation.Constants;
9+
import com.azure.storage.common.test.shared.extensions.LiveOnly;
910
import com.azure.storage.common.test.shared.extensions.RequiredServiceVersion;
1011
import com.azure.storage.file.share.models.NfsFileType;
1112
import com.azure.storage.file.share.models.FilePermissionFormat;
@@ -24,6 +25,7 @@
2425
import com.azure.storage.file.share.options.ShareDirectoryCreateOptions;
2526
import com.azure.storage.file.share.options.ShareDirectorySetPropertiesOptions;
2627
import com.azure.storage.file.share.options.ShareFileRenameOptions;
28+
import org.junit.jupiter.api.Assertions;
2729
import org.junit.jupiter.api.BeforeEach;
2830
import org.junit.jupiter.api.Test;
2931
import org.junit.jupiter.params.ParameterizedTest;
@@ -1021,8 +1023,10 @@ public void storageAccountAudience() {
10211023
StepVerifier.create(createDirMono.then(aadDirClient.exists())).expectNext(true).verifyComplete();
10221024
}
10231025

1026+
@RequiredServiceVersion(clazz = ShareServiceVersion.class, min = "2024-11-04")
1027+
@LiveOnly
10241028
@Test
1025-
public void audienceError() {
1029+
public void audienceErrorBearerChallengeRetry() {
10261030
String dirName = generatePathName();
10271031
ShareDirectoryAsyncClient dirClient = directoryBuilderHelper(shareName, dirName).buildDirectoryAsyncClient();
10281032
Mono<ShareDirectoryInfo> createDirMono = dirClient.create();
@@ -1034,10 +1038,9 @@ public void audienceError() {
10341038
ShareDirectoryAsyncClient aadDirClient
10351039
= oAuthServiceClient.getShareAsyncClient(shareName).getDirectoryClient(dirName);
10361040

1037-
StepVerifier.create(createDirMono.then(aadDirClient.exists())).verifyErrorSatisfies(r -> {
1038-
ShareStorageException e = assertInstanceOf(ShareStorageException.class, r);
1039-
assertEquals(ShareErrorCode.INVALID_AUTHENTICATION_INFO, e.getErrorCode());
1040-
});
1041+
StepVerifier.create(createDirMono.then(aadDirClient.exists()))
1042+
.assertNext(Assertions::assertNotNull)
1043+
.verifyComplete();
10411044
}
10421045

10431046
@Test

sdk/storage/azure-storage-file-share/src/test/java/com/azure/storage/file/share/FileApiTests.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3021,8 +3021,10 @@ public void storageAccountAudience() {
30213021
assertTrue(aadFileClient.exists());
30223022
}
30233023

3024+
@RequiredServiceVersion(clazz = ShareServiceVersion.class, min = "2024-11-04")
3025+
@LiveOnly
30243026
@Test
3025-
public void audienceError() {
3027+
public void audienceErrorBearerChallengeRetry() {
30263028
String fileName = generatePathName();
30273029
ShareFileClient fileClient = fileBuilderHelper(shareName, fileName).buildFileClient();
30283030
fileClient.create(Constants.KB);
@@ -3031,8 +3033,7 @@ public void audienceError() {
30313033
.audience(ShareAudience.createShareServiceAccountAudience("badAudience")));
30323034

30333035
ShareFileClient aadFileClient = oAuthServiceClient.getShareClient(shareName).getFileClient(fileName);
3034-
ShareStorageException e = assertThrows(ShareStorageException.class, aadFileClient::exists);
3035-
assertEquals(ShareErrorCode.INVALID_AUTHENTICATION_INFO, e.getErrorCode());
3036+
assertNotNull(aadFileClient.exists());
30363037
}
30373038

30383039
@Test

sdk/storage/azure-storage-file-share/src/test/java/com/azure/storage/file/share/FileAsyncApiTests.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1797,8 +1797,10 @@ public void storageAccountAudience() {
17971797
.verifyComplete();
17981798
}
17991799

1800+
@RequiredServiceVersion(clazz = ShareServiceVersion.class, min = "2024-11-04")
1801+
@LiveOnly
18001802
@Test
1801-
public void audienceError() {
1803+
public void audienceErrorBearerChallengeRetry() {
18021804
String fileName = generatePathName();
18031805
ShareFileAsyncClient fileClient = fileBuilderHelper(shareName, fileName).buildFileAsyncClient();
18041806
ShareServiceAsyncClient oAuthServiceClient
@@ -1807,10 +1809,9 @@ public void audienceError() {
18071809

18081810
ShareFileAsyncClient aadFileClient = oAuthServiceClient.getShareAsyncClient(shareName).getFileClient(fileName);
18091811

1810-
StepVerifier.create(fileClient.create(Constants.KB).then(aadFileClient.exists())).verifyErrorSatisfies(r -> {
1811-
ShareStorageException e = assertInstanceOf(ShareStorageException.class, r);
1812-
assertEquals(ShareErrorCode.INVALID_AUTHENTICATION_INFO, e.getErrorCode());
1813-
});
1812+
StepVerifier.create(fileClient.create(Constants.KB).then(aadFileClient.exists()))
1813+
.assertNext(Assertions::assertNotNull)
1814+
.verifyComplete();
18141815
}
18151816

18161817
@Test

sdk/storage/azure-storage-file-share/src/test/java/com/azure/storage/file/share/ShareApiTests.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import com.azure.core.http.rest.Response;
1010
import com.azure.storage.common.StorageSharedKeyCredential;
1111
import com.azure.storage.common.implementation.Constants;
12+
import com.azure.storage.common.test.shared.extensions.LiveOnly;
1213
import com.azure.storage.common.test.shared.extensions.PlaybackOnly;
1314
import com.azure.storage.common.test.shared.extensions.RequiredServiceVersion;
1415
import com.azure.storage.file.share.implementation.util.ModelHelper;
@@ -1367,8 +1368,10 @@ public void storageAccountAudience() {
13671368
assertNotNull(infoPermission);
13681369
}
13691370

1371+
@RequiredServiceVersion(clazz = ShareServiceVersion.class, min = "2024-11-04")
1372+
@LiveOnly
13701373
@Test
1371-
public void audienceError() {
1374+
public void audienceErrorBearerChallengeRetry() {
13721375
primaryShareClient.create();
13731376
ShareClient aadShareClient = getOAuthShareClientBuilder(new ShareClientBuilder()).shareName(shareName)
13741377
.shareTokenIntent(ShareTokenIntent.BACKUP)
@@ -1379,9 +1382,7 @@ public void audienceError() {
13791382
+ "1604012920-1887927527-513D:AI(A;;FA;;;SY)(A;;FA;;;BA)(A;;0x1200a9;;;S-1-5-21-397955417-626881126-"
13801383
+ "188441444-3053964)S:NO_ACCESS_CONTROL";
13811384

1382-
ShareStorageException e
1383-
= assertThrows(ShareStorageException.class, () -> aadShareClient.createPermission(permission));
1384-
assertEquals(ShareErrorCode.INVALID_AUTHENTICATION_INFO, e.getErrorCode());
1385+
assertNotNull(aadShareClient.createPermission(permission));
13851386
}
13861387

13871388
@Test

sdk/storage/azure-storage-file-share/src/test/java/com/azure/storage/file/share/ShareAsyncApiTests.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import com.azure.core.http.rest.Response;
77
import com.azure.storage.common.StorageSharedKeyCredential;
88
import com.azure.storage.common.implementation.Constants;
9+
import com.azure.storage.common.test.shared.extensions.LiveOnly;
910
import com.azure.storage.common.test.shared.extensions.PlaybackOnly;
1011
import com.azure.storage.common.test.shared.extensions.RequiredServiceVersion;
1112
import com.azure.storage.file.share.implementation.util.ModelHelper;
@@ -992,8 +993,10 @@ public void storageAccountAudience() {
992993
.verifyComplete();
993994
}
994995

996+
@RequiredServiceVersion(clazz = ShareServiceVersion.class, min = "2024-11-04")
997+
@LiveOnly
995998
@Test
996-
public void audienceError() {
999+
public void audienceErrorBearerChallengeRetry() {
9971000
ShareAsyncClient aadShareClient = getOAuthShareClientBuilder(new ShareClientBuilder()).shareName(shareName)
9981001
.shareTokenIntent(ShareTokenIntent.BACKUP)
9991002
.audience(ShareAudience.createShareServiceAccountAudience("badaudience"))
@@ -1004,10 +1007,8 @@ public void audienceError() {
10041007
+ "188441444-3053964)S:NO_ACCESS_CONTROL";
10051008

10061009
StepVerifier.create(primaryShareAsyncClient.create().then(aadShareClient.createPermission(permission)))
1007-
.verifyErrorSatisfies(r -> {
1008-
ShareStorageException e = assertInstanceOf(ShareStorageException.class, r);
1009-
assertEquals(ShareErrorCode.INVALID_AUTHENTICATION_INFO, e.getErrorCode());
1010-
});
1010+
.assertNext(Assertions::assertNotNull)
1011+
.verifyComplete();
10111012
}
10121013

10131014
@Test

0 commit comments

Comments
 (0)