Commit 0ffcaad5 authored by WeiWei's avatar WeiWei

删除channel_user表及相关类

parent 56d0da8a
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.core.annotation.ChannelIdInit;
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.api.user.model.Pagination;
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.web.bind.annotation.*;
......@@ -17,6 +12,7 @@ import javax.validation.Valid;
/**
* Created with suntao on 2019/8/2
*
* @author suntao
*/
@RestController
......@@ -30,7 +26,8 @@ public class ChannelConfController {
/**
* 查询渠道列表
* @param channelId 在接受参数时,必须放到第一个参数位置
*
* @param channelId 在接受参数时,必须放到第一个参数位置
* @param pageNumber
* @param pageSize
* @return
......@@ -49,12 +46,11 @@ public class ChannelConfController {
}
@CheckChannelRole(isObjParam = true ,paramClazz = ChannelConfVo.class)
@CheckChannelRole(isObjParam = true, paramClazz = ChannelConfVo.class)
@PostMapping("/cfg/info")
public Result editChannelConfInfo(@RequestBody @Valid ChannelConfVo channelConfVo) {
return Result.buildSuccess(channelConfService.editChannelConfInfo(channelConfVo));
}
}
......@@ -26,7 +26,7 @@ public class Principal {
/**
* 所属渠道ID
*/
private String channelId;
private Long channelId;
/**
* 角色列表
......@@ -69,4 +69,14 @@ public class Principal {
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 {
// 设置用户主要信息
Principal principal = new Principal();
principal.setUserId(user.getId());
principal.setChannelId(user.getChannelId());
principal.setRank(user.getRank());
principal.setRoles(user.getRoles());
......
......@@ -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.util.OrderUtil;
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.repository.ClfOrderMappingRepository;
import cn.quantgroup.cashloanflowboss.spi.clotho.service.ClothoCenter;
......@@ -34,9 +33,6 @@ import java.util.*;
@Service
public class OrderService {
@Autowired
private UserSessionService userSessionService;
@Autowired
private ChannelConfRepository channelConfRepository;
@Autowired
......@@ -96,10 +92,11 @@ public class OrderService {
return false;
}
UserSessionInfo userSessionInfo = userSessionService.findUserSessionInfo();
if (!userSessionInfo.getChannelId().equals(orderMapping.getRegisteredFrom())) {
}
// 可以查看Application.getPrincipal()方法
// UserSessionInfo userSessionInfo = userSessionService.findUserSessionInfo();
// if (!userSessionInfo.getChannelId().equals(orderMapping.getRegisteredFrom())) {
//
// }
XUser xUser = xyqbUserService.findXUserById(orderMapping.getQgUserId());
if (xUser == null) {
......
package cn.quantgroup.cashloanflowboss.api.test.controller;
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.dictionary.ApplicationStatus;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -13,12 +12,12 @@ import org.springframework.web.bind.annotation.RestController;
@RequestMapping("/test")
public class TestController {
@Autowired
private UserSessionService userSessionService;
@GetMapping("/user/info")
public Result findUserFromSession() {
UserSessionInfo userSessionInfo = userSessionService.findUserSessionInfo();
return new Result<>(ApplicationStatus.SUCCESS, userSessionInfo);
}
// @Autowired
// private UserSessionService userSessionService;
//
// @GetMapping("/user/info")
// public Result findUserFromSession() {
// UserSessionInfo userSessionInfo = userSessionService.findUserSessionInfo();
// 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 {
@Column(name = "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;
import cn.quantgroup.cashloanflowboss.api.channel.model.ChannelConfVo;
import cn.quantgroup.cashloanflowboss.api.channel.util.ChannelConfUtil;
import cn.quantgroup.cashloanflowboss.api.user.model.UserSessionInfo;
import cn.quantgroup.cashloanflowboss.api.user.service.UserSessionService;
import cn.quantgroup.cashloanflowboss.core.Application;
import cn.quantgroup.cashloanflowboss.core.annotation.ChannelIdInit;
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.dictionary.ApplicationStatus;
import lombok.extern.slf4j.Slf4j;
......@@ -17,12 +15,10 @@ import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.aspectj.lang.reflect.CodeSignature;
import org.aspectj.lang.reflect.MethodSignature;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.Ordered;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
/**
......@@ -37,11 +33,9 @@ import java.lang.reflect.Method;
@Order(Ordered.LOWEST_PRECEDENCE)
public class RoleLoadAspect {
@Autowired
private UserSessionService userSessionService;
@Pointcut("execution(* cn.quantgroup.cashloanflowboss.api.channel.controller.*.*(..))")
private void channelController() {}
@Pointcut("execution(* cn.quantgroup.cashloanflowboss.api.order.controller.*.*(..))")
private void orderController() {}
......@@ -49,7 +43,6 @@ public class RoleLoadAspect {
private void doSomeRole() {}
@Around(value = "doSomeRole()")
public Object around(ProceedingJoinPoint pjp) {
Object[] args = pjp.getArgs();
......@@ -67,23 +60,21 @@ public class RoleLoadAspect {
// 如果是渠道用户登陆 默认加载channelId
ChannelIdInit annotation = method.getAnnotation(ChannelIdInit.class);
UserSessionInfo userSessionInfo = userSessionService.findUserSessionInfo();
final Long channelIdInSession = userSessionInfo.getChannelId();
if (annotation != null && ChannelConfUtil.channelRoleName.equals(userSessionInfo.getRoleInfo().getRoleName())) {
String[] paramNames = ((CodeSignature)pjp.getSignature()).getParameterNames();
if (annotation != null && ChannelConfUtil.channelRoleName.equals(Application.getPrincipal().getChannelId())) {
String[] paramNames = ((CodeSignature) pjp.getSignature()).getParameterNames();
for (int i = 0; i < paramNames.length; i++) {
if (ChannelConfUtil.channelIdParamName.equals(paramNames[i])) {
args[i] = channelIdInSession;
args[i] = Application.getPrincipal().getChannelId();
}
}
}
// 如果是渠道用户登陆,参数中channelId 不是登陆用户channelId,返回 拒绝请求
CheckChannelRole checkChannelRole = method.getAnnotation(CheckChannelRole.class);
if (checkChannelRole != null && ChannelConfUtil.channelRoleName.equals(userSessionInfo.getRoleInfo().getRoleName())) {
Integer requestChannelId = -1;
if (checkChannelRole != null && Application.getPrincipal().isChannel()) {
Long requestChannelId = -1L;
if (!checkChannelRole.isObjParam()) {
String[] paramNames = ((CodeSignature)pjp.getSignature()).getParameterNames();
String[] paramNames = ((CodeSignature) pjp.getSignature()).getParameterNames();
for (int i = 0; i < paramNames.length; i++) {
// 是简单类型,多个参数 直接参数channelId
if (ChannelConfUtil.channelIdParamName.equals(paramNames[i])) {
......@@ -93,8 +84,8 @@ public class RoleLoadAspect {
log.info("[CheckChannelRole]无channelId数据");
return Result.buildFial(ApplicationStatus.ARGUMENT_VALID_EXCEPTION);
}
requestChannelId = Integer.valueOf(String.valueOf(requestChannelIdObj));
if (requestChannelId != channelIdInSession.intValue()) {
requestChannelId = Long.valueOf(String.valueOf(requestChannelIdObj));
if (Application.getPrincipal().isSameChannel(requestChannelId)) {
log.info("[CheckChannelRole]渠道用户,登陆channelId与查询channelId不是同一个");
return Result.buildFial(ApplicationStatus.INVALID_AUTHORITY);
}
......@@ -109,10 +100,10 @@ public class RoleLoadAspect {
log.info("[CheckChannelRole]无channelId数据");
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不是同一个");
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