HDDS-705. OS3Exception resource name should be the actual resource name.
Contributed by Bharat Viswanadham. Recommitting after making sure that patch is clean.
This commit is contained in:
parent
c696419f3e
commit
97a41b3dbe
|
@ -199,11 +199,11 @@ public class BucketEndpoint extends EndpointBase {
|
||||||
} catch (IOException ex) {
|
} catch (IOException ex) {
|
||||||
if (ex.getMessage().contains("BUCKET_NOT_EMPTY")) {
|
if (ex.getMessage().contains("BUCKET_NOT_EMPTY")) {
|
||||||
OS3Exception os3Exception = S3ErrorTable.newError(S3ErrorTable
|
OS3Exception os3Exception = S3ErrorTable.newError(S3ErrorTable
|
||||||
.BUCKET_NOT_EMPTY, S3ErrorTable.Resource.BUCKET);
|
.BUCKET_NOT_EMPTY, bucketName);
|
||||||
throw os3Exception;
|
throw os3Exception;
|
||||||
} else if (ex.getMessage().contains("BUCKET_NOT_FOUND")) {
|
} else if (ex.getMessage().contains("BUCKET_NOT_FOUND")) {
|
||||||
OS3Exception os3Exception = S3ErrorTable.newError(S3ErrorTable
|
OS3Exception os3Exception = S3ErrorTable.newError(S3ErrorTable
|
||||||
.NO_SUCH_BUCKET, S3ErrorTable.Resource.BUCKET);
|
.NO_SUCH_BUCKET, bucketName);
|
||||||
throw os3Exception;
|
throw os3Exception;
|
||||||
} else {
|
} else {
|
||||||
throw ex;
|
throw ex;
|
||||||
|
|
|
@ -28,7 +28,6 @@ import org.apache.hadoop.ozone.client.OzoneClient;
|
||||||
import org.apache.hadoop.ozone.client.OzoneVolume;
|
import org.apache.hadoop.ozone.client.OzoneVolume;
|
||||||
import org.apache.hadoop.ozone.s3.exception.OS3Exception;
|
import org.apache.hadoop.ozone.s3.exception.OS3Exception;
|
||||||
import org.apache.hadoop.ozone.s3.exception.S3ErrorTable;
|
import org.apache.hadoop.ozone.s3.exception.S3ErrorTable;
|
||||||
import org.apache.hadoop.ozone.s3.exception.S3ErrorTable.Resource;
|
|
||||||
import org.apache.hadoop.ozone.s3.header.AuthorizationHeaderV2;
|
import org.apache.hadoop.ozone.s3.header.AuthorizationHeaderV2;
|
||||||
import org.apache.hadoop.ozone.s3.header.AuthorizationHeaderV4;
|
import org.apache.hadoop.ozone.s3.header.AuthorizationHeaderV4;
|
||||||
|
|
||||||
|
@ -61,7 +60,7 @@ public class EndpointBase {
|
||||||
LOG.error("Error occurred is {}", ex);
|
LOG.error("Error occurred is {}", ex);
|
||||||
if (ex.getMessage().contains("NOT_FOUND")) {
|
if (ex.getMessage().contains("NOT_FOUND")) {
|
||||||
OS3Exception oex =
|
OS3Exception oex =
|
||||||
S3ErrorTable.newError(S3ErrorTable.NO_SUCH_BUCKET, Resource.BUCKET);
|
S3ErrorTable.newError(S3ErrorTable.NO_SUCH_BUCKET, bucketName);
|
||||||
throw oex;
|
throw oex;
|
||||||
} else {
|
} else {
|
||||||
throw ex;
|
throw ex;
|
||||||
|
@ -80,7 +79,7 @@ public class EndpointBase {
|
||||||
LOG.error("Error occurred is {}", ex);
|
LOG.error("Error occurred is {}", ex);
|
||||||
if (ex.getMessage().contains("NOT_FOUND")) {
|
if (ex.getMessage().contains("NOT_FOUND")) {
|
||||||
OS3Exception oex =
|
OS3Exception oex =
|
||||||
S3ErrorTable.newError(S3ErrorTable.NO_SUCH_BUCKET, Resource.BUCKET);
|
S3ErrorTable.newError(S3ErrorTable.NO_SUCH_BUCKET, bucketName);
|
||||||
throw oex;
|
throw oex;
|
||||||
} else {
|
} else {
|
||||||
throw ex;
|
throw ex;
|
||||||
|
@ -187,7 +186,7 @@ public class EndpointBase {
|
||||||
|
|
||||||
if (auth == null) {
|
if (auth == null) {
|
||||||
throw S3ErrorTable
|
throw S3ErrorTable
|
||||||
.newError(S3ErrorTable.MALFORMED_HEADER, Resource.HEADER);
|
.newError(S3ErrorTable.MALFORMED_HEADER, auth);
|
||||||
}
|
}
|
||||||
|
|
||||||
String userName;
|
String userName;
|
||||||
|
|
|
@ -150,7 +150,7 @@ public class ObjectEndpoint extends EndpointBase {
|
||||||
} catch (IOException ex) {
|
} catch (IOException ex) {
|
||||||
if (ex.getMessage().contains("NOT_FOUND")) {
|
if (ex.getMessage().contains("NOT_FOUND")) {
|
||||||
OS3Exception os3Exception = S3ErrorTable.newError(S3ErrorTable
|
OS3Exception os3Exception = S3ErrorTable.newError(S3ErrorTable
|
||||||
.NO_SUCH_OBJECT, S3ErrorTable.Resource.OBJECT);
|
.NO_SUCH_KEY, keyPath);
|
||||||
throw os3Exception;
|
throw os3Exception;
|
||||||
} else {
|
} else {
|
||||||
throw ex;
|
throw ex;
|
||||||
|
@ -176,9 +176,8 @@ public class ObjectEndpoint extends EndpointBase {
|
||||||
} catch (IOException ex) {
|
} catch (IOException ex) {
|
||||||
LOG.error("Exception occurred in HeadObject", ex);
|
LOG.error("Exception occurred in HeadObject", ex);
|
||||||
if (ex.getMessage().contains("KEY_NOT_FOUND")) {
|
if (ex.getMessage().contains("KEY_NOT_FOUND")) {
|
||||||
OS3Exception os3Exception = S3ErrorTable.newError(S3ErrorTable
|
// Just return 404 with no content
|
||||||
.NO_SUCH_OBJECT, S3ErrorTable.Resource.OBJECT);
|
return Response.status(Status.NOT_FOUND).build();
|
||||||
throw os3Exception;
|
|
||||||
} else {
|
} else {
|
||||||
throw ex;
|
throw ex;
|
||||||
}
|
}
|
||||||
|
@ -215,7 +214,7 @@ public class ObjectEndpoint extends EndpointBase {
|
||||||
} catch (IOException ex) {
|
} catch (IOException ex) {
|
||||||
if (ex.getMessage().contains("BUCKET_NOT_FOUND")) {
|
if (ex.getMessage().contains("BUCKET_NOT_FOUND")) {
|
||||||
throw S3ErrorTable.newError(S3ErrorTable
|
throw S3ErrorTable.newError(S3ErrorTable
|
||||||
.NO_SUCH_BUCKET, S3ErrorTable.Resource.BUCKET);
|
.NO_SUCH_BUCKET, bucketName);
|
||||||
} else if (!ex.getMessage().contains("NOT_FOUND")) {
|
} else if (!ex.getMessage().contains("NOT_FOUND")) {
|
||||||
throw ex;
|
throw ex;
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,52 +45,23 @@ public final class S3ErrorTable {
|
||||||
"BucketNotEmpty", "The bucket you tried to delete is not empty.",
|
"BucketNotEmpty", "The bucket you tried to delete is not empty.",
|
||||||
HTTP_CONFLICT);
|
HTTP_CONFLICT);
|
||||||
|
|
||||||
public static final OS3Exception NO_SUCH_OBJECT = new OS3Exception(
|
|
||||||
"NoSuchObject", "The specified object does not exist", HTTP_NOT_FOUND);
|
|
||||||
|
|
||||||
|
|
||||||
public static final OS3Exception MALFORMED_HEADER = new OS3Exception(
|
public static final OS3Exception MALFORMED_HEADER = new OS3Exception(
|
||||||
"AuthorizationHeaderMalformed", "The authorization header you provided " +
|
"AuthorizationHeaderMalformed", "The authorization header you provided " +
|
||||||
"is invalid.", HTTP_NOT_FOUND);
|
"is invalid.", HTTP_NOT_FOUND);
|
||||||
|
|
||||||
|
public static final OS3Exception NO_SUCH_KEY = new OS3Exception(
|
||||||
|
"NoSuchObject", "The specified key does not exist", HTTP_NOT_FOUND);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new instance of Error.
|
* Create a new instance of Error.
|
||||||
* @param e Error Template
|
* @param e Error Template
|
||||||
* @param resource Resource associated with this exception
|
* @param resource Resource associated with this exception
|
||||||
* @return creates a new instance of error based on the template
|
* @return creates a new instance of error based on the template
|
||||||
*/
|
*/
|
||||||
public static OS3Exception newError(OS3Exception e, Resource resource) {
|
public static OS3Exception newError(OS3Exception e, String resource) {
|
||||||
OS3Exception err = new OS3Exception(e.getCode(), e.getErrorMessage(),
|
OS3Exception err = new OS3Exception(e.getCode(), e.getErrorMessage(),
|
||||||
e.getHttpCode());
|
e.getHttpCode());
|
||||||
err.setResource(resource.getResource());
|
err.setResource(resource);
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Resources, which can be defined in OS3Exception.
|
|
||||||
*/
|
|
||||||
public enum Resource {
|
|
||||||
BUCKET("Bucket"),
|
|
||||||
OBJECT("Object"),
|
|
||||||
HEADER("header"),
|
|
||||||
VOLUME("Volume");
|
|
||||||
|
|
||||||
private final String resource;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Constructs resource.
|
|
||||||
* @param value
|
|
||||||
*/
|
|
||||||
Resource(String value) {
|
|
||||||
this.resource = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get resource.
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public String getResource() {
|
|
||||||
return this.resource;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -52,28 +52,24 @@ public class AuthorizationHeaderV2 {
|
||||||
public void parseHeader() throws OS3Exception {
|
public void parseHeader() throws OS3Exception {
|
||||||
String[] split = authHeader.split(" ");
|
String[] split = authHeader.split(" ");
|
||||||
if (split.length != 2) {
|
if (split.length != 2) {
|
||||||
throw S3ErrorTable.newError(S3ErrorTable.MALFORMED_HEADER, S3ErrorTable
|
throw S3ErrorTable.newError(S3ErrorTable.MALFORMED_HEADER, authHeader);
|
||||||
.Resource.HEADER);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
identifier = split[0];
|
identifier = split[0];
|
||||||
if (!IDENTIFIER.equals(identifier)) {
|
if (!IDENTIFIER.equals(identifier)) {
|
||||||
throw S3ErrorTable.newError(S3ErrorTable.MALFORMED_HEADER, S3ErrorTable
|
throw S3ErrorTable.newError(S3ErrorTable.MALFORMED_HEADER, authHeader);
|
||||||
.Resource.HEADER);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
String[] remainingSplit = split[1].split(":");
|
String[] remainingSplit = split[1].split(":");
|
||||||
|
|
||||||
if (remainingSplit.length != 2) {
|
if (remainingSplit.length != 2) {
|
||||||
throw S3ErrorTable.newError(S3ErrorTable.MALFORMED_HEADER, S3ErrorTable
|
throw S3ErrorTable.newError(S3ErrorTable.MALFORMED_HEADER, authHeader);
|
||||||
.Resource.HEADER);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
accessKeyID = remainingSplit[0];
|
accessKeyID = remainingSplit[0];
|
||||||
signature = remainingSplit[1];
|
signature = remainingSplit[1];
|
||||||
if (isBlank(accessKeyID) || isBlank(signature)) {
|
if (isBlank(accessKeyID) || isBlank(signature)) {
|
||||||
throw S3ErrorTable.newError(S3ErrorTable.MALFORMED_HEADER, S3ErrorTable
|
throw S3ErrorTable.newError(S3ErrorTable.MALFORMED_HEADER, authHeader);
|
||||||
.Resource.HEADER);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -64,8 +64,7 @@ public class AuthorizationHeaderV4 {
|
||||||
String[] split = authHeader.split(" ");
|
String[] split = authHeader.split(" ");
|
||||||
|
|
||||||
if (split.length != 4) {
|
if (split.length != 4) {
|
||||||
throw S3ErrorTable.newError(S3ErrorTable.MALFORMED_HEADER, S3ErrorTable
|
throw S3ErrorTable.newError(S3ErrorTable.MALFORMED_HEADER, authHeader);
|
||||||
.Resource.HEADER);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
algorithm = split[0];
|
algorithm = split[0];
|
||||||
|
@ -78,24 +77,21 @@ public class AuthorizationHeaderV4 {
|
||||||
credential = credential.substring(CREDENTIAL.length(), credential
|
credential = credential.substring(CREDENTIAL.length(), credential
|
||||||
.length() - 1);
|
.length() - 1);
|
||||||
} else {
|
} else {
|
||||||
throw S3ErrorTable.newError(S3ErrorTable.MALFORMED_HEADER, S3ErrorTable
|
throw S3ErrorTable.newError(S3ErrorTable.MALFORMED_HEADER, authHeader);
|
||||||
.Resource.HEADER);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (signedHeaders.startsWith(SIGNEDHEADERS)) {
|
if (signedHeaders.startsWith(SIGNEDHEADERS)) {
|
||||||
signedHeaders = signedHeaders.substring(SIGNEDHEADERS.length(),
|
signedHeaders = signedHeaders.substring(SIGNEDHEADERS.length(),
|
||||||
signedHeaders.length() - 1);
|
signedHeaders.length() - 1);
|
||||||
} else {
|
} else {
|
||||||
throw S3ErrorTable.newError(S3ErrorTable.MALFORMED_HEADER, S3ErrorTable
|
throw S3ErrorTable.newError(S3ErrorTable.MALFORMED_HEADER, authHeader);
|
||||||
.Resource.HEADER);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (signature.startsWith(SIGNATURE)) {
|
if (signature.startsWith(SIGNATURE)) {
|
||||||
signature = signature.substring(SIGNATURE.length(), signature
|
signature = signature.substring(SIGNATURE.length(), signature
|
||||||
.length());
|
.length());
|
||||||
} else {
|
} else {
|
||||||
throw S3ErrorTable.newError(S3ErrorTable.MALFORMED_HEADER, S3ErrorTable
|
throw S3ErrorTable.newError(S3ErrorTable.MALFORMED_HEADER, authHeader);
|
||||||
.Resource.HEADER);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Parse credential. Other parts of header are not validated yet. When
|
// Parse credential. Other parts of header are not validated yet. When
|
||||||
|
|
|
@ -63,8 +63,7 @@ public class Credential {
|
||||||
awsService = split[3];
|
awsService = split[3];
|
||||||
awsRequest = split[4];
|
awsRequest = split[4];
|
||||||
} else {
|
} else {
|
||||||
throw S3ErrorTable.newError(S3ErrorTable.MALFORMED_HEADER, S3ErrorTable
|
throw S3ErrorTable.newError(S3ErrorTable.MALFORMED_HEADER, credential);
|
||||||
.Resource.HEADER);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -32,7 +32,7 @@ public class TestOS3Exception {
|
||||||
OS3Exception ex = new OS3Exception("AccessDenied", "Access Denied",
|
OS3Exception ex = new OS3Exception("AccessDenied", "Access Denied",
|
||||||
403);
|
403);
|
||||||
String requestId = OzoneUtils.getRequestID();
|
String requestId = OzoneUtils.getRequestID();
|
||||||
ex = S3ErrorTable.newError(ex, S3ErrorTable.Resource.BUCKET);
|
ex = S3ErrorTable.newError(ex, "bucket");
|
||||||
ex.setRequestId(requestId);
|
ex.setRequestId(requestId);
|
||||||
String val = ex.toXml();
|
String val = ex.toXml();
|
||||||
String formatString = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
|
String formatString = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
|
||||||
|
|
Loading…
Reference in New Issue