-
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
Implement a Service Bus Shared Access Key Credential #21227
Changes from 10 commits
645acce
508bae6
703ca1b
0fe6904
d3a195c
9bd997a
44352f8
cfc073b
9201014
350c8ac
836afdc
78c871e
b19e829
4c415d8
f92c3a1
11a4355
10e81d8
c2af928
c7fa9ad
31f8817
0b1aa14
ecd7d0a
b7e204c
b1c5492
ea0f81e
20d9f27
4c0ab95
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,8 @@ | |
import com.azure.core.amqp.implementation.TracerProvider; | ||
import com.azure.core.annotation.ServiceClientBuilder; | ||
import com.azure.core.annotation.ServiceClientProtocol; | ||
import com.azure.core.credential.AzureNamedKeyCredential; | ||
import com.azure.core.credential.AzureSasCredential; | ||
import com.azure.core.credential.TokenCredential; | ||
import com.azure.core.exception.AzureException; | ||
import com.azure.core.util.ClientOptions; | ||
|
@@ -235,6 +237,55 @@ public ServiceBusClientBuilder credential(String fullyQualifiedNamespace, TokenC | |
return this; | ||
} | ||
|
||
/** | ||
* Sets the credential for the Service Bus resource. | ||
* | ||
* @param fullyQualifiedNamespace for the Service Bus. | ||
* @param credential {@link TokenCredential} to be used for authentication. | ||
v-xuto marked this conversation as resolved.
Show resolved
Hide resolved
|
||
* | ||
* @return The updated {@link ServiceBusClientBuilder} object. | ||
*/ | ||
public ServiceBusClientBuilder credential(String fullyQualifiedNamespace, AzureNamedKeyCredential credential) { | ||
|
||
this.fullyQualifiedNamespace = Objects.requireNonNull(fullyQualifiedNamespace, | ||
"'fullyQualifiedNamespace' cannot be null."); | ||
Objects.requireNonNull(credential, "'credential' cannot be null."); | ||
|
||
this.credentials = new ServiceBusSharedKeyCredential(credential.getAzureNamedKey().getName(), | ||
credential.getAzureNamedKey().getKey(), ServiceBusConstants.TOKEN_VALIDITY); | ||
|
||
if (CoreUtils.isNullOrEmpty(fullyQualifiedNamespace)) { | ||
throw logger.logExceptionAsError( | ||
new IllegalArgumentException("'fullyQualifiedNamespace' cannot be an empty string.")); | ||
} | ||
Comment on lines
+257
to
+260
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. All input validation should happen before performing any operations on the input. Here 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. According to your comment, fixed in the new version. |
||
|
||
return this; | ||
} | ||
|
||
/** | ||
* Sets the credential for the Service Bus resource. | ||
* | ||
* @param fullyQualifiedNamespace for the Service Bus. | ||
* @param credential {@link TokenCredential} to be used for authentication. | ||
* | ||
* @return The updated {@link ServiceBusClientBuilder} object. | ||
*/ | ||
public ServiceBusClientBuilder credential(String fullyQualifiedNamespace, AzureSasCredential credential) { | ||
|
||
this.fullyQualifiedNamespace = Objects.requireNonNull(fullyQualifiedNamespace, | ||
"'fullyQualifiedNamespace' cannot be null."); | ||
Objects.requireNonNull(credential, "'credential' cannot be null."); | ||
|
||
this.credentials = new ServiceBusSharedKeyCredential(credential.getSignature()); | ||
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. This overwrites the value set in the previous overload. So, the order of calls to 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. According to your comment, fixed in the new version. |
||
|
||
if (CoreUtils.isNullOrEmpty(fullyQualifiedNamespace)) { | ||
throw logger.logExceptionAsError( | ||
new IllegalArgumentException("'fullyQualifiedNamespace' cannot be an empty string.")); | ||
} | ||
|
||
return this; | ||
} | ||
|
||
/** | ||
* Sets the proxy configuration to use for {@link ServiceBusSenderAsyncClient}. When a proxy is configured, {@link | ||
* AmqpTransportType#AMQP_WEB_SOCKETS} must be used for the transport type. | ||
|
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.
Add more details to javadoc on how to obtain named key credential and sas credential for the next method.
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.
According to your comment, fixed in the new version.