Commit 0ffcaad5 authored by WeiWei's avatar WeiWei

删除channel_user表及相关类

parent 56d0da8a
package cn.quantgroup.cashloanflowboss.api.channel.controller; package cn.quantgroup.cashloanflowboss.api.channel.controller;
import cn.quantgroup.cashloanflowboss.api.channel.model.ChannelConfAddModel;
import cn.quantgroup.cashloanflowboss.api.channel.model.ChannelConfBaseModel;
import cn.quantgroup.cashloanflowboss.api.channel.model.ChannelConfVo; import cn.quantgroup.cashloanflowboss.api.channel.model.ChannelConfVo;
import cn.quantgroup.cashloanflowboss.core.annotation.ChannelIdInit;
import cn.quantgroup.cashloanflowboss.api.channel.service.ChannelConfService; import cn.quantgroup.cashloanflowboss.api.channel.service.ChannelConfService;
import cn.quantgroup.cashloanflowboss.core.annotation.ChannelIdInit;
import cn.quantgroup.cashloanflowboss.core.annotation.CheckChannelRole; import cn.quantgroup.cashloanflowboss.core.annotation.CheckChannelRole;
import cn.quantgroup.cashloanflowboss.api.user.model.Pagination;
import cn.quantgroup.cashloanflowboss.core.base.Result; import cn.quantgroup.cashloanflowboss.core.base.Result;
import cn.quantgroup.cashloanflowboss.utils.JSONTools;
import com.alibaba.fastjson.JSONObject;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
...@@ -17,6 +12,7 @@ import javax.validation.Valid; ...@@ -17,6 +12,7 @@ import javax.validation.Valid;
/** /**
* Created with suntao on 2019/8/2 * Created with suntao on 2019/8/2
*
* @author suntao * @author suntao
*/ */
@RestController @RestController
...@@ -30,7 +26,8 @@ public class ChannelConfController { ...@@ -30,7 +26,8 @@ public class ChannelConfController {
/** /**
* 查询渠道列表 * 查询渠道列表
* @param channelId 在接受参数时,必须放到第一个参数位置 *
* @param channelId 在接受参数时,必须放到第一个参数位置
* @param pageNumber * @param pageNumber
* @param pageSize * @param pageSize
* @return * @return
...@@ -49,12 +46,11 @@ public class ChannelConfController { ...@@ -49,12 +46,11 @@ public class ChannelConfController {
} }
@CheckChannelRole(isObjParam = true ,paramClazz = ChannelConfVo.class) @CheckChannelRole(isObjParam = true, paramClazz = ChannelConfVo.class)
@PostMapping("/cfg/info") @PostMapping("/cfg/info")
public Result editChannelConfInfo(@RequestBody @Valid ChannelConfVo channelConfVo) { public Result editChannelConfInfo(@RequestBody @Valid ChannelConfVo channelConfVo) {
return Result.buildSuccess(channelConfService.editChannelConfInfo(channelConfVo)); return Result.buildSuccess(channelConfService.editChannelConfInfo(channelConfVo));
} }
} }
...@@ -26,7 +26,7 @@ public class Principal { ...@@ -26,7 +26,7 @@ public class Principal {
/** /**
* 所属渠道ID * 所属渠道ID
*/ */
private String channelId; private Long channelId;
/** /**
* 角色列表 * 角色列表
...@@ -69,4 +69,14 @@ public class Principal { ...@@ -69,4 +69,14 @@ public class Principal {
return Objects.nonNull(this.rank) && UserRank.CHANNEL.equals(this.rank); return Objects.nonNull(this.rank) && UserRank.CHANNEL.equals(this.rank);
} }
/**
* 判断当前用户和渠道参数是否相同
*
* @param channelId
* @return
*/
public boolean isSameChannel(Long channelId) {
return Objects.nonNull(channelId) && channelId.equals(this.channelId);
}
} }
...@@ -55,6 +55,7 @@ public class LogService { ...@@ -55,6 +55,7 @@ public class LogService {
// 设置用户主要信息 // 设置用户主要信息
Principal principal = new Principal(); Principal principal = new Principal();
principal.setUserId(user.getId()); principal.setUserId(user.getId());
principal.setChannelId(user.getChannelId());
principal.setRank(user.getRank()); principal.setRank(user.getRank());
principal.setRoles(user.getRoles()); principal.setRoles(user.getRoles());
......
...@@ -6,7 +6,6 @@ import cn.quantgroup.cashloanflowboss.api.order.model.ApproveVo; ...@@ -6,7 +6,6 @@ import cn.quantgroup.cashloanflowboss.api.order.model.ApproveVo;
import cn.quantgroup.cashloanflowboss.api.order.model.OrderVo; import cn.quantgroup.cashloanflowboss.api.order.model.OrderVo;
import cn.quantgroup.cashloanflowboss.api.order.util.OrderUtil; import cn.quantgroup.cashloanflowboss.api.order.util.OrderUtil;
import cn.quantgroup.cashloanflowboss.api.user.model.UserSessionInfo; import cn.quantgroup.cashloanflowboss.api.user.model.UserSessionInfo;
import cn.quantgroup.cashloanflowboss.api.user.service.UserSessionService;
import cn.quantgroup.cashloanflowboss.spi.clf.entity.ClfOrderMapping; import cn.quantgroup.cashloanflowboss.spi.clf.entity.ClfOrderMapping;
import cn.quantgroup.cashloanflowboss.spi.clf.repository.ClfOrderMappingRepository; import cn.quantgroup.cashloanflowboss.spi.clf.repository.ClfOrderMappingRepository;
import cn.quantgroup.cashloanflowboss.spi.clotho.service.ClothoCenter; import cn.quantgroup.cashloanflowboss.spi.clotho.service.ClothoCenter;
...@@ -34,9 +33,6 @@ import java.util.*; ...@@ -34,9 +33,6 @@ import java.util.*;
@Service @Service
public class OrderService { public class OrderService {
@Autowired
private UserSessionService userSessionService;
@Autowired @Autowired
private ChannelConfRepository channelConfRepository; private ChannelConfRepository channelConfRepository;
@Autowired @Autowired
...@@ -96,10 +92,11 @@ public class OrderService { ...@@ -96,10 +92,11 @@ public class OrderService {
return false; return false;
} }
UserSessionInfo userSessionInfo = userSessionService.findUserSessionInfo(); // 可以查看Application.getPrincipal()方法
if (!userSessionInfo.getChannelId().equals(orderMapping.getRegisteredFrom())) { // UserSessionInfo userSessionInfo = userSessionService.findUserSessionInfo();
// if (!userSessionInfo.getChannelId().equals(orderMapping.getRegisteredFrom())) {
} //
// }
XUser xUser = xyqbUserService.findXUserById(orderMapping.getQgUserId()); XUser xUser = xyqbUserService.findXUserById(orderMapping.getQgUserId());
if (xUser == null) { if (xUser == null) {
......
package cn.quantgroup.cashloanflowboss.api.test.controller; package cn.quantgroup.cashloanflowboss.api.test.controller;
import cn.quantgroup.cashloanflowboss.api.user.model.UserSessionInfo; import cn.quantgroup.cashloanflowboss.api.user.model.UserSessionInfo;
import cn.quantgroup.cashloanflowboss.api.user.service.UserSessionService;
import cn.quantgroup.cashloanflowboss.core.base.Result; import cn.quantgroup.cashloanflowboss.core.base.Result;
import cn.quantgroup.cashloanflowboss.core.dictionary.ApplicationStatus; import cn.quantgroup.cashloanflowboss.core.dictionary.ApplicationStatus;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
...@@ -13,12 +12,12 @@ import org.springframework.web.bind.annotation.RestController; ...@@ -13,12 +12,12 @@ import org.springframework.web.bind.annotation.RestController;
@RequestMapping("/test") @RequestMapping("/test")
public class TestController { public class TestController {
@Autowired // @Autowired
private UserSessionService userSessionService; // private UserSessionService userSessionService;
//
@GetMapping("/user/info") // @GetMapping("/user/info")
public Result findUserFromSession() { // public Result findUserFromSession() {
UserSessionInfo userSessionInfo = userSessionService.findUserSessionInfo(); // UserSessionInfo userSessionInfo = userSessionService.findUserSessionInfo();
return new Result<>(ApplicationStatus.SUCCESS, userSessionInfo); // return new Result<>(ApplicationStatus.SUCCESS, userSessionInfo);
} // }
} }
package cn.quantgroup.cashloanflowboss.api.user.entity.boss;
import cn.quantgroup.cashloanflowboss.core.persistence.Primary;
import lombok.Data;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;
@Data
@Entity
@Table(name = "channel_user")
public class ChannelUser extends Primary {
@Column(name = "channel_id")
private Long channelId;
@Column(name = "user_id")
private Long userId;
}
...@@ -30,6 +30,12 @@ public class User extends Primary { ...@@ -30,6 +30,12 @@ public class User extends Primary {
@Column(name = "password") @Column(name = "password")
private String password; private String password;
/**
* 渠道ID
*/
@Column(name = "channel_id")
private Long channelId;
/** /**
* 用户级别 * 用户级别
*/ */
......
package cn.quantgroup.cashloanflowboss.api.user.repository.boss;
import cn.quantgroup.cashloanflowboss.api.user.entity.boss.ChannelUser;
import org.springframework.data.repository.PagingAndSortingRepository;
import org.springframework.stereotype.Repository;
/**
* Created by WeiWei on 2019/7/22.
*/
@Repository
public interface ChannelUserRepository extends PagingAndSortingRepository<ChannelUser, String> {
ChannelUser findByUserId(Long userId);
}
package cn.quantgroup.cashloanflowboss.api.user.service;
import cn.quantgroup.cashloanflowboss.api.user.entity.boss.ChannelUser;
import cn.quantgroup.cashloanflowboss.api.user.repository.boss.ChannelUserRepository;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Slf4j
@Service
public class ChannelUserService {
@Autowired
private ChannelUserRepository channelUserRepository;
public ChannelUser findChannelUserByUserId(Long userId) {
return channelUserRepository.findByUserId(userId);
}
}
package cn.quantgroup.cashloanflowboss.api.user.service;
import cn.quantgroup.cashloanflowboss.api.role.entity.boss.Permission;
import cn.quantgroup.cashloanflowboss.api.role.entity.boss.Role;
import cn.quantgroup.cashloanflowboss.api.role.service.RoleService;
import cn.quantgroup.cashloanflowboss.api.user.entity.boss.ChannelUser;
import cn.quantgroup.cashloanflowboss.api.user.entity.boss.User;
import cn.quantgroup.cashloanflowboss.api.user.model.RoleInfo;
import cn.quantgroup.cashloanflowboss.api.user.model.UserInfo;
import cn.quantgroup.cashloanflowboss.api.user.model.UserSessionInfo;
import cn.quantgroup.cashloanflowboss.component.security.Authority;
import cn.quantgroup.cashloanflowboss.core.asserts.Assert;
import cn.quantgroup.cashloanflowboss.core.dictionary.ApplicationDictionary;
import cn.quantgroup.cashloanflowboss.core.dictionary.ApplicationStatus;
import cn.quantgroup.cashloanflowboss.utils.JSONTools;
import com.fasterxml.jackson.core.type.TypeReference;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import javax.servlet.http.HttpSession;
import java.util.Arrays;
@Slf4j
@Service
public class UserSessionService {
@Autowired
private RoleService roleService;
@Autowired
private ChannelUserService channelUserService;
public void setUserSessionInfo(User user) {
//set user,role,channel or permission info
Role role = roleService.findRoleByUserId(user.getId());
String roleName = null, userName = user.getUsername();
Long roleId = null, channelId = null, userId = user.getId();
if (null != role) {
roleName = role.getName();
roleId = role.getId();
}
ChannelUser channelUser = channelUserService.findChannelUserByUserId(userId);
if (null != channelUser) {
channelId = channelUser.getChannelId();
}
UserSessionInfo userSessionInfo = UserSessionInfo.builder()
.roleInfo(RoleInfo.builder().roleId(roleId).roleName(roleName).build())
.userInfo(UserInfo.builder().userId(userId).userName(userName).build())
.channelId(channelId)
.build();
HttpSession session = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest().getSession();
session.setAttribute(ApplicationDictionary.USER_KEY, JSONTools.serialize(userSessionInfo));
Permission permission = new Permission();
permission.setId("Log.logout");
permission.setAuthorities(Arrays.asList(Authority.READ));
session.setAttribute(ApplicationDictionary.SECURITY_KEY, JSONTools.serialize(Arrays.asList(permission)));
}
public UserSessionInfo findUserSessionInfo() {
HttpSession session = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest().getSession();
Assert.isNull(session.getAttribute(ApplicationDictionary.USER_KEY), ApplicationStatus.INVALID_USER);
UserSessionInfo userSessionInfo = JSONTools.deserialize(String.valueOf(session.getAttribute(ApplicationDictionary.USER_KEY)), new TypeReference<UserSessionInfo>() {
});
return userSessionInfo;
}
}
...@@ -2,11 +2,9 @@ package cn.quantgroup.cashloanflowboss.core.aspect; ...@@ -2,11 +2,9 @@ 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.user.model.UserSessionInfo; import cn.quantgroup.cashloanflowboss.core.Application;
import cn.quantgroup.cashloanflowboss.api.user.service.UserSessionService;
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;
import cn.quantgroup.cashloanflowboss.core.base.BossPageImpl;
import cn.quantgroup.cashloanflowboss.core.base.Result; import cn.quantgroup.cashloanflowboss.core.base.Result;
import cn.quantgroup.cashloanflowboss.core.dictionary.ApplicationStatus; import cn.quantgroup.cashloanflowboss.core.dictionary.ApplicationStatus;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
...@@ -17,12 +15,10 @@ import org.aspectj.lang.annotation.Aspect; ...@@ -17,12 +15,10 @@ import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut; import org.aspectj.lang.annotation.Pointcut;
import org.aspectj.lang.reflect.CodeSignature; import org.aspectj.lang.reflect.CodeSignature;
import org.aspectj.lang.reflect.MethodSignature; import org.aspectj.lang.reflect.MethodSignature;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.Ordered; import org.springframework.core.Ordered;
import org.springframework.core.annotation.Order; import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.lang.reflect.Field;
import java.lang.reflect.Method; import java.lang.reflect.Method;
/** /**
...@@ -37,11 +33,9 @@ import java.lang.reflect.Method; ...@@ -37,11 +33,9 @@ import java.lang.reflect.Method;
@Order(Ordered.LOWEST_PRECEDENCE) @Order(Ordered.LOWEST_PRECEDENCE)
public class RoleLoadAspect { public class RoleLoadAspect {
@Autowired
private UserSessionService userSessionService;
@Pointcut("execution(* cn.quantgroup.cashloanflowboss.api.channel.controller.*.*(..))") @Pointcut("execution(* cn.quantgroup.cashloanflowboss.api.channel.controller.*.*(..))")
private void channelController() {} private void channelController() {}
@Pointcut("execution(* cn.quantgroup.cashloanflowboss.api.order.controller.*.*(..))") @Pointcut("execution(* cn.quantgroup.cashloanflowboss.api.order.controller.*.*(..))")
private void orderController() {} private void orderController() {}
...@@ -49,7 +43,6 @@ public class RoleLoadAspect { ...@@ -49,7 +43,6 @@ public class RoleLoadAspect {
private void doSomeRole() {} private void doSomeRole() {}
@Around(value = "doSomeRole()") @Around(value = "doSomeRole()")
public Object around(ProceedingJoinPoint pjp) { public Object around(ProceedingJoinPoint pjp) {
Object[] args = pjp.getArgs(); Object[] args = pjp.getArgs();
...@@ -67,23 +60,21 @@ public class RoleLoadAspect { ...@@ -67,23 +60,21 @@ public class RoleLoadAspect {
// 如果是渠道用户登陆 默认加载channelId // 如果是渠道用户登陆 默认加载channelId
ChannelIdInit annotation = method.getAnnotation(ChannelIdInit.class); ChannelIdInit annotation = method.getAnnotation(ChannelIdInit.class);
UserSessionInfo userSessionInfo = userSessionService.findUserSessionInfo(); if (annotation != null && ChannelConfUtil.channelRoleName.equals(Application.getPrincipal().getChannelId())) {
final Long channelIdInSession = userSessionInfo.getChannelId(); String[] paramNames = ((CodeSignature) pjp.getSignature()).getParameterNames();
if (annotation != null && ChannelConfUtil.channelRoleName.equals(userSessionInfo.getRoleInfo().getRoleName())) {
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] = channelIdInSession; args[i] = Application.getPrincipal().getChannelId();
} }
} }
} }
// 如果是渠道用户登陆,参数中channelId 不是登陆用户channelId,返回 拒绝请求 // 如果是渠道用户登陆,参数中channelId 不是登陆用户channelId,返回 拒绝请求
CheckChannelRole checkChannelRole = method.getAnnotation(CheckChannelRole.class); CheckChannelRole checkChannelRole = method.getAnnotation(CheckChannelRole.class);
if (checkChannelRole != null && ChannelConfUtil.channelRoleName.equals(userSessionInfo.getRoleInfo().getRoleName())) { if (checkChannelRole != null && Application.getPrincipal().isChannel()) {
Integer requestChannelId = -1; Long requestChannelId = -1L;
if (!checkChannelRole.isObjParam()) { if (!checkChannelRole.isObjParam()) {
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++) {
// 是简单类型,多个参数 直接参数channelId // 是简单类型,多个参数 直接参数channelId
if (ChannelConfUtil.channelIdParamName.equals(paramNames[i])) { if (ChannelConfUtil.channelIdParamName.equals(paramNames[i])) {
...@@ -93,8 +84,8 @@ public class RoleLoadAspect { ...@@ -93,8 +84,8 @@ public class RoleLoadAspect {
log.info("[CheckChannelRole]无channelId数据"); log.info("[CheckChannelRole]无channelId数据");
return Result.buildFial(ApplicationStatus.ARGUMENT_VALID_EXCEPTION); return Result.buildFial(ApplicationStatus.ARGUMENT_VALID_EXCEPTION);
} }
requestChannelId = Integer.valueOf(String.valueOf(requestChannelIdObj)); requestChannelId = Long.valueOf(String.valueOf(requestChannelIdObj));
if (requestChannelId != channelIdInSession.intValue()) { if (Application.getPrincipal().isSameChannel(requestChannelId)) {
log.info("[CheckChannelRole]渠道用户,登陆channelId与查询channelId不是同一个"); log.info("[CheckChannelRole]渠道用户,登陆channelId与查询channelId不是同一个");
return Result.buildFial(ApplicationStatus.INVALID_AUTHORITY); return Result.buildFial(ApplicationStatus.INVALID_AUTHORITY);
} }
...@@ -109,10 +100,10 @@ public class RoleLoadAspect { ...@@ -109,10 +100,10 @@ public class RoleLoadAspect {
log.info("[CheckChannelRole]无channelId数据"); log.info("[CheckChannelRole]无channelId数据");
return Result.buildFial(ApplicationStatus.ARGUMENT_VALID_EXCEPTION); return Result.buildFial(ApplicationStatus.ARGUMENT_VALID_EXCEPTION);
} }
requestChannelId = channelIdTemp.intValue(); requestChannelId = channelIdTemp;
} }
} }
if (requestChannelId != channelIdInSession.intValue()) { if (Application.getPrincipal().isSameChannel(requestChannelId)) {
log.info("[CheckChannelRole]渠道用户,登陆channelId与查询channelId不是同一个"); log.info("[CheckChannelRole]渠道用户,登陆channelId与查询channelId不是同一个");
return Result.buildFial(ApplicationStatus.INVALID_AUTHORITY); return Result.buildFial(ApplicationStatus.INVALID_AUTHORITY);
} }
......
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