Skip to content

Commit 1141d4b

Browse files
author
zengqiao
committed
通过获取类的RequestMapping注解来判断当前请求是否有权限
1 parent cdac92c commit 1141d4b

File tree

1 file changed

+6
-7
lines changed
  • kafka-manager-extends/kafka-manager-account/src/main/java/com/xiaojukeji/kafka/manager/account/impl

1 file changed

+6
-7
lines changed

kafka-manager-extends/kafka-manager-account/src/main/java/com/xiaojukeji/kafka/manager/account/impl/LoginServiceImpl.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ public boolean checkLogin(HttpServletRequest request, HttpServletResponse respon
8484
return false;
8585
}
8686

87-
boolean status = checkAuthority(request, accountService.getAccountRoleFromCache(username));
87+
boolean status = checkAuthority(classRequestMappingValue, accountService.getAccountRoleFromCache(username));
8888
if (status) {
8989
HttpSession session = request.getSession();
9090
session.setAttribute(LoginConstant.SESSION_USERNAME_KEY, username);
@@ -94,19 +94,18 @@ public boolean checkLogin(HttpServletRequest request, HttpServletResponse respon
9494
return false;
9595
}
9696

97-
private boolean checkAuthority(HttpServletRequest request, AccountRoleEnum accountRoleEnum) {
98-
String uri = request.getRequestURI();
99-
if (uri.contains(ApiPrefix.API_V1_NORMAL_PREFIX)) {
97+
private boolean checkAuthority(String classRequestMappingValue, AccountRoleEnum accountRoleEnum) {
98+
if (classRequestMappingValue.equals(ApiPrefix.API_V1_NORMAL_PREFIX)) {
10099
// normal 接口都可以访问
101100
return true;
102101
}
103102

104-
if (uri.contains(ApiPrefix.API_V1_RD_PREFIX) ) {
105-
// RD 接口 OP 或者 RD 可以访问
103+
if (classRequestMappingValue.equals(ApiPrefix.API_V1_RD_PREFIX) ) {
104+
// RD 接口, OP 或者 RD 可以访问
106105
return AccountRoleEnum.RD.equals(accountRoleEnum) || AccountRoleEnum.OP.equals(accountRoleEnum);
107106
}
108107

109-
if (uri.contains(ApiPrefix.API_V1_OP_PREFIX)) {
108+
if (classRequestMappingValue.equals(ApiPrefix.API_V1_OP_PREFIX)) {
110109
// OP 接口只有 OP 可以访问
111110
return AccountRoleEnum.OP.equals(accountRoleEnum);
112111
}

0 commit comments

Comments
 (0)