winter 1 год назад
Родитель
Сommit
74d7d223ba
4 измененных файлов: 47 добавлений и 18 удалений
  1. +0
    -5
      mallinkBApi/src/main/java/com/iformall/controller/BaseController.java
  2. +2
    -2
      mallinkBApi/src/main/java/com/iformall/controller/WxInfoController.java
  3. +1
    -0
      mallinkBApi/src/main/java/com/iformall/controller/WxMallAdminController.java
  4. +44
    -11
      mallinkBApi/src/main/java/com/iformall/interceptor/AuthorizationInterceptor.java

+ 0
- 5
mallinkBApi/src/main/java/com/iformall/controller/BaseController.java Просмотреть файл

@@ -214,11 +214,6 @@ public class BaseController {
}
}
public void setLoginMallUserInfo(MallUserInfo user) {
HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
request.setAttribute(Constant.REQUEST_MALL_USER_KEY, user);
}
public MallUserInfo getLoginMallUserInfo() {
HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
MallUserInfo user = (MallUserInfo) request.getAttribute(Constant.REQUEST_MALL_USER_KEY);


+ 2
- 2
mallinkBApi/src/main/java/com/iformall/controller/WxInfoController.java Просмотреть файл

@@ -17,6 +17,7 @@ import com.iformall.enums.EnumMenuType;
import com.iformall.exception.MallinkException;
import com.iformall.service.*;
import com.iformall.service.cuser.CUserServiceFactory;
import com.iformall.utils.Constant;
import com.iformall.utils.IPUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
@@ -290,8 +291,7 @@ public class WxInfoController extends BaseController {

user.setBopenId(buser.getOpenId());
mallUserInfoService.saveOrUpdate(user);
setLoginMallUserInfo(user);
resultMap.put("adminUserId", user.getId().toString());
return new ResultData(resultMap);
} else {
return new ResultData(ErrorCode.USER_NO_PERMISSION.getCode(),user.getName()+"不是超管或者没有"+EnumMenuType.MOBILE_ADMIN.getMessage()+"的权限", resultMap);


+ 1
- 0
mallinkBApi/src/main/java/com/iformall/controller/WxMallAdminController.java Просмотреть файл

@@ -1,6 +1,7 @@
package com.iformall.controller;

import com.github.pagehelper.PageInfo;
import com.iformall.annotation.AuthIgnore;
import com.iformall.common.ErrorCode;
import com.iformall.common.Result;
import com.iformall.common.ResultData;


+ 44
- 11
mallinkBApi/src/main/java/com/iformall/interceptor/AuthorizationInterceptor.java Просмотреть файл

@@ -6,11 +6,13 @@ import com.iformall.annotation.AuthIgnore;
import com.iformall.annotation.TenantIgnore;
import com.iformall.common.ErrorCode;
import com.iformall.common.TenantThreadLocal;
import com.iformall.domain.po.MallUserInfo;
import com.iformall.domain.po.WxMall;
import com.iformall.domain.po.WxMerchantBUser;
import com.iformall.domain.po.base.BaseCUserEntity;
import com.iformall.exception.MallinkException;
import com.iformall.service.CUserTokenService;
import com.iformall.service.MallUserInfoService;
import com.iformall.service.WxMallService;
import com.iformall.service.WxMerchantBUserService;
import com.iformall.utils.Constant;
@@ -44,6 +46,9 @@ public class AuthorizationInterceptor extends HandlerInterceptorAdapter {

@Autowired
private WxMallService wxMallService;
@Autowired
private MallUserInfoService mallUserInfoService;

@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
@@ -71,9 +76,15 @@ public class AuthorizationInterceptor extends HandlerInterceptorAdapter {
if(StringUtils.isBlank(bid)){
bid = request.getParameter("bid");
}
//商管操作台
String adminUserId = request.getHeader("adminUserId");
if(StringUtils.isBlank(adminUserId)){
adminUserId = request.getParameter("adminUserId");
}

//token为空,
if(StringUtils.isBlank(token) && StringUtils.isBlank(bid)){
if(StringUtils.isBlank(token) && StringUtils.isBlank(bid) && StringUtils.isBlank(adminUserId)){
throw new MallinkException(ErrorCode.NET_TOKEN_EMPTY);
}
@@ -86,6 +97,7 @@ public class AuthorizationInterceptor extends HandlerInterceptorAdapter {
WxMerchantBUser buser = null;
String tenantId = null;
String parenTenantId = null;
MallUserInfo adminUser = null;
if (StringUtils.isNotBlank(token)) {
BaseCUserEntity user = cUserTokenService.getBByToken(token);
if (user == null || user.getExpireTime().getTime() < System.currentTimeMillis()) {
@@ -98,10 +110,16 @@ public class AuthorizationInterceptor extends HandlerInterceptorAdapter {
}
}else if (StringUtils.isNotBlank(bid)) {
buser = wxMerchantBUserService.getById(Long.parseLong(bid));
}else if (StringUtils.isNotBlank(adminUserId)) {
adminUser = mallUserInfoService.getById(Long.parseLong(adminUserId));
if (null == adminUser) {
throw new MallinkException(ErrorCode.NET_TOKEN_INVALID.getCode(), "URL:" + request.getRequestURL() + " adminUserId失效,请重新登录");
}
request.setAttribute(Constant.REQUEST_MALL_USER_KEY, adminUser);
}

if (buser == null) {
throw new MallinkException(ErrorCode.NET_TOKEN_INVALID.getCode(), "URL:" + request.getRequestURL() + " bid失效,请重新登录");
if (buser == null && adminUser == null) {
throw new MallinkException(ErrorCode.NET_TOKEN_INVALID.getCode(), "URL:" + request.getRequestURL() + " 登录失效,请重新登录");
}

if(StringUtils.isNotBlank(mallTenantId) && !"undefined".equals(mallTenantId)){
@@ -111,16 +129,31 @@ public class AuthorizationInterceptor extends HandlerInterceptorAdapter {
parenTenantId = mall.getParentTenantId();
}
}else{
tenantId = buser.getTenantId();
if (StringUtils.isNotBlank(buser.getParentTenantId())) {
parenTenantId = buser.getParentTenantId();
}
if (null != buser) {
tenantId = buser.getTenantId();
if (StringUtils.isNotBlank(buser.getParentTenantId())) {
parenTenantId = buser.getParentTenantId();
}
}else if (null != adminUser) {
tenantId = adminUser.getTenantId();
if (StringUtils.isNotBlank(adminUser.getParentTenantId())) {
parenTenantId = adminUser.getParentTenantId();
}
}
}

if(!tenantId.equals(buser.getTenantId())
&& !buser.getTenantId().equals(parenTenantId)
&& !tenantId.equals(buser.getParentTenantId())){
throw new MallinkException(ErrorCode.SYS_AUTH_ERROR);
if (null != buser) {
if(!tenantId.equals(buser.getTenantId())
&& !buser.getTenantId().equals(parenTenantId)
&& !tenantId.equals(buser.getParentTenantId())){
throw new MallinkException(ErrorCode.SYS_AUTH_ERROR);
}
}else if (null != adminUser) {
if(!tenantId.equals(adminUser.getTenantId())
&& !adminUser.getTenantId().equals(parenTenantId)
&& !tenantId.equals(adminUser.getParentTenantId())){
throw new MallinkException(ErrorCode.SYS_AUTH_ERROR);
}
}

request.setAttribute(Constant.LOGIN_B_USER_KEY, buser.getId());


Загрузка…
Отмена
Сохранить