Skip to content

Commit 41007d3

Browse files
authored
Certificate configuration for client libs (#31)
1 parent b238233 commit 41007d3

1 file changed

Lines changed: 65 additions & 0 deletions

File tree

docs/Authorization/AuthorizationBundle.md

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,71 @@ After creating the `AuthorizationManagementService` instance, the application mu
7979
The AMS client libraries integrate into different web frameworks, such as [CAP](https://cap.cloud.sap/docs/) or [Spring Security](https://spring.io/projects/spring-security). The respective [Spring Boot starters](/Authorization/GettingStarted#java) and [Node.js CAP plugin](/Authorization/GettingStarted#node-js) automatically create the `AuthorizationManagementService` instance from the SCI service binding in the application's environment, so manual initialization is not required in these cases.
8080
:::
8181

82+
### Certificate Configuration
83+
84+
For SAP BTP service bindings with `"credential-type": "X509_PROVIDED"` or `"credential-type": "X509_ATTESTED"`, the certificate and key required for mTLS authentication with AMS is not included in the service binding and must be provided by the application before the library instantiation.
85+
86+
::: tip X509_GENERATED
87+
SAP BTP service bindings with `"credential-type": "X509_GENERATED"` already contain the client certificate and key. No certificate configuration is needed in this case.
88+
:::
89+
90+
::: code-group
91+
92+
```js [Node.js]
93+
// Update the identityService object passed to
94+
// fromIdentityService with the certificate information.
95+
// cert and key must be PEM-encoded strings
96+
identityService.setCertificateAndKey(cert, key);
97+
98+
// then create the AMS instance as usual
99+
const ams = AuthorizationManagementService
100+
.fromIdentityService(identityService);
101+
```
102+
103+
```js [Node.js (CAP)]
104+
const { amsCapPluginRuntime } = require("@sap/ams");
105+
106+
// Update the credentials of the AMS CAP plugin runtime
107+
// with the certificate information.
108+
// cert and key must be PEM-encoded strings
109+
amsCapPluginRuntime.credentials = {
110+
...amsCapPluginRuntime.credentials,
111+
cert,
112+
key
113+
}
114+
```
115+
116+
```java [Java]
117+
import com.sap.cloud.security.ams.api.AuthorizationManagementService;
118+
import com.sap.cloud.security.ams.config.CloudAuthorizationManagementServiceConfig;
119+
import java.security.KeyStore;
120+
121+
// The KeyStore must contain exactly one private key entry with no password (empty password).
122+
KeyStore keyStore = // load KeyStore containing client certificate and private key
123+
124+
CloudAuthorizationManagementServiceConfig config = new CloudAuthorizationManagementServiceConfig()
125+
.withKeyStore(keyStore);
126+
127+
AuthorizationManagementService ams = AuthorizationManagementService
128+
.fromIdentityServiceBinding(identityServiceBinding, config);
129+
```
130+
131+
```java [Spring Boot]
132+
import org.springframework.context.annotation.Bean;
133+
import org.springframework.beans.factory.annotation.Qualifier;
134+
import java.security.KeyStore;
135+
136+
@Bean
137+
@Qualifier("amsKeyStore")
138+
public KeyStore amsKeyStore() {
139+
// The KeyStore must contain exactly one private key entry with no password (empty password).
140+
KeyStore keyStore = // load KeyStore containing client certificate and private key
141+
return keyStore;
142+
}
143+
```
144+
145+
:::
146+
82147
## Startup Check
83148

84149
While it is possible to synchronously block application startup until the AMS module becomes ready, we recommend including AMS in the application's **readiness probes**. This allows the application process to become healthy for the cloud platform but prevent traffic from being routed to the process until the AMS module is ready to serve authorization checks.

0 commit comments

Comments
 (0)