This is an automated email from the ASF dual-hosted git repository.
huzongtang pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/rocketmq.git
The following commit(s) were added to refs/heads/develop by this push:
new 29438a1 [ISSUE #1078]fix User can't use mqadmin command normally if they don't copy
the tool.yml file to related fold and AclEnable flag is closed. (#1079)
29438a1 is described below
commit 29438a11c1569040ee9cb8f9c13ae3b0030e3405
Author: Hu Zongtang <huzongtang@cmss.chinamobile.com>
AuthorDate: Wed Apr 10 10:03:34 2019 +0800
[ISSUE #1078]fix User can't use mqadmin command normally if they don't copy the tool.yml
file to related fold and AclEnable flag is closed. (#1079)
* [issue#1078]fix User can't use mqadmin command normally if they don't copy the tool.yml
file to their related fold and AclEnable flag is closed.
---
.../org/apache/rocketmq/acl/common/AclUtils.java | 8 ++++---
.../apache/rocketmq/acl/common/AclUtilsTest.java | 16 +++++++++++--
.../test/resources/conf/plain_acl_format_error.yml | 26 ++++++++++++++++++++++
.../rocketmq/tools/command/MQAdminStartup.java | 17 +++++++++++---
4 files changed, 59 insertions(+), 8 deletions(-)
diff --git a/acl/src/main/java/org/apache/rocketmq/acl/common/AclUtils.java b/acl/src/main/java/org/apache/rocketmq/acl/common/AclUtils.java
index 1a61845..ce63cbf 100644
--- a/acl/src/main/java/org/apache/rocketmq/acl/common/AclUtils.java
+++ b/acl/src/main/java/org/apache/rocketmq/acl/common/AclUtils.java
@@ -18,6 +18,7 @@ package org.apache.rocketmq.acl.common;
import java.io.File;
import java.io.FileInputStream;
+import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Map;
import java.util.SortedMap;
@@ -124,14 +125,15 @@ public class AclUtils {
try {
fis = new FileInputStream(new File(path));
return ymal.loadAs(fis, clazz);
+ } catch (FileNotFoundException ignore) {
+ return null;
} catch (Exception e) {
- throw new AclException(String.format("The file for Plain mode was not found
, paths %s", path), e);
+ throw new AclException(e.getMessage());
} finally {
if (fis != null) {
try {
fis.close();
- } catch (IOException e) {
- throw new AclException("close transport fileInputStream Exception", e);
+ } catch (IOException ignore) {
}
}
}
diff --git a/acl/src/test/java/org/apache/rocketmq/acl/common/AclUtilsTest.java b/acl/src/test/java/org/apache/rocketmq/acl/common/AclUtilsTest.java
index 72bcda6..12f4372 100644
--- a/acl/src/test/java/org/apache/rocketmq/acl/common/AclUtilsTest.java
+++ b/acl/src/test/java/org/apache/rocketmq/acl/common/AclUtilsTest.java
@@ -16,6 +16,7 @@
*/
package org.apache.rocketmq.acl.common;
+import com.alibaba.fastjson.JSONObject;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
@@ -133,9 +134,20 @@ public class AclUtilsTest {
Assert.assertFalse(map.isEmpty());
}
+ @Test
+ public void getYamlDataIgnoreFileNotFoundExceptionTest() {
+
+ JSONObject yamlDataObject = AclUtils.getYamlDataObject("plain_acl.yml", JSONObject.class);
+ Assert.assertTrue(yamlDataObject == null);
+ }
+
@Test(expected = Exception.class)
- public void getYamlDataObjectExceptionTest() {
+ public void getYamlDataExceptionTest() {
- AclUtils.getYamlDataObject("plain_acl.yml", Map.class);
+ AclUtils.getYamlDataObject("src/test/resources/conf/plain_acl_format_error.yml",
Map.class);
}
+
+
+
+
}
diff --git a/acl/src/test/resources/conf/plain_acl_format_error.yml b/acl/src/test/resources/conf/plain_acl_format_error.yml
new file mode 100644
index 0000000..46782c5
--- /dev/null
+++ b/acl/src/test/resources/conf/plain_acl_format_error.yml
@@ -0,0 +1,26 @@
+# 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.
+
+## suggested format
+
+date 2015-02-01
+accounts:
+ - name: Jai
+accounts:
+- accessKey: RocketMQ
+ secretKey: 12345678
+ whiteRemoteAddress: 192.168.0.*
+ admin: false
+
diff --git a/tools/src/main/java/org/apache/rocketmq/tools/command/MQAdminStartup.java b/tools/src/main/java/org/apache/rocketmq/tools/command/MQAdminStartup.java
index 2ca60aa..da71513 100644
--- a/tools/src/main/java/org/apache/rocketmq/tools/command/MQAdminStartup.java
+++ b/tools/src/main/java/org/apache/rocketmq/tools/command/MQAdminStartup.java
@@ -249,11 +249,22 @@ public class MQAdminStartup {
public static RPCHook getAclRPCHook() {
String fileHome = System.getProperty(MixAll.ROCKETMQ_HOME_PROPERTY, System.getenv(MixAll.ROCKETMQ_HOME_ENV));
String fileName = "/conf/tools.yml";
- JSONObject yamlDataObject = AclUtils.getYamlDataObject(fileHome + fileName ,
+ JSONObject yamlDataObject = null;
+ try {
+ yamlDataObject = AclUtils.getYamlDataObject(fileHome + fileName,
JSONObject.class);
+ } catch (Exception e) {
+ e.printStackTrace();
+ return null;
+ }
+
+ if (yamlDataObject == null) {
+ System.out.printf("Cannot find conf file %s, acl isn't be enabled.%n" ,fileHome
+ fileName);
+ return null;
+ }
- if (yamlDataObject == null || yamlDataObject.isEmpty()) {
- System.out.printf(" Cannot find conf file %s, acl is not be enabled.%n" ,fileHome
+ fileName);
+ if (yamlDataObject.isEmpty()) {
+ System.out.printf("Content of conf file %s is empty, acl isn't be enabled.%n"
,fileHome + fileName);
return null;
}
|