Skip to content

Commit

Permalink
Switched to records
Browse files Browse the repository at this point in the history
  • Loading branch information
Hakky54 committed Sep 9, 2024
1 parent a94cfea commit 110ca15
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 95 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
) {

}

Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -30,23 +32,26 @@
@RestController
public class AdminController {

private static final Logger LOGGER = LoggerFactory.getLogger(AdminController.class);

private final SSLFactory baseSslFactory;

public AdminController(SSLFactory baseSslFactory) {
this.baseSslFactory = 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");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
) {

}

0 comments on commit 110ca15

Please sign in to comment.