diff --git a/instant-server-ssl-reloading/admin/src/main/java/nl/altindag/admin/model/SSLUpdateRequest.java b/instant-server-ssl-reloading/admin/src/main/java/nl/altindag/admin/model/SSLUpdateRequest.java index 3177c8a..d37822b 100644 --- a/instant-server-ssl-reloading/admin/src/main/java/nl/altindag/admin/model/SSLUpdateRequest.java +++ b/instant-server-ssl-reloading/admin/src/main/java/nl/altindag/admin/model/SSLUpdateRequest.java @@ -15,52 +15,14 @@ */ package nl.altindag.admin.model; -public class SSLUpdateRequest { +public record SSLUpdateRequest( - private byte[] keyStore; - private char[] keyStorePassword; - private byte[] trustStore; - private char[] trustStorePassword; + byte[] keyStore, + char[] keyStorePassword, + byte[] trustStore, + char[] trustStorePassword - public SSLUpdateRequest() {} - - public SSLUpdateRequest(byte[] keyStore, char[] keyStorePassword, byte[] trustStore, char[] trustStorePassword) { - this.keyStore = keyStore; - this.keyStorePassword = keyStorePassword; - this.trustStore = trustStore; - this.trustStorePassword = trustStorePassword; - } - - public byte[] getKeyStore() { - return keyStore; - } - - public void setKeyStore(byte[] keyStore) { - this.keyStore = keyStore; - } - - public char[] getKeyStorePassword() { - return keyStorePassword; - } - - public void setKeyStorePassword(char[] keyStorePassword) { - this.keyStorePassword = keyStorePassword; - } - - public byte[] getTrustStore() { - return trustStore; - } - - public void setTrustStore(byte[] trustStore) { - this.trustStore = trustStore; - } - - public char[] getTrustStorePassword() { - return trustStorePassword; - } - - public void setTrustStorePassword(char[] trustStorePassword) { - this.trustStorePassword = trustStorePassword; - } +) { } + diff --git a/instant-server-ssl-reloading/server/src/main/java/nl/altindag/server/controller/AdminController.java b/instant-server-ssl-reloading/server/src/main/java/nl/altindag/server/controller/AdminController.java index 53fbb51..858d57d 100644 --- a/instant-server-ssl-reloading/server/src/main/java/nl/altindag/server/controller/AdminController.java +++ b/instant-server-ssl-reloading/server/src/main/java/nl/altindag/server/controller/AdminController.java @@ -18,6 +18,8 @@ import nl.altindag.server.model.SSLUpdateRequest; import nl.altindag.ssl.SSLFactory; import nl.altindag.ssl.util.SSLFactoryUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.http.MediaType; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; @@ -30,6 +32,8 @@ @RestController public class AdminController { + private static final Logger LOGGER = LoggerFactory.getLogger(AdminController.class); + private final SSLFactory baseSslFactory; public AdminController(SSLFactory baseSslFactory) { @@ -37,16 +41,17 @@ public AdminController(SSLFactory baseSslFactory) { } @PostMapping(value = "/admin/ssl", consumes = MediaType.APPLICATION_JSON_VALUE) - public void updateKeyManager(@RequestBody SSLUpdateRequest request) throws IOException { - try (InputStream keyStoreStream = new ByteArrayInputStream(request.getKeyStore()); - InputStream trustStoreStream = new ByteArrayInputStream(request.getTrustStore())) { + public void updateSslMaterial(@RequestBody SSLUpdateRequest request) throws IOException { + try (InputStream keyStoreStream = new ByteArrayInputStream(request.keyStore()); + InputStream trustStoreStream = new ByteArrayInputStream(request.trustStore())) { SSLFactory updatedSslFactory = SSLFactory.builder() - .withIdentityMaterial(keyStoreStream, request.getKeyStorePassword()) - .withTrustMaterial(trustStoreStream, request.getTrustStorePassword()) + .withIdentityMaterial(keyStoreStream, request.keyStorePassword()) + .withTrustMaterial(trustStoreStream, request.trustStorePassword()) .build(); SSLFactoryUtils.reload(baseSslFactory, updatedSslFactory); + LOGGER.info("Updated server ssl material"); } } diff --git a/instant-server-ssl-reloading/server/src/main/java/nl/altindag/server/model/SSLUpdateRequest.java b/instant-server-ssl-reloading/server/src/main/java/nl/altindag/server/model/SSLUpdateRequest.java index 6a66aba..ce07dce 100644 --- a/instant-server-ssl-reloading/server/src/main/java/nl/altindag/server/model/SSLUpdateRequest.java +++ b/instant-server-ssl-reloading/server/src/main/java/nl/altindag/server/model/SSLUpdateRequest.java @@ -15,52 +15,13 @@ */ package nl.altindag.server.model; -public class SSLUpdateRequest { +public record SSLUpdateRequest( - private byte[] keyStore; - private char[] keyStorePassword; - private byte[] trustStore; - private char[] trustStorePassword; + byte[] keyStore, + char[] keyStorePassword, + byte[] trustStore, + char[] trustStorePassword - public SSLUpdateRequest() {} - - public SSLUpdateRequest(byte[] keyStore, char[] keyStorePassword, byte[] trustStore, char[] trustStorePassword) { - this.keyStore = keyStore; - this.keyStorePassword = keyStorePassword; - this.trustStore = trustStore; - this.trustStorePassword = trustStorePassword; - } - - public byte[] getKeyStore() { - return keyStore; - } - - public void setKeyStore(byte[] keyStore) { - this.keyStore = keyStore; - } - - public char[] getKeyStorePassword() { - return keyStorePassword; - } - - public void setKeyStorePassword(char[] keyStorePassword) { - this.keyStorePassword = keyStorePassword; - } - - public byte[] getTrustStore() { - return trustStore; - } - - public void setTrustStore(byte[] trustStore) { - this.trustStore = trustStore; - } - - public char[] getTrustStorePassword() { - return trustStorePassword; - } - - public void setTrustStorePassword(char[] trustStorePassword) { - this.trustStorePassword = trustStorePassword; - } +) { }