Skip to content
This repository was archived by the owner on Sep 16, 2024. It is now read-only.

Commit 6307a34

Browse files
committed
#231 Added SecurityManager
1 parent c04ee6f commit 6307a34

File tree

2 files changed

+81
-0
lines changed

2 files changed

+81
-0
lines changed
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package com.marklogic.mgmt.resource.security;
2+
3+
import com.marklogic.client.ext.helper.LoggingObject;
4+
import com.marklogic.mgmt.ManageClient;
5+
import org.springframework.http.ResponseEntity;
6+
7+
public class SecurityManager extends LoggingObject {
8+
9+
private ManageClient manageClient;
10+
11+
public SecurityManager(ManageClient client) {
12+
this.manageClient = client;
13+
}
14+
15+
public ResponseEntity<String> rotateConfigEncryptionKey() {
16+
return postJson("{\"operation\":\"rotate-config-encryption-key\"}");
17+
}
18+
19+
public ResponseEntity<String> rotateDateEncryptionKey() {
20+
return postJson("{\"operation\":\"rotate-data-encryption-key\"}");
21+
}
22+
23+
public ResponseEntity<String> rotateLogsEncryptionKey() {
24+
return postJson("{\"operation\":\"rotate-logs-encryption-key\"}");
25+
}
26+
27+
public ResponseEntity<String> importWallet(String filename, String password) {
28+
String json = format(
29+
"{\"operation\":\"import-wallet\", \"filename\":\"%s\", \"password\":\"%s\"}",
30+
filename, password);
31+
return postJson(json);
32+
}
33+
34+
public ResponseEntity<String> exportWallet(String filename, String password) {
35+
String json = format(
36+
"{\"operation\":\"export-wallet\", \"filename\":\"%s\", \"password\":\"%s\"}",
37+
filename, password);
38+
return postJson(json);
39+
}
40+
41+
private ResponseEntity<String> postJson(String json) {
42+
return manageClient.postJson("/manage/v2/security", json);
43+
}
44+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package com.marklogic.mgmt.resource.security;
2+
3+
import com.marklogic.mgmt.AbstractMgmtTest;
4+
import org.junit.Before;
5+
import org.junit.Test;
6+
7+
/**
8+
* This is really just a smoke test, as testing these for real would involve setting up encryption keys and verifying
9+
* that they're rotated correctly.
10+
*
11+
* It also doesn't yet have tests for importing or exporting a wallet
12+
*/
13+
public class SecurityManagerTest extends AbstractMgmtTest {
14+
15+
private SecurityManager securityManager;
16+
17+
@Before
18+
public void setup() {
19+
securityManager = new SecurityManager(super.manageClient);
20+
}
21+
22+
@Test
23+
public void rotateConfigEncryptionKey() {
24+
assertEquals(200, securityManager.rotateConfigEncryptionKey().getStatusCodeValue());
25+
}
26+
27+
@Test
28+
public void rotateDateEncryptionKey() {
29+
assertEquals(200, securityManager.rotateDateEncryptionKey().getStatusCodeValue());
30+
}
31+
32+
@Test
33+
public void rotateLogsEncryptionKey() {
34+
assertEquals(200, securityManager.rotateLogsEncryptionKey().getStatusCodeValue());
35+
}
36+
37+
}

0 commit comments

Comments
 (0)