Skip to content

Commit ab7d65a

Browse files
authored
Update readme and throw exception for abnormal http status codes (Azure#44544)
1 parent 142408f commit ab7d65a

File tree

3 files changed

+24
-11
lines changed

3 files changed

+24
-11
lines changed

sdk/keyvault/azure-security-keyvault-jca/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
### Breaking Changes
88

99
### Bugs Fixed
10+
- Fixed bug: Missing logging for abnormal http status codes when processing HTTP responses. [#42859](https://github.com/Azure/azure-sdk-for-java/issues/42859).
1011

1112
### Other Changes
1213

sdk/keyvault/azure-security-keyvault-jca/README.md

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,20 @@ Azure Key Vault. It is built on four principles:
1010
[Source code] | [API reference documentation] | [Product documentation] | [Samples]
1111

1212
## Getting started
13+
14+
### Prerequisites
15+
- A [Java Development Kit (JDK)][jdk_link], version 8 or later.
16+
- Here are details about [Java 8 client compatibility with Azure Certificate Authority](https://learn.microsoft.com/azure/security/fundamentals/azure-ca-details?tabs=root-and-subordinate-cas-list#client-compatibility-for-public-pkis).
17+
- [Azure Subscription][azure_subscription]
18+
- An existing [Azure Key Vault][azure_keyvault]. If you need to create a Key Vault, you can use the [Azure Cloud Shell][azure_cloud_shell] to create one with this Azure CLI command. Replace `<your-resource-group-name>` and `<your-key-vault-name>` with your own, unique names:
19+
20+
```Bash
21+
az keyvault create --resource-group <your-resource-group-name> --name <your-key-vault-name>
22+
```
23+
- Access configuration:
24+
- If using [role-based](https://learn.microsoft.com/azure/key-vault/general/rbac-guide) access, assign the roles: `Key Vault Secrets User` and `Key Vault Certificate User`. If used for Jar signing, add role `Key Vault Crypto User`.
25+
- If using [access policy](https://learn.microsoft.com/azure/key-vault/general/assign-access-policy), add the permissions: `get` and `list` Secret permissions, `get` and `list` Certificate permissions. If used for Jar signing, add `Sign` Cryptographic Operations.
26+
1327
### Include the package
1428

1529
#### Include the BOM file
@@ -55,16 +69,6 @@ add the direct dependency to your project as follows.
5569
```
5670
[//]: # ({x-version-update-end})
5771

58-
### Prerequisites
59-
- A [Java Development Kit (JDK)][jdk_link], version 8 or later.
60-
- Here are details about [Java 8 client compatibility with Azure Certificate Authority](https://learn.microsoft.com/azure/security/fundamentals/azure-ca-details?tabs=root-and-subordinate-cas-list#client-compatibility-for-public-pkis).
61-
- [Azure Subscription][azure_subscription]
62-
- An existing [Azure Key Vault][azure_keyvault]. If you need to create a Key Vault, you can use the [Azure Cloud Shell][azure_cloud_shell] to create one with this Azure CLI command. Replace `<your-resource-group-name>` and `<your-key-vault-name>` with your own, unique names:
63-
64-
```Bash
65-
az keyvault create --resource-group <your-resource-group-name> --name <your-key-vault-name>
66-
```
67-
6872
## Key concepts
6973
### SSL/TLS and mTLS
7074
The JCA library supports SSL/TLS and mTLS (Mutual TLS) to enhance security in secure communication channels. It enables applications to securely retrieve certificates from Azure Key Vault and use them for TLS-related operations.

sdk/keyvault/azure-security-keyvault-jca/src/main/java/com/azure/security/keyvault/jca/implementation/utils/HttpUtil.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
import java.util.logging.Logger;
3737
import java.util.stream.Stream;
3838

39+
import static java.util.logging.Level.SEVERE;
3940
import static java.util.logging.Level.WARNING;
4041

4142
/**
@@ -139,11 +140,18 @@ public static HttpResponse getWithResponse(String uri, Map<String, String> heade
139140
private static ResponseHandler<String> createResponseHandler() {
140141
return (HttpResponse response) -> {
141142
int status = response.getStatusLine().getStatusCode();
142-
String result = null;
143+
String result;
143144

144145
if (status >= 200 && status < 300) {
145146
HttpEntity entity = response.getEntity();
146147
result = entity != null ? EntityUtils.toString(entity) : null;
148+
} else {
149+
String errorMessage = "Fail to get response from Key Vault because return http status code is " + status
150+
+ ". It "
151+
+ "can be caused by missing permissions or roles. To know how to add permissions or roles, see "
152+
+ "https://github.com/Azure/azure-sdk-for-java/tree/main/sdk/keyvault/azure-security-keyvault-jca#prerequisites.";
153+
LOGGER.log(SEVERE, errorMessage);
154+
throw new RuntimeException(errorMessage);
147155
}
148156

149157
return result;

0 commit comments

Comments
 (0)