Skip to content

Commit c2c8942

Browse files
authored
Merge pull request #2026 from Danielle9897/RDoc-3304-fixPUtClientCertificateOp
RDoc-3304 Update PutClientCertificateOperation (null is not allowed)
2 parents c50bcf6 + fc1643d commit c2c8942

File tree

12 files changed

+197
-105
lines changed

12 files changed

+197
-105
lines changed
Lines changed: 35 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,47 @@
1-
# Operations: Server: How to Put a Client Certificate
1+
# Put Client Certificate Operation
2+
---
23

3-
You can register an existing client certificate using **PutClientCertificateOperation**.
4+
{NOTE: }
45

5-
## Syntax
6+
* Use `PutClientCertificateOperation` to register an existing client certificate.
67

7-
{CODE cert_put_1@ClientApi\Operations\Server\ClientCertificate.cs /}
8+
* To register an existing client certificate from the Studio,
9+
see [Upload an existing client certificate](../../../../studio/server/certificates/server-management-certificates-view#upload-an-existing-client-certificate).
810

9-
{CODE cert_1_2@ClientApi\Operations\Server\ClientCertificate.cs /}
11+
* In this article:
12+
* [Put client certificate example](../../../../client-api/operations/server-wide/certificates/put-client-certificate#put-client-certificate-example)
13+
* [Syntax](../../../../client-api/operations/server-wide/certificates/put-client-certificate#syntax)
1014

11-
{CODE cert_1_3@ClientApi\Operations\Server\ClientCertificate.cs /}
15+
{NOTE/}
1216

17+
---
1318

14-
| Parameters | | |
15-
| ------------- | ------------- | ----- |
16-
| **name** | string | Name of a certificate |
17-
| **certificate** | X509Certificate2 | Certificate to register |
18-
| **permissions** | Dictionary<string, DatabaseAccess> | Dictionary mapping databases to access level |
19-
| **clearance** | SecurityClearance | Access level |
19+
{PANEL: Put client certificate example}
2020

21-
## Example
21+
{CODE-TABS}
22+
{CODE-TAB:csharp:Sync put_client_certificate@ClientApi\Operations\Server\ClientCertificate.cs /}
23+
{CODE-TAB:csharp:Async put_client_certificate_async@ClientApi\Operations\Server\ClientCertificate.cs /}
24+
{CODE-TABS/}
2225

23-
{CODE cert_put_2@ClientApi\Operations\Server\ClientCertificate.cs /}
26+
{PANEL/}
2427

25-
## Related Articles
28+
{PANEL: Syntax}
29+
30+
{CODE put_syntax@ClientApi\Operations\Server\ClientCertificate.cs /}
31+
32+
| Parameter | Type | Description |
33+
|-----------------|--------------------------------------|-----------------------------------------------------------------------------------------------------|
34+
| **name** | `string` | A name for the certificate. |
35+
| **certificate** | `X509Certificate2` | The certificate to register. |
36+
| **permissions** | `Dictionary<string, DatabaseAccess>` | A dictionary mapping database name to access level.<br>Relevant only when clearance is `ValidUser`. |
37+
| **clearance** | `SecurityClearance` | Access level (role) assigned to the certificate. |
2638

27-
- [How to **delete** client certificate?](../../../../client-api/operations/server-wide/certificates/delete-certificate)
28-
- [How to **generate** client certificate?](../../../../client-api/operations/server-wide/certificates/create-client-certificate)
39+
{CODE cert_1_2@ClientApi\Operations\Server\ClientCertificate.cs /}
40+
{CODE cert_1_3@ClientApi\Operations\Server\ClientCertificate.cs /}
41+
42+
{PANEL/}
43+
44+
## Related Articles
2945

46+
- [Delete client certificate](../../../../client-api/operations/server-wide/certificates/delete-certificate)
47+
- [Generate client certificate](../../../../client-api/operations/server-wide/certificates/create-client-certificate)
Lines changed: 32 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,44 @@
1-
# Operations: Server: How to Put a Client Certificate
1+
# Put Client Certificate Operation
2+
---
23

3-
You can register an existing client certificate using **PutClientCertificateOperation**.
4+
{NOTE: }
45

5-
## Syntax
6+
* Use `PutClientCertificateOperation` to register an existing client certificate.
67

7-
{CODE:java cert_put_1@ClientApi\Operations\Server\ClientCertificate.java /}
8-
9-
{CODE:java cert_1_2@ClientApi\Operations\Server\ClientCertificate.java /}
8+
* To register an existing client certificate from the Studio,
9+
see [Upload an existing client certificate](../../../../studio/server/certificates/server-management-certificates-view#upload-an-existing-client-certificate).
1010

11-
{CODE:java cert_1_3@ClientApi\Operations\Server\ClientCertificate.java /}
11+
* In this article:
12+
* [Put client certificate example](../../../../client-api/operations/server-wide/certificates/put-client-certificate#put-client-certificate-example)
13+
* [Syntax](../../../../client-api/operations/server-wide/certificates/put-client-certificate#syntax)
1214

15+
{NOTE/}
1316

14-
| Parameters | | |
15-
| ------------- | ------------- | ----- |
16-
| **name** | String | Name of a certificate |
17-
| **certificate** | String | Certificate to register |
18-
| **permissions** | Map&lt;String, DatabaseAccess&gt; | Map with database to access level mapping |
19-
| **clearance** | SecurityClearance | Access level |
17+
---
2018

21-
## Example
19+
{PANEL: Put client certificate example}
2220

2321
{CODE:java cert_put_2@ClientApi\Operations\Server\ClientCertificate.java /}
2422

25-
## Related Articles
23+
{PANEL/}
24+
25+
{PANEL: Syntax}
26+
27+
{CODE:java cert_put_1@ClientApi\Operations\Server\ClientCertificate.java /}
28+
29+
| Parameter | Type | Description |
30+
|-----------------|-------------------------------|------------------------------------------------------------------------------------------------------|
31+
| **name** | `String` | A name for the certificate. |
32+
| **certificate** | `String` | The certificate to register. |
33+
| **permissions** | `Map<String, DatabaseAccess>` | A dictionary mapping database name to access level.<br>Relevant only when clearance is `VALID_USER`. |
34+
| **clearance** | `SecurityClearance` | Access level (role) assigned to the certificate. |
2635

27-
- [How to **delete** client certificate?](../../../../client-api/operations/server-wide/certificates/delete-certificate)
28-
- [How to **generate** client certificate?](../../../../client-api/operations/server-wide/certificates/create-client-certificate)
36+
{CODE:java cert_1_2@ClientApi\Operations\Server\ClientCertificate.java /}
37+
{CODE:java cert_1_3@ClientApi\Operations\Server\ClientCertificate.java /}
38+
39+
{PANEL/}
40+
41+
## Related Articles
2942

43+
- [Delete client certificate](../../../../client-api/operations/server-wide/certificates/delete-certificate)
44+
- [Generate client certificate](../../../../client-api/operations/server-wide/certificates/create-client-certificate)
Lines changed: 39 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,52 @@
1-
# Operations: Server: How to Put a Client Certificate
1+
# Put Client Certificate Operation
2+
---
23

3-
You can register an existing client certificate using **PutClientCertificateOperation**.
4+
{NOTE: }
45

5-
## Usage
6+
* Use `PutClientCertificateOperation` to register an existing client certificate.
67

7-
{CODE:nodejs cert_put_1@ClientApi\Operations\Server\ClientCertificate.js /}
8+
* To register an existing client certificate from the Studio,
9+
see [Upload an existing client certificate](../../../../studio/server/certificates/server-management-certificates-view#upload-an-existing-client-certificate).
810

9-
`SecurityClearance` options:
11+
* In this article:
12+
* [Put client certificate example](../../../../client-api/operations/server-wide/certificates/put-client-certificate#put-client-certificate-example)
13+
* [Syntax](../../../../client-api/operations/server-wide/certificates/put-client-certificate#syntax)
1014

11-
* `UnauthenticatedClients`
12-
* `ClusterAdmin`
13-
* `ClusterNode`
14-
* `Operator`
15-
* `ValidUser`
15+
{NOTE/}
1616

17-
`DatabaseAccess ` options:
17+
---
1818

19-
* `ReadWrite`
20-
* `Admin`
19+
{PANEL: Put client certificate example}
2120

22-
| Parameters | | |
23-
| ------------- | ------------- | ----- |
24-
| **name** | string | Name of a certificate |
25-
| **certificate** | string | Certificate to register |
26-
| **permissions** | Record<string, DatabaseAccess> | Dictionary mapping databases to access level |
27-
| **clearance** | SecurityClearance | Access level |
21+
{CODE:nodejs cert_put_2@ClientApi\Operations\Server\ClientCertificate.js /}
2822

29-
## Example
23+
{PANEL/}
3024

31-
{CODE:nodejs cert_put_2@ClientApi\Operations\Server\ClientCertificate.js /}
25+
{PANEL: Syntax}
3226

33-
## Related Articles
27+
{CODE:nodejs syntax@ClientApi\Operations\Server\ClientCertificate.js /}
28+
29+
| Parameter | Type | Description |
30+
|-----------------|----------------------------------|-----------------------------------------------------------------------------------------------------|
31+
| **name** | `string` | A name for the certificate. |
32+
| **certificate** | `string` | The certificate to register. |
33+
| **permissions** | `Record<string, DatabaseAccess>` | A dictionary mapping database name to access level.<br>Relevant only when clearance is `ValidUser`. |
34+
| **clearance** | `SecurityClearance` | Access level (role) assigned to the certificate. |
3435

35-
- [How to **delete** client certificate?](../../../../client-api/operations/server-wide/certificates/delete-certificate)
36-
- [How to **generate** client certificate?](../../../../client-api/operations/server-wide/certificates/create-client-certificate)
36+
* `SecurityClearance` options:
37+
* `ClusterAdmin`
38+
* `ClusterNode`
39+
* `Operator`
40+
* `ValidUser`
41+
42+
* `DatabaseAccess ` options:
43+
* `Read`
44+
* `ReadWrite`
45+
* `Admin`
46+
47+
{PANEL/}
48+
49+
## Related Articles
3750

51+
- [Delete client certificate](../../../../client-api/operations/server-wide/certificates/delete-certificate)
52+
- [Generate client certificate](../../../../client-api/operations/server-wide/certificates/create-client-certificate)

Documentation/5.2/Samples/csharp/Raven.Documentation.Samples/ClientApi/Operations/Server/ClientCertificate.cs

Lines changed: 37 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
using System.Collections.Generic;
22
using System.Security.Cryptography.X509Certificates;
3+
using System.Threading.Tasks;
34
using Raven.Client.Documents;
4-
using Raven.Client.ServerWide.Operations;
55
using Raven.Client.ServerWide.Operations.Certificates;
66

77
namespace Raven.Documentation.Samples.ClientApi.Operations.Server
88
{
9-
109
public class ClientCertificate
1110
{
1211
private interface IFoo
@@ -27,7 +26,7 @@ public GetCertificateOperation(string thumbprint)
2726
public GetCertificatesOperation(int start, int pageSize)
2827
#endregion
2928
30-
#region cert_put_1
29+
#region put_syntax
3130
public PutClientCertificateOperation(
3231
string name,
3332
X509Certificate2 certificate,
@@ -40,6 +39,7 @@ public PutClientCertificateOperation(
4039
private class Foo
4140
{
4241
#region cert_1_2
42+
// The role assigned to the certificate:
4343
public enum SecurityClearance
4444
{
4545
ClusterAdmin,
@@ -50,6 +50,7 @@ public enum SecurityClearance
5050
#endregion
5151

5252
#region cert_1_3
53+
// The access level for a 'ValidUser' security clearance:
5354
public enum DatabaseAccess
5455
{
5556
Read,
@@ -105,14 +106,43 @@ public ClientCertificate()
105106
store.Maintenance.Server.Send(new GetCertificatesOperation(0, 20));
106107
#endregion
107108
}
109+
}
110+
}
111+
112+
public async Task PutClientCertificate()
113+
{
114+
using (var store = new DocumentStore())
115+
{
116+
{
117+
#region put_client_certificate
118+
X509Certificate2 certificate = new X509Certificate2("c:\\path_to_pfx_file");
119+
120+
// Define the put client certificate operation
121+
var putClientCertificateOp = new PutClientCertificateOperation(
122+
"certificateName",
123+
certificate,
124+
new Dictionary<string, DatabaseAccess>(),
125+
SecurityClearance.ClusterAdmin);
126+
127+
// Execute the operation by passing it to Maintenance.Server.Send
128+
store.Maintenance.Server.Send(putClientCertificateOp);
129+
#endregion
130+
}
108131

109132
{
133+
#region put_client_certificate_async
110134

111-
#region cert_put_2
112135
X509Certificate2 certificate = new X509Certificate2("c:\\path_to_pfx_file");
113-
store.Maintenance.Server.Send(
114-
new PutClientCertificateOperation(
115-
"cert1", certificate, null, SecurityClearance.ClusterAdmin));
136+
137+
// Define the put client certificate operation
138+
var putClientCertificateOp = new PutClientCertificateOperation(
139+
"certificateName",
140+
certificate,
141+
new Dictionary<string, DatabaseAccess>(),
142+
SecurityClearance.ClusterAdmin);
143+
144+
// Execute the operation by passing it to Maintenance.Server.SendAsync
145+
await store.Maintenance.Server.SendAsync(putClientCertificateOp);
116146
#endregion
117147
}
118148
}

Documentation/5.2/Samples/java/src/test/java/net/ravendb/ClientApi/Operations/Server/ClientCertificate.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ public PutClientCertificateOperation(String name,
5252
private static class Foo {
5353
//region cert_1_2
5454
public enum SecurityClearance {
55-
UNAUTHENTICATED_CLIENTS,
5655
CLUSTER_ADMIN,
5756
CLUSTER_NODE,
5857
OPERATOR,
@@ -118,14 +117,14 @@ public ClientCertificate() {
118117

119118
try {
120119
//region cert_put_2
121-
Certificate certificate = keyStore.getCertificate("clientCert");
122-
String certificateAsBase64 = Base64.encodeBase64String(certificate.getEncoded());
120+
byte[] rawCert = Files.readAllBytes(Paths.get("<path-to-certificate.crt>"));
121+
String certificateAsBase64 = Base64.getEncoder().encodeToString(rawCert);
123122

124123
store.maintenance().server().send(
125124
new PutClientCertificateOperation(
126-
"cert1",
125+
"certificateName",
127126
certificateAsBase64,
128-
null,
127+
new HashMap<>(),
129128
SecurityClearance.CLUSTER_ADMIN));
130129
//endregion
131130
} catch (Exception e) {

Documentation/5.2/Samples/nodejs/ClientApi/Operations/Server/ClientCertificate.js

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ import {
44
DocumentStore,
55
PutClientCertificateOperation
66
} from 'ravendb';
7+
78
let urls, database, authOptions,permissions,clearance,password,certificate,publicKey,thumbprint;
9+
810
{
911
//document_store_creation
1012
const store = new DocumentStore(["http://localhost:8080"], "Northwind2");
@@ -16,11 +18,8 @@ let urls, database, authOptions,permissions,clearance,password,certificate,publi
1618
new CreateClientCertificateOperation([name], [permissions], [clearance], [password]));
1719
//endregion
1820

19-
20-
2121
async function foo1() {
2222

23-
2423
//region cert_1_4
2524
// With user role set to Cluster Administrator or Operator the user of this certificate
2625
// is going to have access to all databases
@@ -40,19 +39,27 @@ let urls, database, authOptions,permissions,clearance,password,certificate,publi
4039
const clientCertificateOperation = await store.maintenance.server.send(
4140
new CreateClientCertificateOperation("user1", clearance, "ValidUser", "myPassword"));
4241
const certificateRawData = clientCertificateOperation.rawData;
43-
4442
//endregion
4543

4644
async function foo2() {
47-
//region cert_put_1
48-
const putOperation = new PutClientCertificateOperation([name], [certificate], [permissions], [clearance]);
45+
//region syntax
46+
const putOperation =
47+
new PutClientCertificateOperation(name, certificate, permissions, clearance);
4948
//endregion
5049
}
5150

5251
async function foo3() {
5352
//region cert_put_2
54-
const putOperation = new PutClientCertificateOperation("cert1", publicKey, {}, "ClusterAdmin");
55-
await store.maintenance.server.send(putOperation);
53+
const rawCert = fs.readFileSync("<path-to-certificate.crt>");
54+
const certificateAsBase64 = rawCert.toString("base64");
55+
56+
const putClientCertificateOp = new PutClientCertificateOperation(
57+
"certificateName",
58+
certificateAsBase64,
59+
{},
60+
"ClusterAdmin");
61+
62+
await store.maintenance.server.send(putClientCertificateOp);
5663
//endregion
5764

5865
//region delete_cert_1

Documentation/5.4/Raven.Documentation.Pages/client-api/operations/server-wide/compact-database.dotnet.markdown

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
{NOTE: }
66

7-
* Use The `CompactDatabaseOperation` compaction operation to **removes empty gaps on disk**
7+
* Use the `CompactDatabaseOperation` compaction operation to **removes empty gaps on disk**
88
that still occupy space after deletes.
99
You can choose whether to compact _documents_ and/or _selected indexes_.
1010

Documentation/5.4/Raven.Documentation.Pages/client-api/operations/server-wide/compact-database.js.markdown

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
{NOTE: }
66

7-
* Use The `CompactDatabaseOperation` compaction operation to **removes empty gaps on disk**
7+
* Use the `CompactDatabaseOperation` compaction operation to **removes empty gaps on disk**
88
that still occupy space after deletes.
99
You can choose whether to compact _documents_ and/or _selected indexes_.
1010

Documentation/5.4/Raven.Documentation.Pages/client-api/operations/server-wide/compact-database.php.markdown

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
{NOTE: }
66

7-
* Use The `CompactDatabaseOperation` compaction operation to **removes empty gaps on disk**
7+
* Use the `CompactDatabaseOperation` compaction operation to **removes empty gaps on disk**
88
that still occupy space after deletes.
99
You can choose whether to compact _documents_ and/or _selected indexes_.
1010

0 commit comments

Comments
 (0)