Browse Source

Merge branch 'release' of gitadmin/tuoheng_oidc into master

tags/v2.3.0
gitadmin 1 year ago
parent
commit
887eb766ca
12 changed files with 212 additions and 17 deletions
  1. +35
    -0
      tuoheng_oidc_admin/src/main/java/com/tuoheng/controller/TenantController.java
  2. +16
    -0
      tuoheng_oidc_admin/src/main/java/com/tuoheng/mapper/TenantMapper.java
  3. +28
    -0
      tuoheng_oidc_admin/src/main/java/com/tuoheng/model/param/CreateClientTenantDto.java
  4. +11
    -0
      tuoheng_oidc_admin/src/main/java/com/tuoheng/model/param/CreateClientUserDto.java
  5. +23
    -0
      tuoheng_oidc_admin/src/main/java/com/tuoheng/model/po/TenantPo.java
  6. +4
    -0
      tuoheng_oidc_admin/src/main/java/com/tuoheng/model/po/UserPo.java
  7. +3
    -0
      tuoheng_oidc_admin/src/main/java/com/tuoheng/service/ClientUserSevice.java
  8. +71
    -5
      tuoheng_oidc_admin/src/main/java/com/tuoheng/service/impl/ClientUserServiceImpl.java
  9. +5
    -5
      tuoheng_oidc_admin/src/main/resources/application-test.yml
  10. +2
    -2
      tuoheng_oidc_admin/src/main/resources/mapper/ClientUserMapper.xml
  11. +9
    -0
      tuoheng_oidc_admin/src/main/resources/mapper/TenantMapper.xml
  12. +5
    -5
      tuoheng_oidc_server/src/main/resources/application-test.yml

+ 35
- 0
tuoheng_oidc_admin/src/main/java/com/tuoheng/controller/TenantController.java View File

@@ -0,0 +1,35 @@
package com.tuoheng.controller;

import com.tuoheng.model.dto.LoginUser;
import com.tuoheng.model.param.CreateClientTenantDto;
import com.tuoheng.model.param.CreateClientUserDto;
import com.tuoheng.service.ClientUserSevice;
import com.tuoheng.service.CurrentUser;
import com.tuoheng.until.JsonResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
* @author chenjiandong
* @description: TODO
* @date 2022/12/7 16:17
*/
@RestController
@RequestMapping("/tenant")
@Slf4j
public class TenantController {

@Autowired
private ClientUserSevice clientUserSevice;

@PostMapping("/create")
public JsonResult createClientTenant(@RequestBody CreateClientTenantDto createClientTenantDto,
@CurrentUser LoginUser loginUser){
return clientUserSevice.createClientTenant(createClientTenantDto, loginUser);
}

}

+ 16
- 0
tuoheng_oidc_admin/src/main/java/com/tuoheng/mapper/TenantMapper.java View File

@@ -0,0 +1,16 @@
package com.tuoheng.mapper;

import com.tuoheng.model.po.TenantPo;
import org.apache.ibatis.annotations.Mapper;

/**
* @author chenjiandong
* @description: TODO
* @date 2022/12/9 9:30
*/
@Mapper
public interface TenantMapper {

int insertTenant(TenantPo tenantPo);

}

+ 28
- 0
tuoheng_oidc_admin/src/main/java/com/tuoheng/model/param/CreateClientTenantDto.java View File

@@ -0,0 +1,28 @@
package com.tuoheng.model.param;

import lombok.Data;

import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.util.List;

/**
* @author chenjiandong
* @description: TODO
* @date 2022/12/8 10:16
*/
@Data
public class CreateClientTenantDto {

@NotEmpty(message = "username can not be empty!")
private String username;

@NotEmpty(message = "password can not be empty!")
private String password;

private String remark;

@NotNull(message = "clientRoleDtoList can not be null!")
private List<ClientRoleDto> clientRoleDtoList;

}

+ 11
- 0
tuoheng_oidc_admin/src/main/java/com/tuoheng/model/param/CreateClientUserDto.java View File

