1. admin-web 接入菜单
2. system 迁移菜单接口
This commit is contained in:
@@ -14,5 +14,9 @@ public class AdminSecurityContext {
|
||||
* 管理员编号
|
||||
*/
|
||||
private Integer adminId;
|
||||
/**
|
||||
* 账号编号
|
||||
*/
|
||||
private Integer accountId;
|
||||
|
||||
}
|
||||
|
||||
@@ -27,4 +27,12 @@ public class AdminSecurityContextHolder {
|
||||
SECURITY_CONTEXT.remove();
|
||||
}
|
||||
|
||||
public static Integer getAdminId() {
|
||||
return getContext().getAdminId();
|
||||
}
|
||||
|
||||
public static Integer getAccountId() {
|
||||
return getContext().getAccountId();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -6,12 +6,15 @@ import cn.iocoder.mall.security.core.context.AdminSecurityContext;
|
||||
import cn.iocoder.mall.security.core.context.AdminSecurityContextHolder;
|
||||
import cn.iocoder.mall.system.rpc.api.admin.AdminRPC;
|
||||
import cn.iocoder.mall.system.rpc.response.admin.AdminResponse;
|
||||
import cn.iocoder.mall.web.core.util.CommonWebUtil;
|
||||
import org.apache.dubbo.config.annotation.Reference;
|
||||
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import static cn.iocoder.mall.system.biz.enums.SystemErrorCodeEnum.ADMIN_NOT_FOUND;
|
||||
|
||||
public class AdminSecurityInterceptor extends HandlerInterceptorAdapter {
|
||||
|
||||
@Reference(validation = "true", version = "${dubbo.consumer.AdminRPC.version}")
|
||||
@@ -19,16 +22,20 @@ public class AdminSecurityInterceptor extends HandlerInterceptorAdapter {
|
||||
|
||||
@Override
|
||||
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) {
|
||||
Integer accountId = AdminSecurityContextHolder.getContext().getAdminId();
|
||||
Integer accountId = CommonWebUtil.getAccountId(request);
|
||||
if (accountId != null) {
|
||||
// 获得 Admin 信息
|
||||
CommonResult<AdminResponse> adminResult = adminRPC.getAdminByAccountId(accountId);
|
||||
if (adminResult.isError()) {
|
||||
throw ServiceExceptionUtil.exception(adminResult);
|
||||
}
|
||||
if (adminResult.getData() == null) {
|
||||
throw ServiceExceptionUtil.exception(ADMIN_NOT_FOUND);
|
||||
}
|
||||
// 设置到 SecurityContext 中
|
||||
AdminResponse adminResponse = adminResult.getData();
|
||||
AdminSecurityContext context = new AdminSecurityContext().setAdminId(adminResponse.getId());
|
||||
AdminSecurityContext context = new AdminSecurityContext().setAdminId(adminResponse.getId())
|
||||
.setAccountId(accountId);
|
||||
AdminSecurityContextHolder.setContext(context);
|
||||
}
|
||||
return true;
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
package cn.iocoder.mall.security.core.interceptor;
|
||||
|
||||
import cn.iocoder.common.framework.util.ExceptionUtil;
|
||||
import cn.iocoder.common.framework.util.ServiceExceptionUtil;
|
||||
import cn.iocoder.common.framework.vo.CommonResult;
|
||||
import cn.iocoder.mall.security.core.context.AdminSecurityContextHolder;
|
||||
import cn.iocoder.mall.security.core.context.UserSecurityContext;
|
||||
import cn.iocoder.mall.security.core.context.UserSecurityContextHolder;
|
||||
import cn.iocoder.mall.system.rpc.api.user.UserRPC;
|
||||
import cn.iocoder.mall.system.rpc.response.user.UserResponse;
|
||||
import cn.iocoder.mall.web.core.util.CommonWebUtil;
|
||||
import org.apache.dubbo.config.annotation.Reference;
|
||||
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
|
||||
|
||||
@@ -20,13 +21,16 @@ public class UserSecurityInterceptor extends HandlerInterceptorAdapter {
|
||||
|
||||
@Override
|
||||
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) {
|
||||
Integer accountId = AdminSecurityContextHolder.getContext().getAdminId();
|
||||
Integer accountId = CommonWebUtil.getAccountId(request);
|
||||
if (accountId != null) {
|
||||
// 获得 Admin 信息
|
||||
CommonResult<UserResponse> userResult = userRPC.getUserByAccountId(accountId);
|
||||
if (userResult.isError()) {
|
||||
throw ServiceExceptionUtil.exception(userResult);
|
||||
}
|
||||
if (userResult.getData() == null) {
|
||||
throw ExceptionUtil.getServiceException(null); // TODO 需要完善
|
||||
}
|
||||
// 设置到 SecurityContext 中
|
||||
UserResponse userResponse = userResult.getData();
|
||||
UserSecurityContext context = new UserSecurityContext().setUserId(userResponse.getId());
|
||||
|
||||
Reference in New Issue
Block a user