| | |
| | | package com.zy.asrs.wms.common.security; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.zy.asrs.common.domain.enums.LoginSystemType; |
| | | import com.zy.asrs.framework.common.Cools; |
| | | import com.zy.asrs.wms.common.config.ConfigProperties; |
| | | import com.zy.asrs.wms.common.constant.Constants; |
| | | import com.zy.asrs.wms.system.entity.Menu; |
| | | import com.zy.asrs.wms.system.entity.Role; |
| | | import com.zy.asrs.wms.system.entity.User; |
| | | import com.zy.asrs.wms.system.entity.UserLogin; |
| | | import com.zy.asrs.wms.system.service.UserLoginService; |
| | | import com.zy.asrs.wms.system.service.UserRoleService; |
| | | import com.zy.asrs.wms.system.service.UserService; |
| | | import com.zy.asrs.wms.utils.HttpUtils; |
| | | import com.zy.asrs.wms.utils.JwtUtil; |
| | |
| | | private UserService userService; |
| | | @Resource |
| | | private UserLoginService userLoginService; |
| | | @Resource |
| | | private UserRoleService userRoleService; |
| | | |
| | | @Override |
| | | protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain chain) throws ServletException, IOException { |
| | |
| | | if (user == null) { |
| | | throw new UsernameNotFoundException("Username not found"); |
| | | } |
| | | boolean root = false; |
| | | List<Role> roles = userRoleService.listByUserId(user.getId()); |
| | | for (Role role : roles) { |
| | | if (role.getId() == 1) { |
| | | root = true; |
| | | break; |
| | | } |
| | | } |
| | | UserLogin userLogin = null; |
| | | if (root) { |
| | | userLogin = userLoginService.superFindByUserId(user.getId(), String.valueOf(LoginSystemType.WMS)); |
| | | } |
| | | |
| | | List<Menu> authorities = user.getAuthorities().stream() |
| | | .filter(m -> !Cools.isEmpty(m.getAuthority())).collect(Collectors.toList()); |
| | | UsernamePasswordAuthenticationToken authentication = new UsernamePasswordAuthenticationToken( |
| | | user, null, authorities); |
| | | userLogin == null ? user : userLogin, null, authorities); |
| | | SecurityContextHolder.getContext().setAuthentication(authentication); |
| | | // token将要过期签发新token, 防止突然退出登录 |
| | | long expiration = (claims.getExpiration().getTime() - new Date().getTime()) / 1000 / 60; |