重构单点-1
This commit is contained in:
1 parent
0c3f96a1a1
commit
4251d4960b
8 files changed
+227
-17
No files matched your search
+116
-11
@@ -20,18 +20,23 @@ 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.admin.api.feign.RemoteUserService;
|
||||
import com.bsd.pjcloud.app.service.AppUserService;
|
||||
import com.bsd.pjcloud.common.core.util.R;
|
||||
import com.bsd.pjcloud.common.security.annotation.Inner;
|
||||
import com.bsd.pjcloud.thirdparty.api.feign.RemoterThirdPartyAuthService;
|
||||
import com.bsd.pjcloud.thirdparty.dto.ZZDUserDTO;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
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 org.springframework.security.oauth2.core.OAuth2AccessToken;
|
||||
import org.springframework.security.oauth2.core.OAuth2RefreshToken;
|
||||
import org.springframework.security.oauth2.server.authorization.authentication.OAuth2AccessTokenAuthenticationToken;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@@ -53,26 +58,126 @@ public class AppUserAutoLoginController {
|
||||
|
||||
private final RemoteTokenService remoteTokenService;
|
||||
|
||||
private final RemoteUserService remoteUserService;
|
||||
|
||||
private final RemoterThirdPartyAuthService remoterThirdPartyAuthService;
|
||||
|
||||
/*
|
||||
*
|
||||
* @param token 浙政钉前端获取的token
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/zzdsso/{token}")
|
||||
@Operation(summary = "浙政钉单点登录")
|
||||
public R zzdsso(@PathVariable(name = "token") String token) {
|
||||
|
||||
//获取数字政务token通过浙政钉前端获取的token,调试阶段先写死
|
||||
// String json = "{" +
|
||||
// "\"username\": \"李宗相\"," +
|
||||
// "\"organizationId\": 2," +
|
||||
// "\"userId\": 1340," +
|
||||
// "\"nickName\": \"李宗相\"," +
|
||||
// "\"mobile\": \"18576496089\"," +
|
||||
// "\"regionCode\": null," +
|
||||
// "\"ext\": {" +
|
||||
// "\"employeeCode\": \"GE_ae12bdf21598498eb48bf2cf2c45a3e1\"," +
|
||||
// "\"organizationCode\": \"GO_63e77077d5e041789bbbe1d0d20bcf41\"," +
|
||||
// "\"nickNameCn\": \"李宗相\"," +
|
||||
// "\"openid\": \"1b51f0e11fc73b8adddcbaf7982daab6\"," +
|
||||
// "\"realmId\": \"196729\"," +
|
||||
// "\"mobile\": null" +
|
||||
// "}" +
|
||||
// "}";
|
||||
|
||||
|
||||
// ObjectMapper objectMapper = new ObjectMapper();
|
||||
// ZZDUserDTO zzdUserDTO;
|
||||
// try {
|
||||
// zzdUserDTO = objectMapper.readValue(json, ZZDUserDTO.class);
|
||||
// } catch (JsonProcessingException e) {
|
||||
// throw new RuntimeException(e);
|
||||
// }
|
||||
//暂时先注释,模拟一下就行
|
||||
R zzdsso = remoterThirdPartyAuthService.zzdsso(token);
|
||||
ZZDUserDTO zzdUserDTO = (ZZDUserDTO) zzdsso.getData();
|
||||
ZZDUserDTO.Ext ext = zzdUserDTO.getExt();
|
||||
String employeeCode = ext.getEmployeeCode();
|
||||
String mobile = zzdUserDTO.getMobile();
|
||||
System.out.println(employeeCode);
|
||||
System.out.println(mobile);
|
||||
//两种方式,手机号+员工钉钉号,查到相同就视为同一个人,然后登录
|
||||
//先系统表里面查看是否有,在第三方数据库表里面看下是否有
|
||||
AdminUserRespDTO adminUserRespDTO =adminUserApi.getUserByMobileOrEmployeeCode(employeeCode,mobile);
|
||||
if(adminUserRespDTO!=null){
|
||||
//登录成功
|
||||
return createTokenAfterLoginSuccess(adminUserRespDTO.getId(), zzdUserDTO.getUsername(), LoginLogTypeEnum.LOGIN_SSO);
|
||||
}
|
||||
log.info("用户不存在,尝试创建用户");
|
||||
CreateUserDto createUserDto = new CreateUserDto();
|
||||
createUserDto.setUsername(zzdUserDTO.getUsername());
|
||||
createUserDto.setMobile(mobile);
|
||||
createUserDto.setNickname(zzdUserDTO.getNickName());
|
||||
createUserDto.setDingtalkEmployeeCode(employeeCode);
|
||||
//todo 换成枚举
|
||||
//浙里办用户
|
||||
createUserDto.setUserType("1");
|
||||
AdminUserRespDTO adminUserRespDTONew=adminUserApi.createSysUser(createUserDto);
|
||||
log.info("创建用户成功,用户id为:{}",adminUserRespDTONew.getId());
|
||||
return createTokenAfterLoginSuccess(adminUserRespDTONew.getId(), mobile, LoginLogTypeEnum.LOGIN_SSO);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 诗画sdk获取参数
|
||||
*
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("/shjnsso")
|
||||
@Operation(summary = "诗画江南单点登录")
|
||||
public R shjnsso(@RequestBody @Valid SHJNSSOReqVO shjnsso) {
|
||||
ZZDUserDTO zzdUserDTO=ssoApi.shjnsso(shjnsso.getAccountId(),shjnsso.getSessionId());
|
||||
ZZDUserDTO.Ext ext = zzdUserDTO.getExt();
|
||||
String mobile = zzdUserDTO.getMobile();
|
||||
AdminUserRespDTO userByMobileOrEmployeeCode = adminUserApi.getUserByMobileOrEmployeeCode(null, mobile);
|
||||
if(userByMobileOrEmployeeCode!=null){
|
||||
return createTokenAfterLoginSuccess(userByMobileOrEmployeeCode.getId(), mobile, LoginLogTypeEnum.LOGIN_SSO);
|
||||
}
|
||||
log.info("用户不存在,尝试创建用户");
|
||||
CreateUserDto createUserDto = new CreateUserDto();
|
||||
createUserDto.setUsername(zzdUserDTO.getUsername());
|
||||
createUserDto.setMobile(mobile);
|
||||
createUserDto.setNickname(zzdUserDTO.getNickName());
|
||||
createUserDto.setAvatar(ext.getHeadImgUrl());
|
||||
//todo 换成枚举
|
||||
//诗画用户
|
||||
createUserDto.setUserType("2");
|
||||
AdminUserRespDTO adminUserRespDTONew=adminUserApi.createSysUser(createUserDto);
|
||||
log.info("创建用户成功,用户id为:{}",adminUserRespDTONew.getId());
|
||||
return createTokenAfterLoginSuccess(adminUserRespDTONew.getId(), mobile, LoginLogTypeEnum.LOGIN_SSO);
|
||||
}
|
||||
|
||||
|
||||
@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);
|
||||
Object refreshToken = authenticationTokenR.getData().get("refreshToken");
|
||||
Map<String, Object> stringObjectHashMap = new HashMap<>();
|
||||
stringObjectHashMap.put("accessToken", accessToken);
|
||||
stringObjectHashMap.put("refreshToken", refreshToken);
|
||||
return R.ok(stringObjectHashMap);
|
||||
}
|
||||
//
|
||||
// /**
|
||||
|
||||
Reference in new issue
Block a user