Commit 4a36c309 authored by suntao's avatar suntao

跨域问题

parent 4c1df48c
...@@ -2,6 +2,7 @@ package cn.quantgroup.cashloanflowboss.core.aspect; ...@@ -2,6 +2,7 @@ package cn.quantgroup.cashloanflowboss.core.aspect;
import cn.quantgroup.cashloanflowboss.api.channel.model.ChannelConfVo; import cn.quantgroup.cashloanflowboss.api.channel.model.ChannelConfVo;
import cn.quantgroup.cashloanflowboss.api.channel.util.ChannelConfUtil; import cn.quantgroup.cashloanflowboss.api.channel.util.ChannelConfUtil;
import cn.quantgroup.cashloanflowboss.api.log.model.Principal;
import cn.quantgroup.cashloanflowboss.core.Application; import cn.quantgroup.cashloanflowboss.core.Application;
import cn.quantgroup.cashloanflowboss.core.annotation.ChannelIdInit; import cn.quantgroup.cashloanflowboss.core.annotation.ChannelIdInit;
import cn.quantgroup.cashloanflowboss.core.annotation.CheckChannelRole; import cn.quantgroup.cashloanflowboss.core.annotation.CheckChannelRole;
...@@ -57,20 +58,31 @@ public class RoleLoadAspect { ...@@ -57,20 +58,31 @@ public class RoleLoadAspect {
MethodSignature methodSignature = (MethodSignature) pjp.getSignature(); MethodSignature methodSignature = (MethodSignature) pjp.getSignature();
Method method = methodSignature.getMethod(); Method method = methodSignature.getMethod();
Principal principal = Application.getPrincipal();
if (principal == null) {
try {
// 没有登录 登录检查控制
return pjp.proceed(args);
} catch (Throwable throwable) {
log.error("请求失败,e={}", ExceptionUtils.getStackTrace(throwable));
return Result.buildFial();
}
}
// 如果是渠道用户登陆 默认加载channelId // 如果是渠道用户登陆 默认加载channelId
ChannelIdInit annotation = method.getAnnotation(ChannelIdInit.class); ChannelIdInit annotation = method.getAnnotation(ChannelIdInit.class);
if (annotation != null && Application.getPrincipal().isChannel()) { if (annotation != null && principal.isChannel()) {
String[] paramNames = ((CodeSignature) pjp.getSignature()).getParameterNames(); String[] paramNames = ((CodeSignature) pjp.getSignature()).getParameterNames();
for (int i = 0; i < paramNames.length; i++) { for (int i = 0; i < paramNames.length; i++) {
if (ChannelConfUtil.channelIdParamName.equals(paramNames[i])) { if (ChannelConfUtil.channelIdParamName.equals(paramNames[i])) {
args[i] = Application.getPrincipal().getChannelId(); args[i] = principal.getChannelId();
} }
} }
} }
// 如果是渠道用户登陆,参数中channelId 不是登陆用户channelId,返回 拒绝请求 // 如果是渠道用户登陆,参数中channelId 不是登陆用户channelId,返回 拒绝请求
CheckChannelRole checkChannelRole = method.getAnnotation(CheckChannelRole.class); CheckChannelRole checkChannelRole = method.getAnnotation(CheckChannelRole.class);
if (checkChannelRole != null && Application.getPrincipal().isChannel()) { if (checkChannelRole != null && principal.isChannel()) {
Long requestChannelId = -1L; Long requestChannelId = -1L;
if (!checkChannelRole.isObjParam()) { if (!checkChannelRole.isObjParam()) {
String[] paramNames = ((CodeSignature) pjp.getSignature()).getParameterNames(); String[] paramNames = ((CodeSignature) pjp.getSignature()).getParameterNames();
...@@ -84,7 +96,7 @@ public class RoleLoadAspect { ...@@ -84,7 +96,7 @@ public class RoleLoadAspect {
return Result.buildFial(ApplicationStatus.ARGUMENT_VALID_EXCEPTION); return Result.buildFial(ApplicationStatus.ARGUMENT_VALID_EXCEPTION);
} }
requestChannelId = Long.valueOf(String.valueOf(requestChannelIdObj)); requestChannelId = Long.valueOf(String.valueOf(requestChannelIdObj));
if (!Application.getPrincipal().isSameChannel(requestChannelId)) { if (!principal.isSameChannel(requestChannelId)) {
log.info("[CheckChannelRole]渠道用户,登陆channelId与查询channelId不是同一个"); log.info("[CheckChannelRole]渠道用户,登陆channelId与查询channelId不是同一个");
return Result.buildFial(ApplicationStatus.INVALID_AUTHORITY); return Result.buildFial(ApplicationStatus.INVALID_AUTHORITY);
} }
...@@ -102,7 +114,7 @@ public class RoleLoadAspect { ...@@ -102,7 +114,7 @@ public class RoleLoadAspect {
requestChannelId = channelIdTemp; requestChannelId = channelIdTemp;
} }
} }
if (!Application.getPrincipal().isSameChannel(requestChannelId)) { if (!principal.isSameChannel(requestChannelId)) {
log.info("[CheckChannelRole]渠道用户,登陆channelId与查询channelId不是同一个"); log.info("[CheckChannelRole]渠道用户,登陆channelId与查询channelId不是同一个");
return Result.buildFial(ApplicationStatus.INVALID_AUTHORITY); return Result.buildFial(ApplicationStatus.INVALID_AUTHORITY);
} }
...@@ -111,7 +123,7 @@ public class RoleLoadAspect { ...@@ -111,7 +123,7 @@ public class RoleLoadAspect {
// 如果是渠道用户登陆,参数中channelOrderNumber 不是登陆用户channelOrderNumber,返回 拒绝请求 // 如果是渠道用户登陆,参数中channelOrderNumber 不是登陆用户channelOrderNumber,返回 拒绝请求
CheckChannelRoleByChannelOrderNumber checkChannelRoleByChannelOrderNumber = method.getAnnotation(CheckChannelRoleByChannelOrderNumber.class); CheckChannelRoleByChannelOrderNumber checkChannelRoleByChannelOrderNumber = method.getAnnotation(CheckChannelRoleByChannelOrderNumber.class);
if (checkChannelRoleByChannelOrderNumber != null && Application.getPrincipal().isChannel()) { if (checkChannelRoleByChannelOrderNumber != null && principal.isChannel()) {
String[] paramNames = ((CodeSignature) pjp.getSignature()).getParameterNames(); String[] paramNames = ((CodeSignature) pjp.getSignature()).getParameterNames();
String channelOrderNumber = ""; String channelOrderNumber = "";
for (int i = 0; i < paramNames.length; i++) { for (int i = 0; i < paramNames.length; i++) {
...@@ -128,7 +140,7 @@ public class RoleLoadAspect { ...@@ -128,7 +140,7 @@ public class RoleLoadAspect {
log.info("[CheckChannelRoleByChannelOrderNumber]无channelOrderNumber数据,channelOrderNumber={}",channelOrderNumber); log.info("[CheckChannelRoleByChannelOrderNumber]无channelOrderNumber数据,channelOrderNumber={}",channelOrderNumber);
return Result.buildFial(ApplicationStatus.ARGUMENT_VALID_EXCEPTION, "未找到该订单"); return Result.buildFial(ApplicationStatus.ARGUMENT_VALID_EXCEPTION, "未找到该订单");
} }
if (!clfOrderMapping.getRegisteredFrom().equals(Application.getPrincipal().getChannelId())) { if (!clfOrderMapping.getRegisteredFrom().equals(principal.getChannelId())) {
log.info("[CheckChannelRoleByChannelOrderNumber]不是该渠道的订单,channelOrderNumber={}",channelOrderNumber); log.info("[CheckChannelRoleByChannelOrderNumber]不是该渠道的订单,channelOrderNumber={}",channelOrderNumber);
return Result.buildFial(ApplicationStatus.INVALID_AUTHORITY); return Result.buildFial(ApplicationStatus.INVALID_AUTHORITY);
} }
......
package cn.quantgroup.cashloanflowboss.core.configuration;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
/**
* function:
* date: 2019/8/20
*
* @author: suntao
*/
//@Configuration
public class CorsConfiguration {//extends WebMvcConfigurerAdapter{
//@Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/**")
.allowedMethods("*")
.allowedOrigins("*")
.allowedHeaders("*");
//super.addCorsMappings(registry);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment