重构单点-1
This commit is contained in:
1 parent
0c3f96a1a1
commit
4251d4960b
8 files changed
+227
-17
No files matched your search
@@ -64,6 +64,12 @@
|
||||
<artifactId>pjcloud-app-server-api</artifactId>
|
||||
<version>5.7.0</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.bsd</groupId>
|
||||
<artifactId>pjcloud-thirdparty-api</artifactId>
|
||||
<version>5.7.0</version>
|
||||
</dependency>
|
||||
<!--必备: log 依赖-->
|
||||
<dependency>
|
||||
<groupId>com.bsd</groupId>
|
||||
|
||||
+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);
|
||||
}
|
||||
//
|
||||
// /**
|
||||
|
||||
+13
@@ -55,4 +55,17 @@ public interface ServiceNameConstants {
|
||||
*/
|
||||
String CODEGEN_SERVICE = "pjcloud-codegen";
|
||||
|
||||
|
||||
/**
|
||||
* 第三方服务
|
||||
*/
|
||||
String THIRDPARTY_SERVICE = "pjcloud-thirdparty-biz";
|
||||
|
||||
|
||||
/**
|
||||
* 智慧食堂服务
|
||||
*/
|
||||
String CANTEEN_SERVICE = "pjcloud-canteen-biz";
|
||||
|
||||
|
||||
}
|
||||
+47
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
*
|
||||
* Copyright (c) 2018-2025, pjcloud 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: pjcloud
|
||||
*
|
||||
*/
|
||||
|
||||
package com.bsd.pjcloud.thirdparty.api.feign;
|
||||
import com.bsd.pjcloud.common.core.constant.ServiceNameConstants;
|
||||
import com.bsd.pjcloud.common.core.util.R;
|
||||
import com.bsd.pjcloud.common.feign.annotation.NoToken;
|
||||
import org.springframework.cloud.openfeign.FeignClient;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author pjcloud
|
||||
* @date 2018/6/22
|
||||
*/
|
||||
@FeignClient(contextId = "remoterThirdPartyAuthService", value = ServiceNameConstants.THIRDPARTY_SERVICE)
|
||||
public interface RemoterThirdPartyAuthService {
|
||||
|
||||
/**
|
||||
* zzd单点
|
||||
* @param token
|
||||
* @return
|
||||
*/
|
||||
@NoToken
|
||||
@GetMapping("/thirdPartyOAth2/zzd/sso")
|
||||
R zzdsso(@RequestParam("token") String token);
|
||||
|
||||
|
||||
|
||||
}
|
||||
+39
@@ -0,0 +1,39 @@
|
||||
package com.bsd.pjcloud.thirdparty.controller;
|
||||
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.bsd.pjcloud.common.core.util.R;
|
||||
import com.bsd.pjcloud.thirdparty.entity.ThirdPartyDeptEntity;
|
||||
import com.bsd.pjcloud.thirdparty.service.ThirdPartyOAuth2Service;
|
||||
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.springdoc.core.annotations.ParameterObject;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@RestController
|
||||
@RequiredArgsConstructor
|
||||
@RequestMapping("/thirdPartyOAth2" )
|
||||
@Tag(description = "thirdPartyOAth2" , name = "第三方单点接口" )
|
||||
@SecurityRequirement(name = HttpHeaders.AUTHORIZATION)
|
||||
public class ThirdPartyOAth2Cotroller {
|
||||
|
||||
private final ThirdPartyOAuth2Service thirdPartyOAuth2Service;
|
||||
|
||||
|
||||
|
||||
@Operation(summary = "浙政钉token" )
|
||||
@GetMapping("/zzd/sso" )
|
||||
public R getThirdPartyDeptPage(@RequestParam("token")String token) {
|
||||
|
||||
return R.ok();
|
||||
}
|
||||
}
|
||||
+2
-2
@@ -1,5 +1,5 @@
|
||||
server:
|
||||
port: 6060
|
||||
port: 6061
|
||||
|
||||
spring:
|
||||
application:
|
||||
@@ -22,4 +22,4 @@ spring:
|
||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||
username: root
|
||||
password: root
|
||||
url: jdbc:mysql://pjcloud-mysql:3306/pjcloud_demo?characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=GMT%2B8&allowMultiQueries=true
|
||||
url: jdbc:mysql://pjcloud-mysql:3306/pjcloudx_thirdparty?characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=GMT%2B8&allowMultiQueries=true
|
||||
Vendored
+2
-2
@@ -1,9 +1,9 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
|
||||
<mapper namespace="com.pig4cloud.pigx.thirdparty.mapper.ThirdPartyDeptMapper">
|
||||
<mapper namespace="com.bsd.pjcloud.thirdparty.mapper.ThirdPartyDeptMapper">
|
||||
|
||||
<resultMap id="thirdPartyDeptMap" type="com.pig4cloud.pigx.thirdparty.entity.ThirdPartyDeptEntity">
|
||||
<resultMap id="thirdPartyDeptMap" type="com.bsd.pjcloud.thirdparty.entity.ThirdPartyDeptEntity">
|
||||
<id property="id" column="id"/>
|
||||
<result property="deptName" column="dept_name"/>
|
||||
<result property="deleted" column="deleted"/>
|
||||
|
||||
Vendored
+2
-2
@@ -1,9 +1,9 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
|
||||
<mapper namespace="com.pig4cloud.pigx.thirdparty.mapper.ThirdPartyUserMapper">
|
||||
<mapper namespace="com.bsd.pjcloud.thirdparty.mapper.ThirdPartyUserMapper">
|
||||
|
||||
<resultMap id="thirdPartyUserMap" type="com.pig4cloud.pigx.thirdparty.entity.ThirdPartyUserEntity">
|
||||
<resultMap id="thirdPartyUserMap" type="com.bsd.pjcloud.thirdparty.entity.ThirdPartyUserEntity">
|
||||
<id property="id" column="id"/>
|
||||
<result property="orgnizationId" column="orgnization_id"/>
|
||||
<result property="deleted" column="deleted"/>
|
||||
|
||||
Reference in new issue
Block a user