-
Notifications
You must be signed in to change notification settings - Fork 2k
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 generating SAS tokens at the account and Table service level. #21944
Merged
Merged
Changes from 23 commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
e87fe2d
Added support for generating SAS tokens at the Account and Table Serv…
vcolin7 d4188f1
Added partition key and row key values for SAS generation.
vcolin7 0872d7e
Fixed CheckStyle issues.
vcolin7 5e401ed
Fixed SpotBugs issue.
vcolin7 aa9ec31
Removed more unused imports.
vcolin7 4144ec2
Renamed classes used for generating table-level SAS tokens. Made clie…
vcolin7 4e85675
Made client builders throw an IllegalStateException if more than one …
vcolin7 fa7eb98
Changed module-info.java to export the tables package to all other pa…
vcolin7 159c76a
Added tests for SAS models.
vcolin7 7578f7c
Added builder tests for when multiple forms of authentication are set.
vcolin7 a0dc7bc
Updated builders to throw when no endpoint or form of authentication …
vcolin7 385656a
Fixed CheckStyle issues.
vcolin7 62ec3ce
Fixed test name.
vcolin7 475bd88
Removed unnecessary exports for implementation packages in module-inf…
vcolin7 cd25daa
Applied PR feedback:
vcolin7 0d9820d
Added tests and renamed test classes to match clients and builders.
vcolin7 08e581d
Updated CHANGELOG and client builders' JavaDoc.
vcolin7 fc1cdf3
Applied APIView feedback.
vcolin7 893da5f
Updated CHANGELOG again.
vcolin7 d52aa73
Removed unused imports. Simplified SAS token comparison logic.
vcolin7 594bac2
Fixed SAS token generation at the table level. Re-ordered query param…
vcolin7 91786bb
Updated CHANGELOG.
vcolin7 44d20a2
Fixed test and CheckStyle issues.
vcolin7 096a492
Added @Immutable and @Fluent annotations where appropriate. Made more…
vcolin7 576b106
Added more @Immutable annotations.
vcolin7 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -26,11 +26,14 @@ | |||||
import com.azure.core.util.logging.ClientLogger; | ||||||
import com.azure.data.tables.implementation.CosmosPatchTransformPolicy; | ||||||
import com.azure.data.tables.implementation.NullHttpClient; | ||||||
import com.azure.data.tables.implementation.StorageAuthenticationSettings; | ||||||
import com.azure.data.tables.implementation.StorageConnectionString; | ||||||
|
||||||
import java.util.ArrayList; | ||||||
import java.util.List; | ||||||
import java.util.Map; | ||||||
import java.util.Objects; | ||||||
import java.util.StringJoiner; | ||||||
import java.util.stream.Collectors; | ||||||
import java.util.stream.Stream; | ||||||
|
||||||
|
@@ -51,12 +54,14 @@ static HttpPipeline buildPipeline( | |||||
retryPolicy = (retryPolicy == null) ? new RetryPolicy() : retryPolicy; | ||||||
logOptions = (logOptions == null) ? new HttpLogOptions() : logOptions; | ||||||
|
||||||
validateSingleCredentialIsPresent(azureNamedKeyCredential, azureSasCredential, sasToken, logger); | ||||||
|
||||||
// Closest to API goes first, closest to wire goes last. | ||||||
List<HttpPipelinePolicy> policies = new ArrayList<>(); | ||||||
|
||||||
if (endpoint.contains(COSMOS_ENDPOINT_SUFFIX)) { | ||||||
if (endpoint == null) { | ||||||
throw logger.logExceptionAsError( | ||||||
new IllegalStateException("An 'endpoint' is required to create a client. Use a builder's 'endpoint()'" | ||||||
+ " or 'connectionString()' methods to set this value.")); | ||||||
} else if (endpoint.contains(COSMOS_ENDPOINT_SUFFIX)) { | ||||||
policies.add(new CosmosPatchTransformPolicy()); | ||||||
} | ||||||
|
||||||
|
@@ -82,20 +87,22 @@ static HttpPipeline buildPipeline( | |||||
policies.add(retryPolicy); | ||||||
|
||||||
policies.add(new AddDatePolicy()); | ||||||
|
||||||
HttpPipelinePolicy credentialPolicy; | ||||||
|
||||||
if (azureNamedKeyCredential != null) { | ||||||
credentialPolicy = new TableAzureNamedKeyCredentialPolicy(azureNamedKeyCredential); | ||||||
} else if (azureSasCredential != null) { | ||||||
credentialPolicy = new AzureSasCredentialPolicy(azureSasCredential, false); | ||||||
} else if (sasToken != null) { | ||||||
credentialPolicy = new AzureSasCredentialPolicy(new AzureSasCredential(sasToken), false); | ||||||
} else { | ||||||
credentialPolicy = null; | ||||||
throw logger.logExceptionAsError( | ||||||
new IllegalStateException("A form of authentication is required to create a client. Use a builder's " | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
+ "'credential()', 'sasToken()' or 'connectionString()' methods to set a form of authentication.")); | ||||||
} | ||||||
|
||||||
if (credentialPolicy != null) { | ||||||
policies.add(credentialPolicy); | ||||||
} | ||||||
policies.add(credentialPolicy); | ||||||
|
||||||
// Add per retry additional policies. | ||||||
policies.addAll(perRetryAdditionalPolicies); | ||||||
|
@@ -121,17 +128,56 @@ static HttpPipeline buildNullClientPipeline() { | |||||
.build(); | ||||||
} | ||||||
|
||||||
private static void validateSingleCredentialIsPresent(AzureNamedKeyCredential azureNamedKeyCredential, | ||||||
AzureSasCredential azureSasCredential, String sasToken, | ||||||
ClientLogger logger) { | ||||||
List<Object> usedCredentials = Stream.of(azureNamedKeyCredential, azureSasCredential, sasToken) | ||||||
.filter(Objects::nonNull).collect(Collectors.toList()); | ||||||
static void validateCredentials(AzureNamedKeyCredential azureNamedKeyCredential, | ||||||
AzureSasCredential azureSasCredential, String sasToken, String connectionString, | ||||||
ClientLogger logger) { | ||||||
List<Object> usedCredentials = | ||||||
Stream.of(azureNamedKeyCredential, azureSasCredential, sasToken, connectionString) | ||||||
.filter(Objects::nonNull) | ||||||
.collect(Collectors.toList()); | ||||||
|
||||||
// Only allow two forms of authentication when 'connectionString' and 'sasToken' are provided. Validate that | ||||||
// both contain the same SAS settings. | ||||||
if (usedCredentials.size() == 2 && connectionString != null && sasToken != null) { | ||||||
StorageConnectionString storageConnectionString = | ||||||
StorageConnectionString.create(connectionString, logger); | ||||||
StorageAuthenticationSettings authSettings = storageConnectionString.getStorageAuthSettings(); | ||||||
|
||||||
if (authSettings.getType() == StorageAuthenticationSettings.Type.SAS_TOKEN) { | ||||||
if (sasToken.equals(authSettings.getSasToken())) { | ||||||
return; | ||||||
} else { | ||||||
throw logger.logExceptionAsError(new IllegalStateException("'connectionString' contains a SAS token" | ||||||
+ " with different settings than 'sasToken'.")); | ||||||
} | ||||||
} | ||||||
|
||||||
// If the 'connectionString' auth type is not SAS_TOKEN and a 'sasToken' was provided, then multiplte | ||||||
// incompatible forms of authentication were specified in the client builder. | ||||||
} | ||||||
|
||||||
if (usedCredentials.size() > 1) { | ||||||
StringJoiner usedCredentialsStringBuilder = new StringJoiner(", "); | ||||||
|
||||||
if (azureNamedKeyCredential != null) { | ||||||
usedCredentialsStringBuilder.add("azureNamedKeyCredential"); | ||||||
} | ||||||
|
||||||
if (azureSasCredential != null) { | ||||||
usedCredentialsStringBuilder.add("azureSasCredential"); | ||||||
} | ||||||
|
||||||
if (sasToken != null) { | ||||||
usedCredentialsStringBuilder.add("sasToken"); | ||||||
} | ||||||
|
||||||
if (connectionString != null) { | ||||||
usedCredentialsStringBuilder.add("connectionString"); | ||||||
} | ||||||
|
||||||
throw logger.logExceptionAsError(new IllegalStateException( | ||||||
"Only one credential should be used. Credentials present: " | ||||||
+ usedCredentials.stream().map(c -> c instanceof String ? "sasToken" : c.getClass().getName()) | ||||||
.collect(Collectors.joining(",")) | ||||||
)); | ||||||
"Only one form of authentication should be used. The authentication forms present are: " | ||||||
+ usedCredentialsStringBuilder + ".")); | ||||||
} | ||||||
} | ||||||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.