添加手动生成token

This commit is contained in:
zjf committed 2024-12-06 17:39:41 +08:00
1 parent aff77150d6
commit 0c3f96a1a1
5 files changed
+324 -1

No files matched your search

@@ -0,0 +1,208 @@
/*
* Copyright (c) 2018-2025, lengleng All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the pig4cloud.com developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: lengleng (wangiegie@gmail.com)
*/
package com.bsd.pjcloud.app.controller;
import com.bsd.pjcloud.admin.api.dto.UserTokenDTO;
import com.bsd.pjcloud.admin.api.feign.RemoteTokenService;
import com.bsd.pjcloud.app.service.AppUserService;
import com.bsd.pjcloud.common.core.util.R;
import com.bsd.pjcloud.common.security.annotation.Inner;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpHeaders;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
import java.util.Map;
/**
* app用户表
*
* @author aeizzz
* @date 2022-12-07 09:52:03
*/
@RestController
@RequiredArgsConstructor
@RequestMapping("/appLogin")
@Tag(description = "appLogin", name = "浙政钉诗画单点登录")
@SecurityRequirement(name = HttpHeaders.AUTHORIZATION)
public class AppUserAutoLoginController {
private final AppUserService appUserService;
private final RemoteTokenService remoteTokenService;
@Inner(value = false)
@GetMapping("/getAuthToken/{token}")
public R info(@PathVariable(name = "token") String token) {
// 拼接请求参数
UserTokenDTO userTokenDTO = new UserTokenDTO();
userTokenDTO.setUsername("admin"); // 只需要用户名,就可以生成 token
userTokenDTO.setAuthorities(List.of("sys_user_add")); // 权限列表的字符串,能调用的接口范围
// feign 调用 auth 模块生成 token
// R<OAuth2AccessTokenAuthenticationToken> authenticationTokenR = remoteTokenService.generateToken(userTokenDTO);
R<Map> authenticationTokenR = remoteTokenService.generateToken(userTokenDTO);
// token 信息
// OAuth2AccessTokenAuthenticationToken data = authenticationTokenR.getData();
// OAuth2AccessToken accessToken = data.getAccessToken();
// // 刷新 token 信息
// OAuth2RefreshToken refreshToken = data.getRefreshToken();
// // 客户端信息
// RegisteredClient registeredClient = data.getRegisteredClient();
Object accessToken = authenticationTokenR.getData().get("accessToken");
return R.ok(accessToken);
}
//
// /**
// * 获取当前用户全部信息
// * @return 用户信息
// */
// @GetMapping(value = { "/info" })
// public R info() {
// String username = SecurityUtils.getUser().getUsername();
// AppUser user = appUserService.getOne(Wrappers.<AppUser>query().lambda().eq(AppUser::getUsername, username));
// if (user == null) {
// return R.failed(MsgUtils.getMessage(ErrorCodes.SYS_USER_QUERY_ERROR));
// }
// return R.ok(appUserService.findUserInfo(user));
// }
//
// /**
// * 分页查询
// * @param page 分页对象
// * @param appUserDTO app用户表
// * @return
// */
// @Operation(summary = "分页查询", description = "分页查询")
// @GetMapping("/page")
// public R getAppUserPage(Page page, AppUserDTO appUserDTO) {
// return R.ok(appUserService.getUsersWithRolePage(page, appUserDTO));
// }
//
// /**
// * 通过id查询app用户表
// * @param userId id
// * @return R
// */
// @Operation(summary = "通过id查询", description = "通过id查询")
// @GetMapping("/details/{userId}")
// public R getById(@PathVariable("userId") Long userId) {
// return R.ok(appUserService.selectUserVoById(userId));
// }
//
// /**
// * @return R
// */
// @Operation(summary = "通过userName查询", description = "通过userName查询")
// @GetMapping("/details")
// public R getByUserName(AppUser user) {
// AppUser one = appUserService.getOne(Wrappers.query(user), false);
// return R.ok(one == null ? null : CommonConstants.SUCCESS);
// }
//
// /**
// * 新增app用户表
// * @param appUser app用户表
// * @return R
// */
// @Operation(summary = "新增app用户表", description = "新增app用户表")
// @SysLog("新增app用户表")
// @PostMapping
// @HasPermission("app_appuser_add")
// public R save(@RequestBody AppUserDTO appUser) {
// appUserService.saveUser(appUser);
// return R.ok();
// }
//
// /**
// * 修改app用户表
// * @param appUser app用户表
// * @return R
// */
// @Operation(summary = "修改app用户表", description = "修改app用户表")
// @SysLog("修改app用户表")
// @PutMapping
// @HasPermission("app_appuser_edit")
// public R updateById(@RequestBody AppUserDTO appUser) {
// return R.ok(appUserService.updateUser(appUser));
// }
//
// /**
// * 通过id删除app用户表
// * @param ids userIds
// * @return R
// */
// @Operation(summary = "通过ids删除app用户表", description = "通过ids删除app用户表")
// @SysLog("通过id删除app用户表")
// @DeleteMapping
// @HasPermission("app_appuser_del")
// public R removeById(@RequestBody Long[] ids) {
// return R.ok(appUserService.deleteAppUserByIds(ids));
// }
//
// /**
// * 导出excel 表格
// * @param appUser 查询条件
// * @return excel 文件流
// */
// @ResponseExcel
// @GetMapping("/export")
// @HasPermission("app_appuser_export")
// public List<AppUserExcelVO> export(AppUserDTO appUser) {
// return appUserService.listUser(appUser);
// }
//
// @SysLog("修改个人信息")
// @PutMapping("/edit")
// public R updateUserInfo(@Valid @RequestBody AppUserDTO userDto) {
// if (UserTypeEnum.TOC.getStatus().equals(SecurityUtils.getUser().getUserType())) {
// userDto.setUserId(SecurityUtils.getUser().getId());
// // TOC 以手机号为key
// userDto.setUsername(SecurityUtils.getUser().getUsername());
// }
// return appUserService.updateUserInfo(userDto);
// }
//
// /**
// * 导入用户
// * @param excelVOList 用户列表
// * @param bindingResult 错误信息列表
// * @return R
// */
// @PostMapping("/import")
// @HasPermission("app_appuser_export")
// public R importUser(@RequestExcel List<AppUserExcelVO> excelVOList, BindingResult bindingResult) {
// return appUserService.importUser(excelVOList, bindingResult);
// }
//
// @Operation(summary = "注册app用户表", description = "注册app用户表")
// @SysLog("注册app用户表")
// @Inner(value = false)
// @PostMapping("/register")
// public R register(@RequestBody AppUserDTO appUser) {
// return appUserService.registerAppUser(appUser);
// }
}