ChenSammi commented on code in PR #11461:
URL: https://github.com/apache/ozone/pull/11461#discussion_r4255843369


##########
hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/s3/endpoint/PutBucketLifecycleConfigurationUnmarshaller.java:
##########
@@ -17,14 +17,67 @@
 
 package org.apache.hadoop.ozone.s3.endpoint;
 
+import static org.apache.hadoop.ozone.s3.util.S3Consts.S3_XML_NAMESPACE;
+
+import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.ImmutableSet;
+import java.util.ArrayDeque;
+import java.util.Deque;
+import org.xml.sax.Attributes;
+import org.xml.sax.SAXException;
+
 /**
  * Custom unmarshaller to read Lifecycle configuration.
  */
 public class PutBucketLifecycleConfigurationUnmarshaller
     extends MessageUnmarshaller<S3LifecycleConfiguration> {
+  private static final ImmutableMap<String, ImmutableSet<String>> 
ALLOWED_CHILDREN =
+      ImmutableMap.<String, ImmutableSet<String>>builder()
+          .put("", ImmutableSet.of("LifecycleConfiguration"))
+          .put("LifecycleConfiguration", ImmutableSet.of("Rule"))
+          .put("Rule", ImmutableSet.of("ID", "Status", "Prefix", "Expiration", 
"AbortIncompleteMultipartUpload",
+              "Filter", "Transition"))
+          .put("Expiration", ImmutableSet.of("Days", "Date"))
+          .put("AbortIncompleteMultipartUpload", 
ImmutableSet.of("DaysAfterInitiation"))
+          .put("Filter", ImmutableSet.of("Prefix", "Tag", "And"))
+          .put("And", ImmutableSet.of("Prefix", "Tag"))
+          .put("Tag", ImmutableSet.of("Key", "Value"))
+          .put("Transition", ImmutableSet.of("Days", "Date", "StorageClass"))
+          .build();
 
   public PutBucketLifecycleConfigurationUnmarshaller() {
     super(S3LifecycleConfiguration.class);
   }
 
+  @Override
+  protected XmlNamespaceFilter createNamespaceFilter() {
+    return new LifecycleNamespaceFilter();
+  }
+
+  private static class LifecycleNamespaceFilter extends XmlNamespaceFilter {
+    private final Deque<String> parents = new ArrayDeque<>();
+
+    LifecycleNamespaceFilter() {
+      super(S3_XML_NAMESPACE);
+    }
+
+    @Override
+    public void startElement(String uri, String localName, String qName, 
Attributes attributes) throws SAXException {
+      // Match JAXB's name selection when the SAX parser is not 
namespace-aware.
+      String name = localName == null || localName.isEmpty() ? qName : 
localName;
+      String parent = parents.isEmpty() ? "" : parents.peek();
+      if (!ALLOWED_CHILDREN.getOrDefault(parent, 
ImmutableSet.of()).contains(name)) {
+        throw new SAXException("Unsupported lifecycle element: " + name);

Review Comment:
   Can we change this to "Unsupported or invalid lifecycle element"? 



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