mirror of
https://github.com/apache/rocketmq-dashboard.git
synced 2025-09-10 11:40:01 +08:00
[ISSUE #321] Fix interface permission verification
This commit is contained in:
@@ -19,6 +19,7 @@ package org.apache.rocketmq.dashboard.permisssion;
|
|||||||
import jakarta.annotation.Resource;
|
import jakarta.annotation.Resource;
|
||||||
import jakarta.servlet.http.HttpServletRequest;
|
import jakarta.servlet.http.HttpServletRequest;
|
||||||
import org.apache.rocketmq.dashboard.config.RMQConfigure;
|
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.model.UserInfo;
|
||||||
import org.apache.rocketmq.dashboard.service.PermissionService;
|
import org.apache.rocketmq.dashboard.service.PermissionService;
|
||||||
import org.apache.rocketmq.dashboard.util.WebUtil;
|
import org.apache.rocketmq.dashboard.util.WebUtil;
|
||||||
@@ -55,13 +56,13 @@ public class PermissionAspect {
|
|||||||
HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
|
HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
|
||||||
String url = request.getRequestURI();
|
String url = request.getRequestURI();
|
||||||
UserInfo userInfo = (UserInfo) request.getSession().getAttribute(WebUtil.USER_INFO);
|
UserInfo userInfo = (UserInfo) request.getSession().getAttribute(WebUtil.USER_INFO);
|
||||||
// if (userInfo == null || userInfo.getUser() == null) {
|
if (userInfo == null || userInfo.getUser() == null) {
|
||||||
// throw new ServiceException(-1, "user not login");
|
throw new ServiceException(-1, "user not login");
|
||||||
// }
|
}
|
||||||
// boolean checkResult = permissionService.checkUrlAvailable(userInfo, url);
|
boolean checkResult = permissionService.checkUrlAvailable(userInfo, url);
|
||||||
// if (!checkResult) {
|
if (!checkResult) {
|
||||||
// throw new ServiceException(-1, "no permission");
|
throw new ServiceException(-1, "no permission");
|
||||||
// }
|
}
|
||||||
}
|
}
|
||||||
return joinPoint.proceed();
|
return joinPoint.proceed();
|
||||||
}
|
}
|
||||||
|
@@ -17,8 +17,8 @@
|
|||||||
package org.apache.rocketmq.dashboard.permisssion;
|
package org.apache.rocketmq.dashboard.permisssion;
|
||||||
|
|
||||||
public enum UserRoleEnum {
|
public enum UserRoleEnum {
|
||||||
ADMIN(1, "admin"),
|
SUPER(1, "Super"),
|
||||||
ORDINARY(0, "ordinary");
|
NORMAL(2, "Normal");
|
||||||
|
|
||||||
private int roleType;
|
private int roleType;
|
||||||
private String roleName;
|
private String roleName;
|
||||||
|
@@ -33,8 +33,9 @@ import java.util.List;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
import static org.apache.rocketmq.dashboard.permisssion.UserRoleEnum.ADMIN;
|
import static org.apache.rocketmq.dashboard.permisssion.UserRoleEnum.NORMAL;
|
||||||
import static org.apache.rocketmq.dashboard.permisssion.UserRoleEnum.ORDINARY;
|
import static org.apache.rocketmq.dashboard.permisssion.UserRoleEnum.SUPER;
|
||||||
|
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
public class PermissionServiceImpl implements PermissionService, InitializingBean {
|
public class PermissionServiceImpl implements PermissionService, InitializingBean {
|
||||||
@@ -55,10 +56,10 @@ public class PermissionServiceImpl implements PermissionService, InitializingBea
|
|||||||
public boolean checkUrlAvailable(UserInfo userInfo, String url) {
|
public boolean checkUrlAvailable(UserInfo userInfo, String url) {
|
||||||
int type = userInfo.getUser().getType();
|
int type = userInfo.getUser().getType();
|
||||||
// if it is admin, it could access all resources
|
// if it is admin, it could access all resources
|
||||||
if (type == ADMIN.getRoleType()) {
|
if (type == SUPER.getRoleType()) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
String loginUserRole = ORDINARY.getRoleName();
|
String loginUserRole = NORMAL.getRoleName();
|
||||||
Map<String, List<String>> rolePerms = PermissionFileStore.rolePerms;
|
Map<String, List<String>> rolePerms = PermissionFileStore.rolePerms;
|
||||||
List<String> perms = rolePerms.get(loginUserRole);
|
List<String> perms = rolePerms.get(loginUserRole);
|
||||||
for (String perm : perms) {
|
for (String perm : perms) {
|
||||||
|
@@ -22,12 +22,13 @@
|
|||||||
# **: Matches 0 or more characters.
|
# **: Matches 0 or more characters.
|
||||||
|
|
||||||
rolePerms:
|
rolePerms:
|
||||||
ordinary:
|
Normal:
|
||||||
- /rocketmq/*.query
|
- /rocketmq/*.query
|
||||||
- /ops/*.query
|
- /ops/*.query
|
||||||
- /dashboard/*.query
|
- /dashboard/*.query
|
||||||
- /topic/*.query
|
- /topic/*.query
|
||||||
- /topic/sendTopicMessage.do
|
- /topic/sendTopicMessage.do
|
||||||
|
- /topic/list.queryTopicType
|
||||||
- /producer/*.query
|
- /producer/*.query
|
||||||
- /message/*.query
|
- /message/*.query
|
||||||
- /messageTrace/*.query
|
- /messageTrace/*.query
|
||||||
|
Reference in New Issue
Block a user