@@ -20,6 +20,17 @@ public class CreateClientUserDto {
@NotEmpty(message = "password can not be empty!")
private String password;

/**
* 如果不是租户,传值:用户所属租户名称
*/
private String tenantName;

/**
* 是否为租户标识
* 0:不是;1:是
*/
private Integer tenantFlag;

@NotNull(message = "clientRoleDtoList can not be null!")
private List<ClientRoleDto> clientRoleDtoList;


+ 23
- 0
tuoheng_oidc_admin/src/main/java/com/tuoheng/model/po/TenantPo.java View File

@@ -0,0 +1,23 @@
package com.tuoheng.model.po;

import lombok.Data;
import lombok.experimental.Accessors;

/**
* @author chenjiandong
* @description: TODO
* @date 2022/12/9 9:10
*/
@Data
@Accessors(chain = true)
public class TenantPo extends BasePo {

private Long id;

private Long userId;

private String remark;

private Integer enabled;

}

+ 4
- 0
tuoheng_oidc_admin/src/main/java/com/tuoheng/model/po/UserPo.java View File

@@ -20,4 +20,8 @@ public class UserPo extends BasePo {

private Integer enabled;

private Long tenantId;

private Integer isTenant;

}

+ 3
- 0
tuoheng_oidc_admin/src/main/java/com/tuoheng/service/ClientUserSevice.java View File

@@ -1,6 +1,7 @@
package com.tuoheng.service;

import com.tuoheng.model.dto.LoginUser;
import com.tuoheng.model.param.CreateClientTenantDto;
import com.tuoheng.model.param.CreateClientUserDto;
import com.tuoheng.model.param.UpdateUserClientRoleDto;
import com.tuoheng.model.param.UpdateUserPassDto;
@@ -17,6 +18,8 @@ public interface ClientUserSevice {

JsonResult createClientUser(CreateClientUserDto createClientUserDto, LoginUser loginUser);

JsonResult createClientTenant(CreateClientTenantDto createClientTenantDto, LoginUser loginUser);

JsonResult updateUserPassword(UpdateUserPassDto updateUserPassDto, LoginUser loginUser);

JsonResult updateUserClientRole(UpdateUserClientRoleDto updateUserClientRoleDto, LoginUser loginUser);

+ 71
- 5
tuoheng_oidc_admin/src/main/java/com/tuoheng/service/impl/ClientUserServiceImpl.java View File

@@ -3,13 +3,12 @@ package com.tuoheng.service.impl;
import com.tuoheng.mapper.AuthoritiesMapper;
import com.tuoheng.mapper.ClientUserMapper;
import com.tuoheng.mapper.ClientUserRoleMapper;
import com.tuoheng.mapper.TenantMapper;
import com.tuoheng.model.dto.LoginUser;
import com.tuoheng.model.param.ClientRoleDto;
import com.tuoheng.model.param.CreateClientUserDto;
import com.tuoheng.model.param.UpdateUserClientRoleDto;
import com.tuoheng.model.param.UpdateUserPassDto;
import com.tuoheng.model.param.*;
import com.tuoheng.model.po.AuthoritiesPo;
import com.tuoheng.model.po.ClientUserRolePo;
import com.tuoheng.model.po.TenantPo;
import com.tuoheng.model.po.UserPo;
import com.tuoheng.service.ClientUserSevice;
import com.tuoheng.until.JsonResult;
@@ -32,12 +31,16 @@ public class ClientUserServiceImpl implements ClientUserSevice {
@Autowired
private ClientUserMapper clientUserMapper;

@Autowired
private TenantMapper tenantMapper;

@Autowired
private AuthoritiesMapper authoritiesMapper;

@Autowired
private ClientUserRoleMapper clientUserRoleMapper;

@Override
@Transactional(readOnly = true)
public JsonResult judgeCreate(String username){
if(clientUserMapper.judgeCreateByUserName(username) > 0){
@@ -46,6 +49,7 @@ public class ClientUserServiceImpl implements ClientUserSevice {
return JsonResult.success(true);
}

@Override
@Transactional(rollbackFor = Exception.class)
public JsonResult createClientUser(CreateClientUserDto createClientUserDto, LoginUser loginUser){

@@ -57,8 +61,27 @@ public class ClientUserServiceImpl implements ClientUserSevice {
.setUsername(createClientUserDto.getUsername())
.setPassword("{bcrypt}" + new BCryptPasswordEncoder().encode(createClientUserDto.getPassword()));
userPo.setCreateUser(loginUser.getUserId());
//租户逻辑新增 start
if(createClientUserDto.getTenantFlag() != null){
if(createClientUserDto.getTenantFlag() == 1){
userPo.setIsTenant(1);
}else {
userPo.setIsTenant(0);
UserPo po = clientUserMapper.getUserByUserName(createClientUserDto.getTenantName());
if(po != null){
userPo.setTenantId(po.getId());
}
}
}
//租户逻辑新增 end
clientUserMapper.insertClientUser(userPo);

if(createClientUserDto.getTenantFlag() != null){
if(createClientUserDto.getTenantFlag() == 1){
TenantPo tenantPo = new TenantPo()
.setUserId(userPo.getId());
tenantMapper.insertTenant(tenantPo);
}
}
List<AuthoritiesPo> authoritiesPos = new ArrayList<>();
List<ClientUserRolePo> clientUserRolePoArrayList = new ArrayList<>();
for(ClientRoleDto clientRoleDto : createClientUserDto.getClientRoleDtoList()){
@@ -82,6 +105,48 @@ public class ClientUserServiceImpl implements ClientUserSevice {
return JsonResult.success(userPo.getId());
}


@Override
@Transactional(rollbackFor = Exception.class)
public JsonResult createClientTenant(CreateClientTenantDto createClientTenantDto, LoginUser loginUser){

if(clientUserMapper.judgeCreateByUserName(createClientTenantDto.getUsername()) > 0){
return JsonResult.error("该用户名称已存在!");
}
UserPo userPo = new UserPo()
.setIsTenant(1)
.setUsername(createClientTenantDto.getUsername())
.setPassword("{bcrypt}" + new BCryptPasswordEncoder().encode(createClientTenantDto.getPassword()));
userPo.setCreateUser(loginUser.getUserId());
clientUserMapper.insertClientUser(userPo);
TenantPo tenantPo = new TenantPo()
.setUserId(userPo.getId())
.setRemark(createClientTenantDto.getRemark());
tenantMapper.insertTenant(tenantPo);
List<AuthoritiesPo> authoritiesPos = new ArrayList<>();
List<ClientUserRolePo> clientUserRolePoArrayList = new ArrayList<>();
for(ClientRoleDto clientRoleDto : createClientTenantDto.getClientRoleDtoList()){
AuthoritiesPo authoritiesPo = new AuthoritiesPo()
.setUserId(userPo.getId())
.setUsername(createClientTenantDto.getUsername())
.setAuthority(clientRoleDto.getClientId());
authoritiesPo.setCreateUser(loginUser.getUserId());
authoritiesPos.add(authoritiesPo);

ClientUserRolePo clientUserRolePo = new ClientUserRolePo()
.setUserId(userPo.getId())
.setClientId(clientRoleDto.getClientId())
.setRoleId(clientRoleDto.getRoleId());
clientUserRolePo.setCreateUser(loginUser.getUserId());
clientUserRolePoArrayList.add(clientUserRolePo);

}
authoritiesMapper.batchInsert(authoritiesPos);
clientUserRoleMapper.batchInsert(clientUserRolePoArrayList);
return JsonResult.success(userPo.getId());
}

@Override
@Transactional(rollbackFor = Exception.class)
public JsonResult updateUserPassword(UpdateUserPassDto updateUserPassDto, LoginUser loginUser){

@@ -97,6 +162,7 @@ public class ClientUserServiceImpl implements ClientUserSevice {
return JsonResult.success(true);
}

@Override
@Transactional(rollbackFor = Exception.class)
public JsonResult updateUserClientRole(UpdateUserClientRoleDto updateUserClientRoleDto, LoginUser loginUser){
UserPo userPo = clientUserMapper.getUserByUserName(updateUserClientRoleDto.getUsername());

+ 5
- 5
tuoheng_oidc_admin/src/main/resources/application-test.yml View File

@@ -2,11 +2,11 @@ spring:
# 注册中心consul地址
cloud:
consul:
host: 192.168.11.242 # consul 所在服务地址
host: 172.15.1.11 # consul 所在服务地址
port: 8500 # consul 服务端口
discovery:
## consul ip地址
hostname: 192.168.11.242
hostname: 172.15.1.11
# 注册到consul的服务名称
service-name: ${spring.application.name} # 服务提供者名称
instance-id: ${spring.application.name}:${spring.cloud.client.ip-address}:${server.port} #实例ID
@@ -21,9 +21,9 @@ spring:
type: com.alibaba.druid.pool.DruidDataSource
driver-class-name: com.mysql.cj.jdbc.Driver
# 填写你数据库的url、登录名、密码和数据库名
url: jdbc:mysql://192.168.11.242:3306/tuoheng_oidc?useUnicode=true&characterEncoding=UTF-8&serverTimezone=GMT%2b8&useSSL=true&tinyInt1isBit=false
url: jdbc:mysql://rm-uf6z740323e8053pj.mysql.rds.aliyuncs.com:3306/tuoheng_oidc?useUnicode=true&characterEncoding=UTF-8&serverTimezone=GMT%2b8&useSSL=true&tinyInt1isBit=false
username: root
password: idontcare
password: TH22#2022
druid:
# 连接池的配置信息
# 初始连接数
@@ -50,7 +50,7 @@ spring:
# 缓存库默认索引0
database: 0
# Redis服务器地址
host: 192.168.11.242
host: r-uf6cdzjifj20jszykr.redis.rds.aliyuncs.com
# Redis服务器连接端口
port: 6379
# Redis服务器连接密码(默认为空)

+ 2
- 2
tuoheng_oidc_admin/src/main/resources/mapper/ClientUserMapper.xml View File

@@ -3,8 +3,8 @@
<mapper namespace="com.tuoheng.mapper.ClientUserMapper">

<insert id="insertClientUser" parameterType="com.tuoheng.model.po.UserPo" keyProperty="id" useGeneratedKeys="true">
insert into users (username, password, create_user)
values (#{username}, #{password}, #{createUser})
insert into users (username, password, create_user, tenant_id, is_tenant)
values (#{username}, #{password}, #{createUser}, #{tenantId}, #{isTenant})
</insert>

<select id="judgeCreateByUserName" parameterType="java.lang.String" resultType="int">

+ 9
- 0
tuoheng_oidc_admin/src/main/resources/mapper/TenantMapper.xml View File

@@ -0,0 +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.tuoheng.mapper.TenantMapper">

<insert id="insertTenant" parameterType="com.tuoheng.model.po.TenantPo" keyProperty="id" useGeneratedKeys="true">
insert into t_tenant (user_id, remark) values (#{userId}, #{remark})
</insert>

</mapper>

+ 5
- 5
tuoheng_oidc_server/src/main/resources/application-test.yml View File

@@ -4,7 +4,7 @@ spring:
resource-server:
jwt:
#issuer-uri: http://192.168.11.241:8090 #认证中心端点,作为资源端的配置、
issuer-uri: https://oidc.test.t-aaron.com #认证中心端点,作为资源端的配置、
issuer-uri: https://login-test.t-aaron.com #认证中心端点,作为资源端的配置、

# 配置数据源
datasource:
@@ -12,9 +12,9 @@ spring:
type: com.alibaba.druid.pool.DruidDataSource
driver-class-name: com.mysql.cj.jdbc.Driver
# 填写你数据库的url、登录名、密码和数据库名
url: jdbc:mysql://192.168.11.242:3306/tuoheng_oidc?useUnicode=true&characterEncoding=UTF-8&serverTimezone=GMT%2b8&useSSL=true&tinyInt1isBit=false
url: jdbc:mysql://rm-uf6z740323e8053pj.mysql.rds.aliyuncs.com:3306/tuoheng_oidc?useUnicode=true&characterEncoding=UTF-8&serverTimezone=GMT%2b8&useSSL=true&tinyInt1isBit=false
username: root
password: idontcare
password: TH22#2022
druid:
# 连接池的配置信息
# 初始连接数
@@ -41,7 +41,7 @@ spring:
# 缓存库默认索引0
database: 0
# Redis服务器地址
host: 192.168.11.242
host: r-uf6cdzjifj20jszykr.redis.rds.aliyuncs.com
# Redis服务器连接端口
port: 6379
# Redis服务器连接密码(默认为空)
@@ -58,4 +58,4 @@ spring:
min-idle: 1 # 连接池中的最小空闲连接
oauth2:
token:
issuer: https://oidc.test.t-aaron.com
issuer: https://login-test.t-aaron.com

Loading…
Cancel
Save