Skip to content

Commit 110ca15

Browse files
committed
Switched to records
1 parent a94cfea commit 110ca15

File tree

3 files changed

+23
-95
lines changed

3 files changed

+23
-95
lines changed

Diff for: instant-server-ssl-reloading/admin/src/main/java/nl/altindag/admin/model/SSLUpdateRequest.java

+7-45
Original file line numberDiff line numberDiff line change
@@ -15,52 +15,14 @@
1515
*/
1616
package nl.altindag.admin.model;
1717

18-
public class SSLUpdateRequest {
18+
public record SSLUpdateRequest(
1919

20-
private byte[] keyStore;
21-
private char[] keyStorePassword;
22-
private byte[] trustStore;
23-
private char[] trustStorePassword;
20+
byte[] keyStore,
21+
char[] keyStorePassword,
22+
byte[] trustStore,
23+
char[] trustStorePassword
2424

25-
public SSLUpdateRequest() {}
26-
27-
public SSLUpdateRequest(byte[] keyStore, char[] keyStorePassword, byte[] trustStore, char[] trustStorePassword) {
28-
this.keyStore = keyStore;
29-
this.keyStorePassword = keyStorePassword;
30-
this.trustStore = trustStore;
31-
this.trustStorePassword = trustStorePassword;
32-
}
33-
34-
public byte[] getKeyStore() {
35-
return keyStore;
36-
}
37-
38-
public void setKeyStore(byte[] keyStore) {
39-
this.keyStore = keyStore;
40-
}
41-
42-
public char[] getKeyStorePassword() {
43-
return keyStorePassword;
44-
}
45-
46-
public void setKeyStorePassword(char[] keyStorePassword) {
47-
this.keyStorePassword = keyStorePassword;
48-
}
49-
50-
public byte[] getTrustStore() {
51-
return trustStore;
52-
}
53-
54-
public void setTrustStore(byte[] trustStore) {
55-
this.trustStore = trustStore;
56-
}
57-
58-
public char[] getTrustStorePassword() {
59-
return trustStorePassword;
60-
}
61-
62-
public void setTrustStorePassword(char[] trustStorePassword) {
63-
this.trustStorePassword = trustStorePassword;
64-
}
25+
) {
6526

6627
}
28+

Diff for: instant-server-ssl-reloading/server/src/main/java/nl/altindag/server/controller/AdminController.java

+10-5
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
import nl.altindag.server.model.SSLUpdateRequest;
1919
import nl.altindag.ssl.SSLFactory;
2020
import nl.altindag.ssl.util.SSLFactoryUtils;
21+
import org.slf4j.Logger;
22+
import org.slf4j.LoggerFactory;
2123
import org.springframework.http.MediaType;
2224
import org.springframework.web.bind.annotation.PostMapping;
2325
import org.springframework.web.bind.annotation.RequestBody;
@@ -30,23 +32,26 @@
3032
@RestController
3133
public class AdminController {
3234

35+
private static final Logger LOGGER = LoggerFactory.getLogger(AdminController.class);
36+
3337
private final SSLFactory baseSslFactory;
3438

3539
public AdminController(SSLFactory baseSslFactory) {
3640
this.baseSslFactory = baseSslFactory;
3741
}
3842

3943
@PostMapping(value = "/admin/ssl", consumes = MediaType.APPLICATION_JSON_VALUE)
40-
public void updateKeyManager(@RequestBody SSLUpdateRequest request) throws IOException {
41-
try (InputStream keyStoreStream = new ByteArrayInputStream(request.getKeyStore());
42-
InputStream trustStoreStream = new ByteArrayInputStream(request.getTrustStore())) {
44+
public void updateSslMaterial(@RequestBody SSLUpdateRequest request) throws IOException {
45+
try (InputStream keyStoreStream = new ByteArrayInputStream(request.keyStore());
46+
InputStream trustStoreStream = new ByteArrayInputStream(request.trustStore())) {
4347

4448
SSLFactory updatedSslFactory = SSLFactory.builder()
45-
.withIdentityMaterial(keyStoreStream, request.getKeyStorePassword())
46-
.withTrustMaterial(trustStoreStream, request.getTrustStorePassword())
49+
.withIdentityMaterial(keyStoreStream, request.keyStorePassword())
50+
.withTrustMaterial(trustStoreStream, request.trustStorePassword())
4751
.build();
4852

4953
SSLFactoryUtils.reload(baseSslFactory, updatedSslFactory);
54+
LOGGER.info("Updated server ssl material");
5055
}
5156
}
5257

Diff for: instant-server-ssl-reloading/server/src/main/java/nl/altindag/server/model/SSLUpdateRequest.java

+6-45
Original file line numberDiff line numberDiff line change
@@ -15,52 +15,13 @@
1515
*/
1616
package nl.altindag.server.model;
1717

18-
public class SSLUpdateRequest {
18+
public record SSLUpdateRequest(
1919

20-
private byte[] keyStore;
21-
private char[] keyStorePassword;
22-
private byte[] trustStore;
23-
private char[] trustStorePassword;
20+
byte[] keyStore,
21+
char[] keyStorePassword,
22+
byte[] trustStore,
23+
char[] trustStorePassword
2424

25-
public SSLUpdateRequest() {}
26-
27-
public SSLUpdateRequest(byte[] keyStore, char[] keyStorePassword, byte[] trustStore, char[] trustStorePassword) {
28-
this.keyStore = keyStore;
29-
this.keyStorePassword = keyStorePassword;
30-
this.trustStore = trustStore;
31-
this.trustStorePassword = trustStorePassword;
32-
}
33-
34-
public byte[] getKeyStore() {
35-
return keyStore;
36-
}
37-
38-
public void setKeyStore(byte[] keyStore) {
39-
this.keyStore = keyStore;
40-
}
41-
42-
public char[] getKeyStorePassword() {
43-
return keyStorePassword;
44-
}
45-
46-
public void setKeyStorePassword(char[] keyStorePassword) {
47-
this.keyStorePassword = keyStorePassword;
48-
}
49-
50-
public byte[] getTrustStore() {
51-
return trustStore;
52-
}
53-
54-
public void setTrustStore(byte[] trustStore) {
55-
this.trustStore = trustStore;
56-
}
57-
58-
public char[] getTrustStorePassword() {
59-
return trustStorePassword;
60-
}
61-
62-
public void setTrustStorePassword(char[] trustStorePassword) {
63-
this.trustStorePassword = trustStorePassword;
64-
}
25+
) {
6526

6627
}

0 commit comments

Comments
 (0)