未验证 提交 29438a11 编写于 作者: H Hu Zongtang 提交者: GitHub

[ISSUE #1078]fix User can't use mqadmin command normally if they don't copy...

[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.
上级 b80c2629
...@@ -18,6 +18,7 @@ package org.apache.rocketmq.acl.common; ...@@ -18,6 +18,7 @@ package org.apache.rocketmq.acl.common;
import java.io.File; import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException; import java.io.IOException;
import java.util.Map; import java.util.Map;
import java.util.SortedMap; import java.util.SortedMap;
...@@ -124,14 +125,15 @@ public class AclUtils { ...@@ -124,14 +125,15 @@ public class AclUtils {
try { try {
fis = new FileInputStream(new File(path)); fis = new FileInputStream(new File(path));
return ymal.loadAs(fis, clazz); return ymal.loadAs(fis, clazz);
} catch (FileNotFoundException ignore) {
return null;
} catch (Exception e) { } 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 { } finally {
if (fis != null) { if (fis != null) {
try { try {
fis.close(); fis.close();
} catch (IOException e) { } catch (IOException ignore) {
throw new AclException("close transport fileInputStream Exception", e);
} }
} }
} }
......
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
*/ */
package org.apache.rocketmq.acl.common; package org.apache.rocketmq.acl.common;
import com.alibaba.fastjson.JSONObject;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
...@@ -133,9 +134,20 @@ public class AclUtilsTest { ...@@ -133,9 +134,20 @@ public class AclUtilsTest {
Assert.assertFalse(map.isEmpty()); 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) @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);
} }
} }
# 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
...@@ -249,11 +249,22 @@ public class MQAdminStartup { ...@@ -249,11 +249,22 @@ public class MQAdminStartup {
public static RPCHook getAclRPCHook() { public static RPCHook getAclRPCHook() {
String fileHome = System.getProperty(MixAll.ROCKETMQ_HOME_PROPERTY, System.getenv(MixAll.ROCKETMQ_HOME_ENV)); String fileHome = System.getProperty(MixAll.ROCKETMQ_HOME_PROPERTY, System.getenv(MixAll.ROCKETMQ_HOME_ENV));
String fileName = "/conf/tools.yml"; String fileName = "/conf/tools.yml";
JSONObject yamlDataObject = AclUtils.getYamlDataObject(fileHome + fileName , JSONObject yamlDataObject = null;
try {
yamlDataObject = AclUtils.getYamlDataObject(fileHome + fileName,
JSONObject.class); 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()) { if (yamlDataObject.isEmpty()) {
System.out.printf(" Cannot find conf file %s, acl is not be enabled.%n" ,fileHome + fileName); System.out.printf("Content of conf file %s is empty, acl isn't be enabled.%n" ,fileHome + fileName);
return null; return null;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册