|
|
|
@@ -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()); |
|
|
|
|