zhangjidi2016 commented on a change in pull request #6:
URL: https://github.com/apache/rocketmq-dashboard/pull/6#discussion_r690827669



##########
File path: 
src/main/java/org/apache/rocketmq/dashboard/service/impl/PermissionServiceImpl.java
##########
@@ -0,0 +1,119 @@
+/*
+ * 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.rocketmq.dashboard.service.impl;
+
+import com.alibaba.fastjson.JSONObject;
+import java.io.File;
+import java.io.FileReader;
+import java.io.InputStream;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+import javax.annotation.Resource;
+import org.apache.rocketmq.dashboard.config.RMQConfigure;
+import org.apache.rocketmq.dashboard.exception.ServiceException;
+import org.apache.rocketmq.dashboard.service.PermissionService;
+import org.apache.rocketmq.srvutil.FileWatchService;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.InitializingBean;
+import org.springframework.stereotype.Service;
+import org.yaml.snakeyaml.Yaml;
+
+@Service
+public class PermissionServiceImpl implements PermissionService, 
InitializingBean {
+
+    @Resource
+    RMQConfigure configure;
+
+    FileBasedPermissionStore fileBasedPermissionStore;
+
+    @Override
+    public Map<String, List<String>> queryRolePerms() {
+        return fileBasedPermissionStore.rolePerms;
+    }
+
+    @Override
+    public void afterPropertiesSet() {
+        if (configure.isLoginRequired()) {
+            fileBasedPermissionStore = new FileBasedPermissionStore(configure);
+        }
+    }
+
+    public static class FileBasedPermissionStore {

Review comment:
       Okay, I'll re-optimize the code as suggested.

##########
File path: 
src/main/java/org/apache/rocketmq/dashboard/permisssion/PermissionAspect.java
##########
@@ -0,0 +1,82 @@
+/*
+ * 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.rocketmq.dashboard.permisssion;
+
+import java.util.List;
+import java.util.Map;
+import javax.annotation.Resource;
+import javax.servlet.http.HttpServletRequest;
+import org.apache.rocketmq.dashboard.config.RMQConfigure;
+import org.apache.rocketmq.dashboard.exception.ServiceException;
+import org.apache.rocketmq.dashboard.model.UserInfo;
+import org.apache.rocketmq.dashboard.service.PermissionService;
+import org.apache.rocketmq.dashboard.util.WebUtil;
+import org.aspectj.lang.ProceedingJoinPoint;
+import org.aspectj.lang.annotation.Around;
+import org.aspectj.lang.annotation.Aspect;
+import org.aspectj.lang.annotation.Pointcut;
+import org.springframework.stereotype.Component;
+import org.springframework.web.context.request.RequestContextHolder;
+import org.springframework.web.context.request.ServletRequestAttributes;
+
+@Aspect
+@Component
+public class PermissionAspect {
+
+    public static final String ORDINARY = "ordinary";
+    public static final String ADMIN = "admin";
+
+    @Resource
+    private RMQConfigure configure;
+
+    @Resource
+    private PermissionService permissionService;
+
+    /**
+     * @Permission can be applied to the Controller class to implement 
Permission verification on all methods in the class
+     * can also be applied to methods in a class for fine control
+     */
+    
@Pointcut("@annotation(org.apache.rocketmq.dashboard.permisssion.Permission) || 
@within(org.apache.rocketmq.dashboard.permisssion.Permission)")
+    private void permission() {

Review comment:
       Yes,it can work,@within - limits matching to join points within types 
that have the given annotation (the execution of methods declared in types with 
the given annotation when using Spring AOP).

##########
File path: 
src/main/java/org/apache/rocketmq/dashboard/controller/ConsumerController.java
##########
@@ -37,6 +38,7 @@
 
 @Controller
 @RequestMapping("/consumer")
+@Permission

Review comment:
       The @permission annotation is on a class in which all the methods of the 
class will implement aop methods. There is no need to annotate each method




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


Reply via email to