Skip to content

Commit 1a96ed6

Browse files
committed
Remove deprecated FilePasswordFilePath class
With the inclusion of FasterXML/jackson-databind#4327 in the new Jackson release, the deprecated class can be replaced with a JsonAlias annotation. Signed-off-by: kwall <[email protected]>
1 parent 3d40898 commit 1a96ed6

File tree

7 files changed

+16
-81
lines changed

7 files changed

+16
-81
lines changed

kroxylicious-api/src/main/java/io/kroxylicious/proxy/config/secret/FilePassword.java

+5-2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import java.nio.charset.StandardCharsets;
1414
import java.util.Objects;
1515

16+
import com.fasterxml.jackson.annotation.JsonAlias;
1617
import com.fasterxml.jackson.annotation.JsonProperty;
1718

1819
import edu.umd.cs.findbugs.annotations.NonNull;
@@ -21,10 +22,12 @@
2122
* A reference to the file containing a plain text password in UTF-8 encoding. If the password file
2223
* contains more than one line, only the characters of the first line are taken to be the password,
2324
* excluding the line ending. Subsequent lines are ignored.
25+
* <br>
26+
* Note that the {@code filePath} alias was deprecated at 0.5.0.
2427
*
25-
* @param passwordFile file containing the password,
28+
* @param passwordFile file containing the password.
2629
*/
27-
public record FilePassword(@JsonProperty(required = true) String passwordFile) implements PasswordProvider {
30+
public record FilePassword(@JsonProperty(required = true) @JsonAlias("filePath") String passwordFile) implements PasswordProvider {
2831

2932
public FilePassword {
3033
Objects.requireNonNull(passwordFile);

kroxylicious-api/src/main/java/io/kroxylicious/proxy/config/secret/FilePasswordFilePath.java

-48
This file was deleted.

kroxylicious-api/src/main/java/io/kroxylicious/proxy/config/secret/PasswordProvider.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* A PasswordProvider is an abstract source of a password.
1414
*/
1515
@JsonTypeInfo(use = JsonTypeInfo.Id.DEDUCTION)
16-
@JsonSubTypes({ @JsonSubTypes.Type(InlinePassword.class), @JsonSubTypes.Type(FilePassword.class), @JsonSubTypes.Type(FilePasswordFilePath.class) })
16+
@JsonSubTypes({ @JsonSubTypes.Type(InlinePassword.class), @JsonSubTypes.Type(FilePassword.class) })
1717
@SuppressWarnings("java:S5738") // java:S5738 warns of the use of the deprecated class.
1818
public interface PasswordProvider {
1919
String getProvidedPassword();

kroxylicious-api/src/test/java/io/kroxylicious/proxy/config/secret/FilePasswordTest.java

+8-18
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@
99
import java.io.File;
1010
import java.io.FileNotFoundException;
1111
import java.nio.file.Files;
12-
import java.util.List;
1312
import java.util.function.Function;
1413
import java.util.stream.Stream;
1514

1615
import org.assertj.core.api.Condition;
1716
import org.junit.jupiter.api.AfterEach;
1817
import org.junit.jupiter.api.BeforeEach;
18+
import org.junit.jupiter.api.Test;
1919
import org.junit.jupiter.params.ParameterizedTest;
2020
import org.junit.jupiter.params.provider.Arguments;
2121
import org.junit.jupiter.params.provider.MethodSource;
@@ -42,14 +42,10 @@ void afterEach() {
4242

4343
static Stream<Arguments> readPassword() {
4444
Function<String, PasswordProvider> filePassword = FilePassword::new;
45-
Function<String, PasswordProvider> filePasswordPath = FilePasswordFilePath::new;
4645
return Stream.of(
4746
Arguments.of(filePassword, "mypassword", "mypassword"),
4847
Arguments.of(filePassword, "mypassword\n", "mypassword"),
49-
Arguments.of(filePassword, "mypassword\nignores\nadditional lines", "mypassword"),
50-
Arguments.of(filePasswordPath, "mypassword", "mypassword"),
51-
Arguments.of(filePasswordPath, "mypassword\n", "mypassword"),
52-
Arguments.of(filePasswordPath, "mypassword\nignores\nadditional lines", "mypassword"));
48+
Arguments.of(filePassword, "mypassword\nignores\nadditional lines", "mypassword"));
5349
}
5450

5551
@ParameterizedTest
@@ -62,28 +58,22 @@ void readPassword(Function<String, PasswordProvider> providerFunc, String input,
6258
.isEqualTo(expected);
6359
}
6460

65-
static List<Function<String, PasswordProvider>> providers() {
66-
return List.of(FilePassword::new, FilePasswordFilePath::new);
67-
}
68-
69-
@ParameterizedTest
70-
@MethodSource("providers")
71-
void toStringDoesNotLeakPassword(Function<String, PasswordProvider> providerFunc) throws Exception {
61+
@Test
62+
void toStringDoesNotLeakPassword() throws Exception {
7263
var password = "mypassword";
7364
Files.writeString(file.toPath(), password);
74-
var provider = providerFunc.apply(file.getAbsolutePath());
65+
var provider = new FilePassword(file.getAbsolutePath());
7566
assertThat(provider)
7667
.extracting(Object::toString)
7768
.doesNotHave(new Condition<>(s -> s.contains(password), "contains password"));
7869
}
7970

80-
@ParameterizedTest
81-
@MethodSource("providers")
82-
void passwordFileNotFound(Function<String, PasswordProvider> providerFunc) {
71+
@Test
72+
void passwordFileNotFound() {
8373
assertThat(file.delete()).isTrue();
8474

8575
String path = file.getAbsolutePath();
86-
var provider = providerFunc.apply(path);
76+
var provider = new FilePassword(file.getAbsolutePath());
8777
assertThatThrownBy(provider::getProvidedPassword)
8878
.hasMessageContaining(path)
8979
.hasRootCauseInstanceOf(FileNotFoundException.class);

kroxylicious-api/src/test/java/io/kroxylicious/proxy/config/tls/TlsParseTest.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
import com.fasterxml.jackson.databind.exc.ValueInstantiationException;
1717

1818
import io.kroxylicious.proxy.config.secret.FilePassword;
19-
import io.kroxylicious.proxy.config.secret.FilePasswordFilePath;
2019
import io.kroxylicious.proxy.config.secret.InlinePassword;
2120

2221
import static org.assertj.core.api.Assertions.assertThat;
@@ -203,7 +202,7 @@ void testTrustStoreStoreFilePathPassword() throws IOException {
203202
}
204203
""";
205204
Tls tls = readTls(json);
206-
assertThat(tls).isEqualTo(new Tls(null, new TrustStore("/tmp/file", new FilePasswordFilePath("/tmp/pass"), null)));
205+
assertThat(tls).isEqualTo(new Tls(null, new TrustStore("/tmp/file", new FilePassword("/tmp/pass"), null)));
207206
}
208207

209208
@Test

kroxylicious-runtime/src/test/java/io/kroxylicious/proxy/config/tls/NettyKeyProviderTest.java

+1-5
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,7 @@
2828
import static io.kroxylicious.proxy.config.tls.TlsTestConstants.JKS;
2929
import static io.kroxylicious.proxy.config.tls.TlsTestConstants.KEYPASS;
3030
import static io.kroxylicious.proxy.config.tls.TlsTestConstants.KEYPASS_FILE_PASSWORD;
31-
import static io.kroxylicious.proxy.config.tls.TlsTestConstants.KEYPASS_FILE_PASSWORD_FILE_PATH;
3231
import static io.kroxylicious.proxy.config.tls.TlsTestConstants.KEYSTORE_FILE_PASSWORD;
33-
import static io.kroxylicious.proxy.config.tls.TlsTestConstants.KEYSTORE_FILE_PASSWORD_FILE_PATH;
3432
import static io.kroxylicious.proxy.config.tls.TlsTestConstants.NOT_EXIST;
3533
import static io.kroxylicious.proxy.config.tls.TlsTestConstants.PEM;
3634
import static io.kroxylicious.proxy.config.tls.TlsTestConstants.PKCS_12;
@@ -50,9 +48,7 @@ private static Stream<Arguments> withKeyStore() {
5048
Arguments.of("PKCS12", PKCS_12, "server.p12", STOREPASS, null),
5149
Arguments.of("Combined key/crt PEM passed as keyStore (KIP-651)", PEM, "server_key_crt.pem", null, null),
5250
Arguments.of("Combined key/crt PEM passed as keyStore (KIP-651) with encrypted key", PEM, "server_crt_encrypted_key.pem", null, KEYPASS),
53-
Arguments.of("JKS keystore from file", JKS, "server_diff_keypass.jks", KEYSTORE_FILE_PASSWORD, KEYPASS_FILE_PASSWORD),
54-
Arguments.of("JKS keystore from file (deprecated provider)", JKS, "server_diff_keypass.jks", KEYSTORE_FILE_PASSWORD_FILE_PATH,
55-
KEYPASS_FILE_PASSWORD_FILE_PATH));
51+
Arguments.of("JKS keystore from file", JKS, "server_diff_keypass.jks", KEYSTORE_FILE_PASSWORD, KEYPASS_FILE_PASSWORD));
5652
}
5753

5854
public static Stream<Arguments> serverWithKeyStore() {

kroxylicious-runtime/src/test/java/io/kroxylicious/proxy/config/tls/TlsTestConstants.java

-5
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
package io.kroxylicious.proxy.config.tls;
88

99
import io.kroxylicious.proxy.config.secret.FilePassword;
10-
import io.kroxylicious.proxy.config.secret.FilePasswordFilePath;
1110
import io.kroxylicious.proxy.config.secret.InlinePassword;
1211
import io.kroxylicious.proxy.config.secret.PasswordProvider;
1312

@@ -23,10 +22,6 @@ public class TlsTestConstants {
2322
static final PasswordProvider BADPASS = new InlinePassword("badpass");
2423
static final PasswordProvider KEYSTORE_FILE_PASSWORD = new FilePassword(getResourceLocationOnFilesystem("storepass.password"));
2524
static final PasswordProvider KEYPASS_FILE_PASSWORD = new FilePassword(getResourceLocationOnFilesystem("keypass.password"));
26-
@SuppressWarnings("java:S5738") // java:S5738 warns of the use of the deprecated class.
27-
static final PasswordProvider KEYSTORE_FILE_PASSWORD_FILE_PATH = new FilePasswordFilePath(getResourceLocationOnFilesystem("storepass.password"));
28-
@SuppressWarnings("java:S5738") // java:S5738 warns of the use of the deprecated class.
29-
static final PasswordProvider KEYPASS_FILE_PASSWORD_FILE_PATH = new FilePasswordFilePath(getResourceLocationOnFilesystem("keypass.password"));
3025

3126
public static final String NOT_EXIST = "/does/not/exist";
3227

0 commit comments

Comments
 (0)