Replace Base64Utils with JDK's Base64

See gh-33967
This commit is contained in:
Johnny Lim
2023-01-25 01:44:46 +09:00
committed by Moritz Halbritter
parent b62b88372f
commit bc7fc90550
23 changed files with 73 additions and 67 deletions

View File

@@ -16,10 +16,11 @@
package org.springframework.boot.buildpack.platform.docker.configuration;
import java.util.Base64;
import com.fasterxml.jackson.core.JsonProcessingException;
import org.springframework.boot.buildpack.platform.json.SharedObjectMapper;
import org.springframework.util.Base64Utils;
/**
* {@link DockerRegistryAuthentication} that uses a Base64 encoded auth header value based
@@ -38,7 +39,7 @@ class JsonEncodedDockerRegistryAuthentication implements DockerRegistryAuthentic
protected void createAuthHeader() {
try {
this.authHeader = Base64Utils.encodeToUrlSafeString(SharedObjectMapper.get().writeValueAsBytes(this));
this.authHeader = Base64.getUrlEncoder().encodeToString(SharedObjectMapper.get().writeValueAsBytes(this));
}
catch (JsonProcessingException ex) {
throw new IllegalStateException("Error creating Docker registry authentication header", ex);

View File

@@ -24,13 +24,12 @@ import java.security.cert.CertificateException;
import java.security.cert.CertificateFactory;
import java.security.cert.X509Certificate;
import java.util.ArrayList;
import java.util.Base64;
import java.util.List;
import java.util.function.Consumer;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.springframework.util.Base64Utils;
/**
* Parser for X.509 certificates in PEM format.
*
@@ -93,7 +92,7 @@ final class CertificateParser {
private static byte[] decodeBase64(String content) {
byte[] bytes = content.replaceAll("\r", "").replaceAll("\n", "").getBytes();
return Base64Utils.decode(bytes);
return Base64.getDecoder().decode(bytes);
}
}

View File

@@ -25,14 +25,13 @@ import java.security.KeyFactory;
import java.security.PrivateKey;
import java.security.spec.PKCS8EncodedKeySpec;
import java.util.ArrayList;
import java.util.Base64;
import java.util.Collections;
import java.util.List;
import java.util.function.Function;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.springframework.util.Base64Utils;
/**
* Parser for PKCS private key files in PEM format.
*
@@ -153,7 +152,7 @@ final class PrivateKeyParser {
private static byte[] decodeBase64(String content) {
byte[] contentBytes = content.replaceAll("\r", "").replaceAll("\n", "").getBytes();
return Base64Utils.decode(contentBytes);
return Base64.getDecoder().decode(contentBytes);
}
private PrivateKey parse(byte[] bytes) {

View File

@@ -18,13 +18,13 @@ package org.springframework.boot.buildpack.platform.docker.configuration;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.Base64;
import org.json.JSONException;
import org.junit.jupiter.api.Test;
import org.skyscreamer.jsonassert.JSONAssert;
import org.springframework.boot.buildpack.platform.json.AbstractJsonTests;
import org.springframework.util.Base64Utils;
import org.springframework.util.StreamUtils;
/**
@@ -39,7 +39,7 @@ class DockerRegistryTokenAuthenticationTests extends AbstractJsonTests {
DockerRegistryTokenAuthentication auth = new DockerRegistryTokenAuthentication("tokenvalue");
String header = auth.getAuthHeader();
String expectedJson = StreamUtils.copyToString(getContent("auth-token.json"), StandardCharsets.UTF_8);
JSONAssert.assertEquals(expectedJson, new String(Base64Utils.decodeFromUrlSafeString(header)), false);
JSONAssert.assertEquals(expectedJson, new String(Base64.getUrlDecoder().decode(header)), false);
}
}

View File

@@ -18,13 +18,13 @@ package org.springframework.boot.buildpack.platform.docker.configuration;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.Base64;
import org.json.JSONException;
import org.junit.jupiter.api.Test;
import org.skyscreamer.jsonassert.JSONAssert;
import org.springframework.boot.buildpack.platform.json.AbstractJsonTests;
import org.springframework.util.Base64Utils;
import org.springframework.util.StreamUtils;
/**
@@ -52,7 +52,7 @@ class DockerRegistryUserAuthenticationTests extends AbstractJsonTests {
}
private String decoded(String header) {
return new String(Base64Utils.decodeFromUrlSafeString(header));
return new String(Base64.getUrlDecoder().decode(header));
}
}

View File

@@ -17,6 +17,7 @@
package org.springframework.boot.gradle.tasks.bundling;
import java.io.File;
import java.util.Base64;
import org.gradle.api.GradleException;
import org.junit.jupiter.api.BeforeEach;
@@ -26,7 +27,6 @@ import org.junit.jupiter.api.io.TempDir;
import org.springframework.boot.buildpack.platform.docker.configuration.DockerConfiguration;
import org.springframework.boot.buildpack.platform.docker.configuration.DockerHost;
import org.springframework.boot.gradle.junit.GradleProjectBuilder;
import org.springframework.util.Base64Utils;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
@@ -176,7 +176,7 @@ class DockerSpecTests {
}
String decoded(String value) {
return new String(Base64Utils.decodeFromString(value));
return new String(Base64.getDecoder().decode(value));
}
}

View File

@@ -16,11 +16,12 @@
package org.springframework.boot.maven;
import java.util.Base64;
import org.junit.jupiter.api.Test;
import org.springframework.boot.buildpack.platform.docker.configuration.DockerConfiguration;
import org.springframework.boot.buildpack.platform.docker.configuration.DockerHost;
import org.springframework.util.Base64Utils;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
@@ -142,7 +143,7 @@ class DockerTests {
}
String decoded(String value) {
return new String(Base64Utils.decodeFromString(value));
return new String(Base64.getDecoder().decode(value));
}
}