fmorg-git commented on code in PR #12215:
URL: https://github.com/apache/ozone/pull/12215#discussion_r4793657900


##########
hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/s3/endpoint/BucketObjectLockHandler.java:
##########
@@ -0,0 +1,176 @@
+/*
+ * 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
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * 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.
+ */
+
+package org.apache.hadoop.ozone.s3.endpoint;
+
+import static 
org.apache.hadoop.ozone.s3.exception.S3ErrorTable.INVALID_ARGUMENT;
+import static org.apache.hadoop.ozone.s3.exception.S3ErrorTable.MALFORMED_XML;
+import static 
org.apache.hadoop.ozone.s3.exception.S3ErrorTable.PAYLOAD_TOO_LARGE;
+import static org.apache.hadoop.ozone.s3.exception.S3ErrorTable.newError;
+import static 
org.apache.hadoop.ozone.s3.util.S3Consts.EXPECTED_BUCKET_OWNER_HEADER;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.function.Supplier;
+import javax.ws.rs.WebApplicationException;
+import javax.ws.rs.core.HttpHeaders;
+import javax.ws.rs.core.Response;
+import javax.xml.XMLConstants;
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlRootElement;
+import javax.xml.validation.SchemaFactory;
+import org.apache.hadoop.ozone.audit.S3GAction;
+import org.apache.hadoop.ozone.om.helpers.BucketRetention;
+import org.apache.hadoop.ozone.om.helpers.RetentionDuration;
+import 
org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.RetentionMode;
+import 
org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.RetentionTimeUnit;
+import org.apache.hadoop.ozone.s3.util.S3Consts.QueryParams;
+import org.apache.ratis.util.MemoizedSupplier;
+import org.xml.sax.SAXException;
+
+/**
+ * Handles PUT requests for the bucket Object Lock subresource.
+ */
+class BucketObjectLockHandler extends BucketOperationHandler {
+
+  static final int MAX_BODY_BYTES = 64 * 1024;
+
+  private static final Supplier<MessageUnmarshaller<ObjectLockConfiguration>> 
UNMARSHALLER =
+      MemoizedSupplier.valueOf(BucketObjectLockHandler::newUnmarshaller);
+
+  private static MessageUnmarshaller<ObjectLockConfiguration> 
newUnmarshaller() {
+    try {
+      SchemaFactory factory = 
SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
+      factory.setProperty(XMLConstants.ACCESS_EXTERNAL_DTD, "");
+      factory.setProperty(XMLConstants.ACCESS_EXTERNAL_SCHEMA, "");
+      return new MessageUnmarshaller<>(ObjectLockConfiguration.class,
+          
factory.newSchema(BucketObjectLockHandler.class.getResource("bucket-object-lock.xsd")));
+    } catch (SAXException e) {
+      throw new IllegalStateException("Cannot load the bucket Object Lock XML 
schema", e);
+    }
+  }
+
+  @Override
+  Response handlePutRequest(S3RequestContext context, String bucketName, 
InputStream body) throws IOException {
+    if (!queryParams().containsKey(QueryParams.OBJECT_LOCK)) {
+      return null;
+    }
+    context.setAction(S3GAction.PUT_BUCKET_OBJECT_LOCK_CONFIGURATION);
+
+    ObjectLockConfiguration configuration;
+    try {
+      byte[] xml = body.readNBytes(MAX_BODY_BYTES + 1);
+      if (xml.length > MAX_BODY_BYTES) {
+        throw newError(PAYLOAD_TOO_LARGE, bucketName);
+      }
+      configuration = UNMARSHALLER.get().readFrom(new 
ByteArrayInputStream(xml));

Review Comment:
   it looks like this is validating the XML against the schema - should it also 
validate the bytes against `Content-MD5` header if supplied? See 
https://github.com/apache/ozone/pull/12094/changes as example



-- 
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.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to