kopia lustrzana https://github.com/gaul/s3proxy
Prefer Splitter over String.split
The latter has surprising semantics. Found via error-prone 2.2.0.pull/257/head
rodzic
757a9dc855
commit
357f8e4197
|
@ -35,6 +35,7 @@ import javax.crypto.spec.SecretKeySpec;
|
|||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import com.google.common.base.Joiner;
|
||||
import com.google.common.base.Splitter;
|
||||
import com.google.common.base.Strings;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.SortedSetMultimap;
|
||||
|
@ -192,7 +193,7 @@ final class AwsSignature {
|
|||
}
|
||||
|
||||
@Nullable
|
||||
private static String[] extractSignedHeaders(String authorization) {
|
||||
private static List<String> extractSignedHeaders(String authorization) {
|
||||
int index = authorization.indexOf("SignedHeaders=");
|
||||
if (index < 0) {
|
||||
return null;
|
||||
|
@ -202,11 +203,12 @@ final class AwsSignature {
|
|||
return null;
|
||||
}
|
||||
int startHeaders = authorization.indexOf('=', index);
|
||||
return authorization.substring(startHeaders + 1, endSigned).split(";");
|
||||
return Splitter.on(';').splitToList(authorization.substring(
|
||||
startHeaders + 1, endSigned));
|
||||
}
|
||||
|
||||
private static String buildCanonicalHeaders(HttpServletRequest request,
|
||||
String[] signedHeaders) {
|
||||
List<String> signedHeaders) {
|
||||
List<String> headers = new ArrayList<>();
|
||||
for (String header : signedHeaders) {
|
||||
headers.add(header.toLowerCase());
|
||||
|
@ -271,12 +273,12 @@ final class AwsSignature {
|
|||
} else {
|
||||
digest = getMessageDigest(payload, hashAlgorithm);
|
||||
}
|
||||
String[] signedHeaders;
|
||||
List<String> signedHeaders;
|
||||
if (authorizationHeader != null) {
|
||||
signedHeaders = extractSignedHeaders(authorizationHeader);
|
||||
} else {
|
||||
signedHeaders = request.getParameter("X-Amz-SignedHeaders")
|
||||
.split(";");
|
||||
signedHeaders = Splitter.on(';').splitToList(request.getParameter(
|
||||
"X-Amz-SignedHeaders"));
|
||||
}
|
||||
String canonicalRequest = Joiner.on("\n").join(
|
||||
request.getMethod(),
|
||||
|
|
|
@ -16,6 +16,9 @@
|
|||
|
||||
package org.gaul.s3proxy;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.google.common.base.Splitter;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
|
||||
final class S3AuthorizationHeader {
|
||||
|
@ -48,16 +51,17 @@ final class S3AuthorizationHeader {
|
|||
region = null;
|
||||
date = null;
|
||||
service = null;
|
||||
String[] fields = header.split(" ");
|
||||
if (fields.length != 2) {
|
||||
List<String> fields = Splitter.on(' ').splitToList(header);
|
||||
if (fields.size() != 2) {
|
||||
throw new IllegalArgumentException("Invalid header");
|
||||
}
|
||||
String[] identityTuple = fields[1].split(":");
|
||||
if (identityTuple.length != 2) {
|
||||
List<String> identityTuple = Splitter.on(':').splitToList(
|
||||
fields.get(1));
|
||||
if (identityTuple.size() != 2) {
|
||||
throw new IllegalArgumentException("Invalid header");
|
||||
}
|
||||
identity = identityTuple[0];
|
||||
signature = identityTuple[1];
|
||||
identity = identityTuple.get(0);
|
||||
signature = identityTuple.get(1);
|
||||
} else if (header.startsWith("AWS4-HMAC")) {
|
||||
authenticationType = AuthenticationType.AWS_V4;
|
||||
signature = extractSignature(header);
|
||||
|
@ -72,19 +76,21 @@ final class S3AuthorizationHeader {
|
|||
}
|
||||
String credential = header.substring(credentialIndex +
|
||||
CREDENTIAL_FIELD.length(), credentialEnd);
|
||||
String[] fields = credential.split("/");
|
||||
if (fields.length != 5) {
|
||||
List<String> fields = Splitter.on('/').splitToList(credential);
|
||||
if (fields.size() != 5) {
|
||||
throw new IllegalArgumentException(
|
||||
"Invalid Credential: " + credential);
|
||||
}
|
||||
identity = fields[0];
|
||||
date = fields[1];
|
||||
region = fields[2];
|
||||
service = fields[3];
|
||||
identity = fields.get(0);
|
||||
date = fields.get(1);
|
||||
region = fields.get(2);
|
||||
service = fields.get(3);
|
||||
String awsSignatureVersion = header.substring(
|
||||
0, header.indexOf(' '));
|
||||
hashAlgorithm = DIGEST_MAP.get(awsSignatureVersion.split("-")[2]);
|
||||
hmacAlgorithm = "Hmac" + awsSignatureVersion.split("-")[2];
|
||||
hashAlgorithm = DIGEST_MAP.get(Splitter.on('-').splitToList(
|
||||
awsSignatureVersion).get(2));
|
||||
hmacAlgorithm = "Hmac" + Splitter.on('-').splitToList(
|
||||
awsSignatureVersion).get(2);
|
||||
} else {
|
||||
throw new IllegalArgumentException("Invalid header");
|
||||
}
|
||||
|
|
|
@ -59,6 +59,7 @@ import javax.xml.stream.XMLStreamWriter;
|
|||
import com.fasterxml.jackson.dataformat.xml.XmlMapper;
|
||||
import com.google.common.base.CharMatcher;
|
||||
import com.google.common.base.Optional;
|
||||
import com.google.common.base.Splitter;
|
||||
import com.google.common.base.Strings;
|
||||
import com.google.common.cache.Cache;
|
||||
import com.google.common.cache.CacheBuilder;
|
||||
|
@ -2779,8 +2780,8 @@ public class S3ProxyHandler {
|
|||
}
|
||||
|
||||
private static boolean validateIpAddress(String string) {
|
||||
String[] parts = string.split("\\.");
|
||||
if (parts.length != 4) {
|
||||
List<String> parts = Splitter.on('.').splitToList(string);
|
||||
if (parts.size() != 4) {
|
||||
return false;
|
||||
}
|
||||
for (String part : parts) {
|
||||
|
|
Ładowanie…
Reference in New Issue