Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added try-with-resource to address potential resource leak #1

Merged
merged 2 commits into from
Mar 3, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,10 @@ private static byte[] parsePEMFile(File pemFile) throws IOException {
throw new FileNotFoundException(
String.format(Constants.FILE_NOT_EXISTS, pemFile.getAbsolutePath()));
}
PemReader reader = new PemReader(new FileReader(pemFile));
PemObject pemObject = reader.readPemObject();
byte[] content = pemObject.getContent();
reader.close();
return content;
try (PemReader reader = new PemReader(new FileReader(pemFile))) {
PemObject pemObject = reader.readPemObject();
return pemObject.getContent();
}
}

public static PublicKey getPublicKey(byte[] keyBytes, String algorithm) {
Expand Down
4 changes: 2 additions & 2 deletions jwt-opa/src/test/resources/application-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ tokens:
signature:
algorithm: "EC"
keypair:
priv: "../private/ec-key.pem"
pub: "../private/ec-key-pub.pem"
priv: "../testdata/test-key.pem"
pub: "../testdata/test-key-pub.pem"

# This is used to build the Rule validation endpoint:
# http://localhost:8181/v1/data/kapsules/allow
Expand Down
4 changes: 4 additions & 0 deletions testdata/test-key-pub.pem
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
-----BEGIN PUBLIC KEY-----
MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEvoIrS9BIMchQr3U+qyd/Q2wqyy8C
0XkwOTl2oXCBHggcoH8od+R/E/a/bh7M0jgqQJNUEDLoalEc8lhGio5Pdg==
-----END PUBLIC KEY-----
5 changes: 5 additions & 0 deletions testdata/test-key.pem
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
-----BEGIN PRIVATE KEY-----
MIGHAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBG0wawIBAQQgYEIUVkTtwBilNcNo
EzsP3jdslIlOtXQ5pByuzxhLJTChRANCAAS+gitL0EgxyFCvdT6rJ39DbCrLLwLR
eTA5OXahcIEeCBygfyh35H8T9r9uHszSOCpAk1QQMuhqURzyWEaKjk92
-----END PRIVATE KEY-----
4 changes: 2 additions & 2 deletions webapp-example/src/test/resources/application-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ tokens:
signature:
algorithm: "EC"
keypair:
priv: "../private/ec-key.pem"
pub: "../private/ec-key-pub.pem"
priv: "../testdata/test-key.pem"
pub: "../testdata/test-key-pub.pem"


# This is used to build the Rule validation endpoint:
Expand Down