| | |
| | | return ResponseEntity.ok(authInfo); |
| | | } |
| | | |
| | | @ApiOperation("临时授权") |
| | | @AnonymousPostMapping(value = "/token") |
| | | public ResponseEntity<Object> loginTest(@RequestParam String username, HttpServletRequest request) { |
| | | // 生成令牌与第三方系统获取令牌方式 |
| | | JwtUserDto jwtUser = userDetailsService.loadUserByUsername(username); |
| | | Authentication authentication = new UsernamePasswordAuthenticationToken(jwtUser, null, jwtUser.getAuthorities()); |
| | | SecurityContextHolder.getContext().setAuthentication(authentication); |
| | | // 生成令牌 |
| | | String token = tokenProvider.createToken(jwtUser); |
| | | // 返回 token 与 用户信息 |
| | | Map<String, Object> authInfo = new HashMap<String, Object>(2) {{ |
| | | put("token", properties.getTokenStartWith() + token); |
| | | put("user", jwtUser); |
| | | }}; |
| | | // 保存在线信息 |
| | | onlineUserService.save(jwtUser, token, request); |
| | | // 返回登录信息 |
| | | return ResponseEntity.ok(authInfo); |
| | | } |
| | | |
| | | @ApiOperation("获取用户信息") |
| | | @GetMapping(value = "/info") |
| | | public ResponseEntity<UserDetails> getUserInfo() { |