This is an automated email from the ASF dual-hosted git repository.

sunchao pushed a commit to branch branch-2.3
in repository https://gitbox.apache.org/repos/asf/hive.git


The following commit(s) were added to refs/heads/branch-2.3 by this push:
     new 63e2194281b HIVE-18586: (2.3) Upgrade Derby to 10.14.1.0 (#5113)
63e2194281b is described below

commit 63e2194281bd7d769e9b039431563d68436455a7
Author: Cheng Pan <[email protected]>
AuthorDate: Tue Mar 5 01:39:26 2024 +0800

    HIVE-18586: (2.3) Upgrade Derby to 10.14.1.0 (#5113)
---
 .../java/org/apache/hive/hcatalog/DerbyPolicy.java | 90 ++++++++++++++++++++++
 .../java/org/apache/hive/hcatalog/DerbyPolicy.java | 90 ++++++++++++++++++++++
 .../org/apache/hive/hcatalog/cli/TestPermsGrp.java |  3 +
 .../mapreduce/TestHCatPartitionPublish.java        |  3 +
 .../org/apache/hive/hcatalog/package-info.java     | 22 ++++++
 .../apache/hive/hcatalog/api/TestHCatClient.java   |  4 +
 .../metastore/TestHiveMetaStoreGetMetaConf.java    | 25 ------
 .../metastore/TestHiveMetaStorePartitionSpecs.java | 26 -------
 8 files changed, 212 insertions(+), 51 deletions(-)

diff --git a/core/src/test/java/org/apache/hive/hcatalog/DerbyPolicy.java 
b/core/src/test/java/org/apache/hive/hcatalog/DerbyPolicy.java
new file mode 100644
index 00000000000..cecf6dc676f
--- /dev/null
+++ b/core/src/test/java/org/apache/hive/hcatalog/DerbyPolicy.java
@@ -0,0 +1,90 @@
+/*
+ * 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.hive.hcatalog;
+
+import org.apache.derby.security.SystemPermission;
+
+import java.security.CodeSource;
+import java.security.Permission;
+import java.security.PermissionCollection;
+import java.security.Policy;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Enumeration;
+import java.util.Iterator;
+
+/**
+ * A security policy that grants usederbyinternals
+ *
+ * <p>
+ *   HCatalog tests use Security Manager to handle exits.  With Derby version 
10.14.1, if a
+ *   security manager is configured, embedded Derby requires usederbyinternals 
permission, and
+ *   that is checked directly using AccessController.checkPermission.  This 
class will be used to
+ *   setup a security policy to grant usederbyinternals, in tests that use 
NoExitSecurityManager.
+ * </p>
+ */
+public class DerbyPolicy extends Policy {
+
+  private static PermissionCollection perms;
+
+  public DerbyPolicy() {
+    super();
+    if (perms == null) {
+      perms = new DerbyPermissionCollection();
+      addPermissions();
+    }
+  }
+
+  @Override
+  public PermissionCollection getPermissions(CodeSource codesource) {
+    return perms;
+  }
+
+  private void addPermissions() {
+    SystemPermission systemPermission = new SystemPermission("engine", 
"usederbyinternals");
+    perms.add(systemPermission);
+  }
+
+  class DerbyPermissionCollection extends PermissionCollection {
+
+    ArrayList<Permission> perms = new ArrayList<Permission>();
+
+    public void add(Permission p) {
+      perms.add(p);
+    }
+
+    public boolean implies(Permission p) {
+      for (Iterator<Permission> i = perms.iterator(); i.hasNext();) {
+        if (((Permission) i.next()).implies(p)) {
+          return true;
+        }
+      }
+      return false;
+    }
+
+    public Enumeration<Permission> elements() {
+      return Collections.enumeration(perms);
+    }
+
+    public boolean isReadOnly() {
+      return false;
+    }
+  }
+}
+
diff --git 
a/hcatalog/core/src/test/java/org/apache/hive/hcatalog/DerbyPolicy.java 
b/hcatalog/core/src/test/java/org/apache/hive/hcatalog/DerbyPolicy.java
new file mode 100644
index 00000000000..cecf6dc676f
--- /dev/null
+++ b/hcatalog/core/src/test/java/org/apache/hive/hcatalog/DerbyPolicy.java
@@ -0,0 +1,90 @@
+/*
+ * 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.hive.hcatalog;
+
+import org.apache.derby.security.SystemPermission;
+
+import java.security.CodeSource;
+import java.security.Permission;
+import java.security.PermissionCollection;
+import java.security.Policy;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Enumeration;
+import java.util.Iterator;
+
+/**
+ * A security policy that grants usederbyinternals
+ *
+ * <p>
+ *   HCatalog tests use Security Manager to handle exits.  With Derby version 
10.14.1, if a
+ *   security manager is configured, embedded Derby requires usederbyinternals 
permission, and
+ *   that is checked directly using AccessController.checkPermission.  This 
class will be used to
+ *   setup a security policy to grant usederbyinternals, in tests that use 
NoExitSecurityManager.
+ * </p>
+ */
+public class DerbyPolicy extends Policy {
+
+  private static PermissionCollection perms;
+
+  public DerbyPolicy() {
+    super();
+    if (perms == null) {
+      perms = new DerbyPermissionCollection();
+      addPermissions();
+    }
+  }
+
+  @Override
+  public PermissionCollection getPermissions(CodeSource codesource) {
+    return perms;
+  }
+
+  private void addPermissions() {
+    SystemPermission systemPermission = new SystemPermission("engine", 
"usederbyinternals");
+    perms.add(systemPermission);
+  }
+
+  class DerbyPermissionCollection extends PermissionCollection {
+
+    ArrayList<Permission> perms = new ArrayList<Permission>();
+
+    public void add(Permission p) {
+      perms.add(p);
+    }
+
+    public boolean implies(Permission p) {
+      for (Iterator<Permission> i = perms.iterator(); i.hasNext();) {
+        if (((Permission) i.next()).implies(p)) {
+          return true;
+        }
+      }
+      return false;
+    }
+
+    public Enumeration<Permission> elements() {
+      return Collections.enumeration(perms);
+    }
+
+    public boolean isReadOnly() {
+      return false;
+    }
+  }
+}
+
diff --git 
a/hcatalog/core/src/test/java/org/apache/hive/hcatalog/cli/TestPermsGrp.java 
b/hcatalog/core/src/test/java/org/apache/hive/hcatalog/cli/TestPermsGrp.java
index 2375f5d4d1e..04cd5ba8be5 100644
--- a/hcatalog/core/src/test/java/org/apache/hive/hcatalog/cli/TestPermsGrp.java
+++ b/hcatalog/core/src/test/java/org/apache/hive/hcatalog/cli/TestPermsGrp.java
@@ -19,6 +19,7 @@
 package org.apache.hive.hcatalog.cli;
 
 import java.io.FileNotFoundException;
+import java.security.Policy;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.HashMap;
@@ -50,6 +51,7 @@ import org.apache.hadoop.hive.ql.metadata.Hive;
 import org.apache.hadoop.hive.serde.serdeConstants;
 import org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe;
 import org.apache.hadoop.hive.shims.ShimLoader;
+import org.apache.hive.hcatalog.DerbyPolicy;
 import org.apache.hive.hcatalog.ExitException;
 import org.apache.hive.hcatalog.NoExitSecurityManager;
 import org.apache.hive.hcatalog.cli.SemanticAnalysis.HCatSemanticAnalyzer;
@@ -85,6 +87,7 @@ public class TestPermsGrp extends TestCase {
 
     securityManager = System.getSecurityManager();
     System.setSecurityManager(new NoExitSecurityManager());
+    Policy.setPolicy(new DerbyPolicy());
 
     hcatConf = new HiveConf(this.getClass());
     hcatConf.setVar(HiveConf.ConfVars.METASTOREURIS, "thrift://127.0.0.1:" + 
msPort);
diff --git 
a/hcatalog/core/src/test/java/org/apache/hive/hcatalog/mapreduce/TestHCatPartitionPublish.java
 
b/hcatalog/core/src/test/java/org/apache/hive/hcatalog/mapreduce/TestHCatPartitionPublish.java
index 777fc9c4588..f88d79e9993 100644
--- 
a/hcatalog/core/src/test/java/org/apache/hive/hcatalog/mapreduce/TestHCatPartitionPublish.java
+++ 
b/hcatalog/core/src/test/java/org/apache/hive/hcatalog/mapreduce/TestHCatPartitionPublish.java
@@ -20,6 +20,7 @@ package org.apache.hive.hcatalog.mapreduce;
 
 import java.io.File;
 import java.io.IOException;
+import java.security.Policy;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
@@ -55,6 +56,7 @@ import org.apache.hadoop.mapreduce.Job;
 import org.apache.hadoop.mapreduce.Mapper;
 import org.apache.hadoop.mapreduce.lib.input.TextInputFormat;
 import org.apache.hadoop.util.Shell;
+import org.apache.hive.hcatalog.DerbyPolicy;
 import org.apache.hive.hcatalog.NoExitSecurityManager;
 import org.apache.hive.hcatalog.cli.SemanticAnalysis.HCatSemanticAnalyzer;
 import org.apache.hive.hcatalog.data.DefaultHCatRecord;
@@ -110,6 +112,7 @@ public class TestHCatPartitionPublish {
     isServerRunning = true;
     securityManager = System.getSecurityManager();
     System.setSecurityManager(new NoExitSecurityManager());
+    Policy.setPolicy(new DerbyPolicy());
 
     hcatConf = new HiveConf(TestHCatPartitionPublish.class);
     hcatConf.setVar(HiveConf.ConfVars.METASTOREURIS, "thrift://localhost:"
diff --git 
a/hcatalog/core/src/test/java/org/apache/hive/hcatalog/package-info.java 
b/hcatalog/core/src/test/java/org/apache/hive/hcatalog/package-info.java
new file mode 100644
index 00000000000..a1c304389e6
--- /dev/null
+++ b/hcatalog/core/src/test/java/org/apache/hive/hcatalog/package-info.java
@@ -0,0 +1,22 @@
+/*
+ * 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.
+ */
+
+/**
+ * A package info file for hcatalog tests.
+ */
+package org.apache.hive.hcatalog;
diff --git 
a/hcatalog/webhcat/java-client/src/test/java/org/apache/hive/hcatalog/api/TestHCatClient.java
 
b/hcatalog/webhcat/java-client/src/test/java/org/apache/hive/hcatalog/api/TestHCatClient.java
index 86d3acbcb46..2afce5075c8 100644
--- 
a/hcatalog/webhcat/java-client/src/test/java/org/apache/hive/hcatalog/api/TestHCatClient.java
+++ 
b/hcatalog/webhcat/java-client/src/test/java/org/apache/hive/hcatalog/api/TestHCatClient.java
@@ -20,6 +20,7 @@ package org.apache.hive.hcatalog.api;
 
 import java.io.IOException;
 import java.math.BigInteger;
+import java.security.Policy;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.EnumSet;
@@ -50,6 +51,7 @@ import org.apache.hadoop.hive.ql.metadata.Table;
 import org.apache.hadoop.hive.serde.serdeConstants;
 import org.apache.hadoop.hive.serde2.columnar.LazyBinaryColumnarSerDe;
 import org.apache.hadoop.mapred.TextInputFormat;
+import org.apache.hive.hcatalog.DerbyPolicy;
 import org.apache.hive.hcatalog.api.repl.Command;
 import org.apache.hive.hcatalog.api.repl.ReplicationTask;
 import org.apache.hive.hcatalog.api.repl.ReplicationUtils;
@@ -114,6 +116,8 @@ public class TestHCatClient {
     msPort = MetaStoreUtils.startMetaStore();
     securityManager = System.getSecurityManager();
     System.setSecurityManager(new NoExitSecurityManager());
+    Policy.setPolicy(new DerbyPolicy());
+
     hcatConf.setVar(HiveConf.ConfVars.METASTOREURIS, "thrift://localhost:"
       + msPort);
     hcatConf.setIntVar(HiveConf.ConfVars.METASTORETHRIFTCONNECTIONRETRIES, 3);
diff --git 
a/metastore/src/test/org/apache/hadoop/hive/metastore/TestHiveMetaStoreGetMetaConf.java
 
b/metastore/src/test/org/apache/hadoop/hive/metastore/TestHiveMetaStoreGetMetaConf.java
index da883d20482..3d5141c2091 100644
--- 
a/metastore/src/test/org/apache/hadoop/hive/metastore/TestHiveMetaStoreGetMetaConf.java
+++ 
b/metastore/src/test/org/apache/hadoop/hive/metastore/TestHiveMetaStoreGetMetaConf.java
@@ -18,7 +18,6 @@
 
 package org.apache.hadoop.hive.metastore;
 
-import java.security.Permission;
 import org.apache.hadoop.hive.conf.HiveConf;
 import org.apache.hadoop.hive.metastore.api.MetaException;
 import org.apache.thrift.TException;
@@ -41,40 +40,16 @@ public class TestHiveMetaStoreGetMetaConf {
 
   private static final Logger LOG = 
LoggerFactory.getLogger(TestHiveMetaStoreGetMetaConf.class);
   private static HiveConf hiveConf;
-  private static SecurityManager securityManager;
 
   private HiveMetaStoreClient hmsc;
 
-  public static class NoExitSecurityManager extends SecurityManager {
-
-    @Override
-    public void checkPermission(Permission perm) {
-      // allow anything.
-    }
-
-    @Override
-    public void checkPermission(Permission perm, Object context) {
-      // allow anything.
-    }
-
-    @Override
-    public void checkExit(int status) {
-      super.checkExit(status);
-      throw new RuntimeException("System.exit() was called. Raising 
exception.");
-    }
-  }
-
   @AfterClass
   public static void tearDown() throws Exception {
     LOG.info("Shutting down metastore.");
-    System.setSecurityManager(securityManager);
   }
 
   @BeforeClass
   public static void startMetaStoreServer() throws Exception {
-
-    securityManager = System.getSecurityManager();
-    System.setSecurityManager(new NoExitSecurityManager());
     HiveConf metastoreConf = new HiveConf();
     
metastoreConf.setClass(HiveConf.ConfVars.METASTORE_EXPRESSION_PROXY_CLASS.varname,
       MockPartitionExpressionForMetastore.class, 
PartitionExpressionProxy.class);
diff --git 
a/metastore/src/test/org/apache/hadoop/hive/metastore/TestHiveMetaStorePartitionSpecs.java
 
b/metastore/src/test/org/apache/hadoop/hive/metastore/TestHiveMetaStorePartitionSpecs.java
index 61fe7e1d917..4d54fe541f8 100644
--- 
a/metastore/src/test/org/apache/hadoop/hive/metastore/TestHiveMetaStorePartitionSpecs.java
+++ 
b/metastore/src/test/org/apache/hadoop/hive/metastore/TestHiveMetaStorePartitionSpecs.java
@@ -36,7 +36,6 @@ import org.junit.Test;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import java.security.Permission;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.HashMap;
@@ -51,33 +50,10 @@ public class TestHiveMetaStorePartitionSpecs {
   private static final Logger LOG = 
LoggerFactory.getLogger(TestHiveMetaStorePartitionSpecs.class);
   private static int msPort;
   private static HiveConf hiveConf;
-  private static SecurityManager securityManager;
-
-  public static class NoExitSecurityManager extends SecurityManager {
-
-    @Override
-    public void checkPermission(Permission perm) {
-      // allow anything.
-    }
-
-    @Override
-    public void checkPermission(Permission perm, Object context) {
-      // allow anything.
-    }
-
-    @Override
-    public void checkExit(int status) {
-
-      super.checkExit(status);
-      throw new RuntimeException("System.exit() was called. Raising exception. 
");
-    }
-  }
-
 
   @AfterClass
   public static void tearDown() throws Exception {
     LOG.info("Shutting down metastore.");
-    System.setSecurityManager(securityManager);
 
     HiveMetaStoreClient hmsc = new HiveMetaStoreClient(hiveConf);
     hmsc.dropDatabase(dbName, true, true, true);
@@ -90,8 +66,6 @@ public class TestHiveMetaStorePartitionSpecs {
     
metastoreConf.setClass(HiveConf.ConfVars.METASTORE_EXPRESSION_PROXY_CLASS.varname,
       MockPartitionExpressionForMetastore.class, 
PartitionExpressionProxy.class);
     msPort = MetaStoreUtils.startMetaStore(metastoreConf);
-    securityManager = System.getSecurityManager();
-    System.setSecurityManager(new NoExitSecurityManager());
     hiveConf = new HiveConf(TestHiveMetaStorePartitionSpecs.class);
     hiveConf.setVar(HiveConf.ConfVars.METASTOREURIS, "thrift://localhost:"
         + msPort);

Reply via email to