bharatviswa504 commented on a change in pull request #1628: URL: https://github.com/apache/ozone/pull/1628#discussion_r538898372
########## File path: hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/s3/signature/AuthorizationV4HeaderParser.java ########## @@ -1,86 +1,78 @@ /** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with this - * work for additional information regarding copyright ownership. The ASF - * licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at * <p> * http://www.apache.org/licenses/LICENSE-2.0 * <p> * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations under - * the License. + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ +package org.apache.hadoop.ozone.s3.signature; -package org.apache.hadoop.ozone.s3.header; - +import java.time.LocalDate; +import java.util.Collection; -import com.google.common.annotations.VisibleForTesting; -import com.google.common.base.Preconditions; -import org.apache.commons.codec.DecoderException; -import org.apache.commons.codec.binary.Hex; import org.apache.hadoop.ozone.s3.exception.OS3Exception; import org.apache.hadoop.ozone.s3.exception.S3ErrorTable; +import org.apache.hadoop.ozone.s3.signature.SignatureInfo.Version; import org.apache.hadoop.util.StringUtils; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.time.LocalDate; -import java.util.Collection; +import com.google.common.annotations.VisibleForTesting; import static java.time.temporal.ChronoUnit.DAYS; +import org.apache.commons.codec.DecoderException; +import org.apache.commons.codec.binary.Hex; import static org.apache.commons.lang3.StringUtils.isEmpty; import static org.apache.commons.lang3.StringUtils.isNotEmpty; import static org.apache.hadoop.ozone.s3.exception.S3ErrorTable.MALFORMED_HEADER; -import static org.apache.hadoop.ozone.s3.AWSSignatureProcessor.AWS4_SIGNING_ALGORITHM; -import static org.apache.hadoop.ozone.s3.AWSSignatureProcessor.DATE_FORMATTER; +import static org.apache.hadoop.ozone.s3.signature.SignatureProcessor.AWS4_SIGNING_ALGORITHM; +import static org.apache.hadoop.ozone.s3.signature.SignatureProcessor.DATE_FORMATTER; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** - * S3 Authorization header. - * Ref: https://docs.aws.amazon.com/AmazonS3/latest/API/sigv4-auth-using - * -authorization-header.html + * Class to parse v4 auth information from header. */ -public class AuthorizationHeaderV4 { +public class AuthorizationV4HeaderParser implements SignatureParser { - private final static Logger LOG = LoggerFactory.getLogger( - AuthorizationHeaderV4.class); + private static final Logger LOG = + LoggerFactory.getLogger(AuthorizationV4HeaderParser.class); private final static String CREDENTIAL = "Credential="; private final static String SIGNEDHEADERS = "SignedHeaders="; private final static String SIGNATURE = "Signature="; private String authHeader; - private String algorithm; - private String credential; - private String signedHeadersStr; - private String signature; - private Credential credentialObj; - private Collection<String> signedHeaders; - /** - * Construct AuthorizationHeader object. - * @param header - */ - public AuthorizationHeaderV4(String header) throws OS3Exception { - Preconditions.checkNotNull(header); - this.authHeader = header; - parseAuthHeader(); + public AuthorizationV4HeaderParser(String authHeader) { + this.authHeader = authHeader; } /** * This method parses authorization header. + * <p> + * Authorization Header sample: + * AWS4-HMAC-SHA256 Credential=AKIAJWFJK62WUTKNFJJA/20181009/us-east-1/s3 + * /aws4_request, SignedHeaders=host;x-amz-content-sha256;x-amz-date, + * Signature + * =db81b057718d7c1b3b8dffa29933099551c51d787b3b13b9e0f9ebed45982bf2 * - * Authorization Header sample: - * AWS4-HMAC-SHA256 Credential=AKIAJWFJK62WUTKNFJJA/20181009/us-east-1/s3 - * /aws4_request, SignedHeaders=host;x-amz-content-sha256;x-amz-date, - * Signature=db81b057718d7c1b3b8dffa29933099551c51d787b3b13b9e0f9ebed45982bf2 * @throws OS3Exception */ @SuppressWarnings("StringSplitter") - public void parseAuthHeader() throws OS3Exception { + @Override + public SignatureInfo parseSignature() throws OS3Exception { + if (authHeader == null || authHeader + .startsWith(AuthorizationV2HeaderParser.IDENTIFIER + " ")) { Review comment: AuthorizationV4HeaderParser.IDENTIFIER=AWS4 ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
