增加 OAuth2 客户端

This commit is contained in:
YunaiV 2022-05-11 00:43:03 +08:00
parent 5cf68961e1
commit f46d81dab5
18 changed files with 798 additions and 3 deletions

View File

@ -119,8 +119,11 @@ public interface ErrorCodeConstants {
ErrorCode SOCIAL_USER_UNBIND_NOT_SELF = new ErrorCode(1002018001, "社交解绑失败,非当前用户绑定");
ErrorCode SOCIAL_USER_NOT_FOUND = new ErrorCode(1002018002, "社交授权失败,找不到对应的用户");
// ========== 系统感词 1002019000 =========
// ========== 系统感词 1002019000 =========
ErrorCode SENSITIVE_WORD_NOT_EXISTS = new ErrorCode(1002019000, "系统敏感词在所有标签中都不存在");
ErrorCode SENSITIVE_WORD_EXISTS = new ErrorCode(1002019001, "系统敏感词已在标签中存在");
// ========== 系统敏感词 1002020000 =========
ErrorCode OAUTH2_CLIENT_NOT_EXISTS = new ErrorCode(1002020000, "OAuth2 客户端不存在");
}

View File

@ -0,0 +1,74 @@
package cn.iocoder.yudao.module.system.controller.admin.auth;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.system.controller.admin.auth.vo.client.OAuth2ClientCreateReqVO;
import cn.iocoder.yudao.module.system.controller.admin.auth.vo.client.OAuth2ClientPageReqVO;
import cn.iocoder.yudao.module.system.controller.admin.auth.vo.client.OAuth2ClientRespVO;
import cn.iocoder.yudao.module.system.controller.admin.auth.vo.client.OAuth2ClientUpdateReqVO;
import cn.iocoder.yudao.module.system.convert.auth.OAuth2ClientConvert;
import cn.iocoder.yudao.module.system.dal.dataobject.auth.OAuth2ClientDO;
import cn.iocoder.yudao.module.system.service.auth.OAuth2ClientService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import javax.validation.Valid;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
@Api(tags = "管理后台 - OAuth2 客户端")
@RestController
@RequestMapping("/system/oauth2-client")
@Validated
public class OAuth2ClientController {
@Resource
private OAuth2ClientService oAuth2ClientService;
@PostMapping("/create")
@ApiOperation("创建 OAuth2 客户端")
@PreAuthorize("@ss.hasPermission('system:oauth2-client:create')")
public CommonResult<Long> createOAuth2Client(@Valid @RequestBody OAuth2ClientCreateReqVO createReqVO) {
return success(oAuth2ClientService.createOAuth2Client(createReqVO));
}
@PutMapping("/update")
@ApiOperation("更新 OAuth2 客户端")
@PreAuthorize("@ss.hasPermission('system:oauth2-client:update')")
public CommonResult<Boolean> updateOAuth2Client(@Valid @RequestBody OAuth2ClientUpdateReqVO updateReqVO) {
oAuth2ClientService.updateOAuth2Client(updateReqVO);
return success(true);
}
@DeleteMapping("/delete")
@ApiOperation("删除 OAuth2 客户端")
@ApiImplicitParam(name = "id", value = "编号", required = true, dataTypeClass = Long.class)
@PreAuthorize("@ss.hasPermission('system:oauth2-client:delete')")
public CommonResult<Boolean> deleteOAuth2Client(@RequestParam("id") Long id) {
oAuth2ClientService.deleteOAuth2Client(id);
return success(true);
}
@GetMapping("/get")
@ApiOperation("获得 OAuth2 客户端")
@ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = Long.class)
@PreAuthorize("@ss.hasPermission('system:oauth2-client:query')")
public CommonResult<OAuth2ClientRespVO> getOAuth2Client(@RequestParam("id") Long id) {
OAuth2ClientDO oAuth2Client = oAuth2ClientService.getOAuth2Client(id);
return success(OAuth2ClientConvert.INSTANCE.convert(oAuth2Client));
}
@GetMapping("/page")
@ApiOperation("获得OAuth2 客户端分页")
@PreAuthorize("@ss.hasPermission('system:oauth2-client:query')")
public CommonResult<PageResult<OAuth2ClientRespVO>> getOAuth2ClientPage(@Valid OAuth2ClientPageReqVO pageVO) {
PageResult<OAuth2ClientDO> pageResult = oAuth2ClientService.getOAuth2ClientPage(pageVO);
return success(OAuth2ClientConvert.INSTANCE.convertPage(pageResult));
}
}

View File

@ -0,0 +1,51 @@
package cn.iocoder.yudao.module.system.controller.admin.auth.vo.client;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import javax.validation.constraints.NotNull;
import java.util.List;
/**
* OAuth2 客户端 Base VO提供给添加修改详细的子 VO 使用
* 如果子 VO 存在差异的字段请不要添加到这里影响 Swagger 文档生成
*/
@Data
public class OAuth2ClientBaseVO {
@ApiModelProperty(value = "客户端编号", required = true)
@NotNull(message = "客户端编号不能为空")
private Long id;
@ApiModelProperty(value = "客户端密钥", required = true)
@NotNull(message = "客户端密钥不能为空")
private String secret;
@ApiModelProperty(value = "应用名", required = true)
@NotNull(message = "应用名不能为空")
private String name;
@ApiModelProperty(value = "应用图标", required = true)
@NotNull(message = "应用图标不能为空")
private String logo;
@ApiModelProperty(value = "应用描述")
private String description;
@ApiModelProperty(value = "状态", required = true)
@NotNull(message = "状态不能为空")
private Integer status;
@ApiModelProperty(value = "访问令牌的有效期", required = true)
@NotNull(message = "访问令牌的有效期不能为空")
private Integer accessTokenValiditySeconds;
@ApiModelProperty(value = "刷新令牌的有效期", required = true)
@NotNull(message = "刷新令牌的有效期不能为空")
private Integer refreshTokenValiditySeconds;
@ApiModelProperty(value = "可重定向的 URI 地址", required = true)
@NotNull(message = "可重定向的 URI 地址不能为空")
private List<String> redirectUris;
}

View File

@ -0,0 +1,12 @@
package cn.iocoder.yudao.module.system.controller.admin.auth.vo.client;
import lombok.*;
import io.swagger.annotations.*;
@ApiModel("管理后台 - OAuth2 客户端创建 Request VO")
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public class OAuth2ClientCreateReqVO extends OAuth2ClientBaseVO {
}

View File

@ -0,0 +1,19 @@
package cn.iocoder.yudao.module.system.controller.admin.auth.vo.client;
import lombok.*;
import io.swagger.annotations.*;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
@ApiModel("管理后台 - OAuth2 客户端分页 Request VO")
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public class OAuth2ClientPageReqVO extends PageParam {
@ApiModelProperty(value = "应用名")
private String name;
@ApiModelProperty(value = "状态")
private Integer status;
}

View File

@ -0,0 +1,20 @@
package cn.iocoder.yudao.module.system.controller.admin.auth.vo.client;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;
import java.util.Date;
@ApiModel("管理后台 - OAuth2 客户端 Response VO")
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public class OAuth2ClientRespVO extends OAuth2ClientBaseVO {
@ApiModelProperty(value = "创建时间", required = true)
private Date createTime;
}

View File

@ -0,0 +1,14 @@
package cn.iocoder.yudao.module.system.controller.admin.auth.vo.client;
import io.swagger.annotations.ApiModel;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;
@ApiModel("管理后台 - OAuth2 客户端更新 Request VO")
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public class OAuth2ClientUpdateReqVO extends OAuth2ClientBaseVO {
}

View File

@ -0,0 +1,33 @@
package cn.iocoder.yudao.module.system.convert.auth;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.system.controller.admin.auth.vo.client.OAuth2ClientCreateReqVO;
import cn.iocoder.yudao.module.system.controller.admin.auth.vo.client.OAuth2ClientRespVO;
import cn.iocoder.yudao.module.system.controller.admin.auth.vo.client.OAuth2ClientUpdateReqVO;
import cn.iocoder.yudao.module.system.dal.dataobject.auth.OAuth2ClientDO;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;
import java.util.List;
/**
* OAuth2 客户端 Convert
*
* @author 芋道源码
*/
@Mapper
public interface OAuth2ClientConvert {
OAuth2ClientConvert INSTANCE = Mappers.getMapper(OAuth2ClientConvert.class);
OAuth2ClientDO convert(OAuth2ClientCreateReqVO bean);
OAuth2ClientDO convert(OAuth2ClientUpdateReqVO bean);
OAuth2ClientRespVO convert(OAuth2ClientDO bean);
List<OAuth2ClientRespVO> convertList(List<OAuth2ClientDO> list);
PageResult<OAuth2ClientRespVO> convertPage(PageResult<OAuth2ClientDO> page);
}

View File

@ -2,8 +2,11 @@ package cn.iocoder.yudao.module.system.dal.dataobject.auth;
import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
@ -18,7 +21,7 @@ import java.util.List;
*
* @author 芋道源码
*/
@TableName("system_oauth2_application")
@TableName(value = "system_oauth2_client", autoResultMap = true)
@Data
@EqualsAndHashCode(callSuper = true)
@Accessors(chain = true)
@ -29,7 +32,7 @@ public class OAuth2ClientDO extends BaseDO {
*
* 由于 SQL Server 在存储 String 主键有点问题所以暂时使用 Long 类型
*/
@TableId
@TableId(type = IdType.INPUT)
private Long id;
/**
* 客户端密钥
@ -64,6 +67,7 @@ public class OAuth2ClientDO extends BaseDO {
/**
* 可重定向的 URI 地址
*/
@TableField(typeHandler = JacksonTypeHandler.class)
private List<String> redirectUris;
}

View File

@ -0,0 +1,25 @@
package cn.iocoder.yudao.module.system.dal.mysql.auth;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.module.system.controller.admin.auth.vo.client.OAuth2ClientPageReqVO;
import cn.iocoder.yudao.module.system.dal.dataobject.auth.OAuth2ClientDO;
import org.apache.ibatis.annotations.Mapper;
/**
* OAuth2 客户端 Mapper
*
* @author 芋道源码
*/
@Mapper
public interface OAuth2ClientMapper extends BaseMapperX<OAuth2ClientDO> {
default PageResult<OAuth2ClientDO> selectPage(OAuth2ClientPageReqVO reqVO) {
return selectPage(reqVO, new LambdaQueryWrapperX<OAuth2ClientDO>()
.likeIfPresent(OAuth2ClientDO::getName, reqVO.getName())
.eqIfPresent(OAuth2ClientDO::getStatus, reqVO.getStatus())
.orderByDesc(OAuth2ClientDO::getId));
}
}

View File

@ -1,7 +1,13 @@
package cn.iocoder.yudao.module.system.service.auth;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.system.controller.admin.auth.vo.client.OAuth2ClientCreateReqVO;
import cn.iocoder.yudao.module.system.controller.admin.auth.vo.client.OAuth2ClientPageReqVO;
import cn.iocoder.yudao.module.system.controller.admin.auth.vo.client.OAuth2ClientUpdateReqVO;
import cn.iocoder.yudao.module.system.dal.dataobject.auth.OAuth2ClientDO;
import javax.validation.Valid;
/**
* OAuth2.0 Client Service 接口
*
@ -11,6 +17,44 @@ import cn.iocoder.yudao.module.system.dal.dataobject.auth.OAuth2ClientDO;
*/
public interface OAuth2ClientService {
/**
* 创建OAuth2 客户端
*
* @param createReqVO 创建信息
* @return 编号
*/
Long createOAuth2Client(@Valid OAuth2ClientCreateReqVO createReqVO);
/**
* 更新OAuth2 客户端
*
* @param updateReqVO 更新信息
*/
void updateOAuth2Client(@Valid OAuth2ClientUpdateReqVO updateReqVO);
/**
* 删除OAuth2 客户端
*
* @param id 编号
*/
void deleteOAuth2Client(Long id);
/**
* 获得OAuth2 客户端
*
* @param id 编号
* @return OAuth2 客户端
*/
OAuth2ClientDO getOAuth2Client(Long id);
/**
* 获得OAuth2 客户端分页
*
* @param pageReqVO 分页查询
* @return OAuth2 客户端分页
*/
PageResult<OAuth2ClientDO> getOAuth2ClientPage(OAuth2ClientPageReqVO pageReqVO);
/**
* 从缓存中校验客户端是否合法
*

View File

@ -1,8 +1,19 @@
package cn.iocoder.yudao.module.system.service.auth;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.system.controller.admin.auth.vo.client.OAuth2ClientCreateReqVO;
import cn.iocoder.yudao.module.system.controller.admin.auth.vo.client.OAuth2ClientPageReqVO;
import cn.iocoder.yudao.module.system.controller.admin.auth.vo.client.OAuth2ClientUpdateReqVO;
import cn.iocoder.yudao.module.system.convert.auth.OAuth2ClientConvert;
import cn.iocoder.yudao.module.system.dal.dataobject.auth.OAuth2ClientDO;
import cn.iocoder.yudao.module.system.dal.mysql.auth.OAuth2ClientMapper;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.OAUTH2_CLIENT_NOT_EXISTS;
/**
* OAuth2.0 Client Service 实现类
*
@ -11,6 +22,51 @@ import org.springframework.stereotype.Service;
@Service
public class OAuth2ClientServiceImpl implements OAuth2ClientService {
@Resource
private OAuth2ClientMapper oauth2ClientMapper;
@Override
public Long createOAuth2Client(OAuth2ClientCreateReqVO createReqVO) {
// 插入
OAuth2ClientDO oAuth2Client = OAuth2ClientConvert.INSTANCE.convert(createReqVO);
oauth2ClientMapper.insert(oAuth2Client);
// 返回
return oAuth2Client.getId();
}
@Override
public void updateOAuth2Client(OAuth2ClientUpdateReqVO updateReqVO) {
// 校验存在
this.validateOAuth2ClientExists(updateReqVO.getId());
// 更新
OAuth2ClientDO updateObj = OAuth2ClientConvert.INSTANCE.convert(updateReqVO);
oauth2ClientMapper.updateById(updateObj);
}
@Override
public void deleteOAuth2Client(Long id) {
// 校验存在
this.validateOAuth2ClientExists(id);
// 删除
oauth2ClientMapper.deleteById(id);
}
private void validateOAuth2ClientExists(Long id) {
if (oauth2ClientMapper.selectById(id) == null) {
throw exception(OAUTH2_CLIENT_NOT_EXISTS);
}
}
@Override
public OAuth2ClientDO getOAuth2Client(Long id) {
return oauth2ClientMapper.selectById(id);
}
@Override
public PageResult<OAuth2ClientDO> getOAuth2ClientPage(OAuth2ClientPageReqVO pageReqVO) {
return oauth2ClientMapper.selectPage(pageReqVO);
}
@Override
public OAuth2ClientDO validOAuthClientFromCache(Long id) {
return new OAuth2ClientDO().setId(id)

View File

@ -0,0 +1,128 @@
package cn.iocoder.yudao.module.system.service.auth;
import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest;
import cn.iocoder.yudao.module.system.controller.admin.auth.vo.client.OAuth2ClientCreateReqVO;
import cn.iocoder.yudao.module.system.controller.admin.auth.vo.client.OAuth2ClientPageReqVO;
import cn.iocoder.yudao.module.system.controller.admin.auth.vo.client.OAuth2ClientUpdateReqVO;
import cn.iocoder.yudao.module.system.dal.dataobject.auth.OAuth2ClientDO;
import cn.iocoder.yudao.module.system.dal.mysql.auth.OAuth2ClientMapper;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.springframework.context.annotation.Import;
import javax.annotation.Resource;
import static cn.iocoder.yudao.framework.common.util.object.ObjectUtils.cloneIgnoreId;
import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertPojoEquals;
import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertServiceException;
import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomLongId;
import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomPojo;
import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.OAUTH2_CLIENT_NOT_EXISTS;
import static org.junit.jupiter.api.Assertions.*;
/**
* {@link OAuth2ClientServiceImpl} 的单元测试类
*
* @author 芋道源码
*/
@Import(OAuth2ClientServiceImpl.class)
public class OAuth2ClientServiceImplTest extends BaseDbUnitTest {
@Resource
private OAuth2ClientServiceImpl oAuth2ClientService;
@Resource
private OAuth2ClientMapper oAuth2ClientMapper;
@Test
public void testCreateOAuth2Client_success() {
// 准备参数
OAuth2ClientCreateReqVO reqVO = randomPojo(OAuth2ClientCreateReqVO.class);
// 调用
Long oauth2ClientId = oAuth2ClientService.createOAuth2Client(reqVO);
// 断言
assertNotNull(oauth2ClientId);
// 校验记录的属性是否正确
OAuth2ClientDO oAuth2Client = oAuth2ClientMapper.selectById(oauth2ClientId);
assertPojoEquals(reqVO, oAuth2Client);
}
@Test
public void testUpdateOAuth2Client_success() {
// mock 数据
OAuth2ClientDO dbOAuth2Client = randomPojo(OAuth2ClientDO.class);
oAuth2ClientMapper.insert(dbOAuth2Client);// @Sql: 先插入出一条存在的数据
// 准备参数
OAuth2ClientUpdateReqVO reqVO = randomPojo(OAuth2ClientUpdateReqVO.class, o -> {
o.setId(dbOAuth2Client.getId()); // 设置更新的 ID
});
// 调用
oAuth2ClientService.updateOAuth2Client(reqVO);
// 校验是否更新正确
OAuth2ClientDO oAuth2Client = oAuth2ClientMapper.selectById(reqVO.getId()); // 获取最新的
assertPojoEquals(reqVO, oAuth2Client);
}
@Test
public void testUpdateOAuth2Client_notExists() {
// 准备参数
OAuth2ClientUpdateReqVO reqVO = randomPojo(OAuth2ClientUpdateReqVO.class);
// 调用, 并断言异常
assertServiceException(() -> oAuth2ClientService.updateOAuth2Client(reqVO), OAUTH2_CLIENT_NOT_EXISTS);
}
@Test
public void testDeleteOAuth2Client_success() {
// mock 数据
OAuth2ClientDO dbOAuth2Client = randomPojo(OAuth2ClientDO.class);
oAuth2ClientMapper.insert(dbOAuth2Client);// @Sql: 先插入出一条存在的数据
// 准备参数
Long id = dbOAuth2Client.getId();
// 调用
oAuth2ClientService.deleteOAuth2Client(id);
// 校验数据不存在了
assertNull(oAuth2ClientMapper.selectById(id));
}
@Test
public void testDeleteOAuth2Client_notExists() {
// 准备参数
Long id = randomLongId();
// 调用, 并断言异常
assertServiceException(() -> oAuth2ClientService.deleteOAuth2Client(id), OAUTH2_CLIENT_NOT_EXISTS);
}
@Test
@Disabled
public void testGetOAuth2ClientPage() {
// mock 数据
OAuth2ClientDO dbOAuth2Client = randomPojo(OAuth2ClientDO.class, o -> { // 等会查询到
o.setName("潜龙");
o.setStatus(CommonStatusEnum.ENABLE.getStatus());
});
oAuth2ClientMapper.insert(dbOAuth2Client);
// 测试 name 不匹配
oAuth2ClientMapper.insert(cloneIgnoreId(dbOAuth2Client, o -> o.setName("凤凰")));
// 测试 status 不匹配
oAuth2ClientMapper.insert(cloneIgnoreId(dbOAuth2Client, o -> o.setStatus(CommonStatusEnum.ENABLE.getStatus())));
// 准备参数
OAuth2ClientPageReqVO reqVO = new OAuth2ClientPageReqVO();
reqVO.setName("long");
reqVO.setStatus(CommonStatusEnum.ENABLE.getStatus());
// 调用
PageResult<OAuth2ClientDO> pageResult = oAuth2ClientService.getOAuth2ClientPage(reqVO);
// 断言
assertEquals(1, pageResult.getTotal());
assertEquals(1, pageResult.getList().size());
assertPojoEquals(dbOAuth2Client, pageResult.getList().get(0));
}
}

View File

@ -20,3 +20,4 @@ DELETE FROM "system_social_user_bind";
DELETE FROM "system_tenant";
DELETE FROM "system_tenant_package";
DELETE FROM "system_sensitive_word";
DELETE FROM "system_oauth2_client";

View File

@ -470,3 +470,21 @@ CREATE TABLE IF NOT EXISTS "system_sensitive_word" (
"deleted" bit NOT NULL DEFAULT FALSE,
PRIMARY KEY ("id")
) COMMENT '系统敏感词';
CREATE TABLE IF NOT EXISTS "system_oauth2_client" (
"id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY,
"secret" varchar NOT NULL,
"name" varchar NOT NULL,
"logo" varchar NOT NULL,
"description" varchar,
"status" int NOT NULL,
"access_token_validity_seconds" int NOT NULL,
"refresh_token_validity_seconds" int NOT NULL,
"redirect_uris" varchar NOT NULL,
"creator" varchar DEFAULT '',
"create_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updater" varchar DEFAULT '',
"update_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
"deleted" bit NOT NULL DEFAULT FALSE,
PRIMARY KEY ("id")
) COMMENT 'OAuth2 客户端表';

View File

@ -114,6 +114,7 @@ yudao:
- system_sms_template
- system_sms_log
- system_sensitive_word
- system_oauth2_client
- infra_codegen_column
- infra_codegen_table
- infra_test_demo

View File

@ -0,0 +1,44 @@
import request from '@/utils/request'
// 创建 OAuth2 客户端
export function createOAuth2Client(data) {
return request({
url: '/system/oauth2-client/create',
method: 'post',
data: data
})
}
// 更新 OAuth2 客户端
export function updateOAuth2Client(data) {
return request({
url: '/system/oauth2-client/update',
method: 'put',
data: data
})
}
// 删除 OAuth2 客户端
export function deleteOAuth2Client(id) {
return request({
url: '/system/oauth2-client/delete?id=' + id,
method: 'delete'
})
}
// 获得 OAuth2 客户端
export function getOAuth2Client(id) {
return request({
url: '/system/oauth2-client/get?id=' + id,
method: 'get'
})
}
// 获得 OAuth2 客户端分页
export function getOAuth2ClientPage(query) {
return request({
url: '/system/oauth2-client/page',
method: 'get',
params: query
})
}

View File

@ -0,0 +1,248 @@
<template>
<div class="app-container">
<!-- 搜索工作栏 -->
<el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
<el-form-item label="应用名" prop="name">
<el-input v-model="queryParams.name" placeholder="请输入应用名" clearable @keyup.enter.native="handleQuery"/>
</el-form-item>
<el-form-item label="状态" prop="status">
<el-select v-model="queryParams.status" placeholder="请选择状态" clearable size="small">
<el-option v-for="dict in this.getDictDatas(DICT_TYPE.COMMON_STATUS)"
:key="dict.value" :label="dict.label" :value="dict.value"/>
</el-select>
</el-form-item>
<el-form-item>
<el-button type="primary" icon="el-icon-search" @click="handleQuery">搜索</el-button>
<el-button icon="el-icon-refresh" @click="resetQuery">重置</el-button>
</el-form-item>
</el-form>
<!-- 操作工具栏 -->
<el-row :gutter="10" class="mb8">
<el-col :span="1.5">
<el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd"
v-hasPermi="['system:oauth2-client:create']">新增</el-button>
</el-col>
<right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
</el-row>
<!-- 列表 -->
<el-table v-loading="loading" :data="list">
<el-table-column label="客户端编号" align="center" prop="id" />
<el-table-column label="客户端密钥" align="center" prop="secret" />
<el-table-column label="应用名" align="center" prop="name" />
<el-table-column label="应用图标" align="center" prop="logo" />
<el-table-column label="应用描述" align="center" prop="description" />
<el-table-column label="状态" align="center" prop="status">
<template slot-scope="scope">
<dict-tag :type="DICT_TYPE.COMMON_STATUS" :value="scope.row.status" />
</template>
</el-table-column>
<el-table-column label="访问令牌的有效期" align="center" prop="accessTokenValiditySeconds" />
<el-table-column label="刷新令牌的有效期" align="center" prop="refreshTokenValiditySeconds" />
<el-table-column label="可重定向的 URI 地址" align="center" prop="redirectUris" />
<el-table-column label="创建时间" align="center" prop="createTime" width="180">
<template slot-scope="scope">
<span>{{ parseTime(scope.row.createTime) }}</span>
</template>
</el-table-column>
<el-table-column label="操作" align="center" class-name="small-padding fixed-width">
<template slot-scope="scope">
<el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)"
v-hasPermi="['system:oauth2-client:update']">修改</el-button>
<el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)"
v-hasPermi="['system:oauth2-client:delete']">删除</el-button>
</template>
</el-table-column>
</el-table>
<!-- 分页组件 -->
<pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNo" :limit.sync="queryParams.pageSize"
@pagination="getList"/>
<!-- 对话框(添加 / 修改) -->
<el-dialog :title="title" :visible.sync="open" width="700px" append-to-body>
<el-form ref="form" :model="form" :rules="rules" label-width="160px">
<el-form-item label="客户端密钥" prop="secret">
<el-input v-model="form.secret" placeholder="请输入客户端密钥" />
</el-form-item>
<el-form-item label="应用名" prop="name">
<el-input v-model="form.name" placeholder="请输入应用名" />
</el-form-item>
<el-form-item label="应用图标">
<imageUpload v-model="form.logo" :limit="1"/>
</el-form-item>
<el-form-item label="应用描述">
<el-input type="textarea" v-model="form.description" placeholder="请输入应用名" />
</el-form-item>
<el-form-item label="状态" prop="status">
<el-radio-group v-model="form.status">
<el-radio v-for="dict in this.getDictDatas(DICT_TYPE.COMMON_STATUS)"
:key="dict.value" :label="parseInt(dict.value)">{{dict.label}}</el-radio>
</el-radio-group>
</el-form-item>
<el-form-item label="访问令牌的有效期" prop="accessTokenValiditySeconds">
<el-input-number v-model="form.accessTokenValiditySeconds" placeholder="单位:秒" />
</el-form-item>
<el-form-item label="刷新令牌的有效期" prop="refreshTokenValiditySeconds">
<el-input-number v-model="form.refreshTokenValiditySeconds" placeholder="单位:秒" />
</el-form-item>
<el-form-item label="可重定向的 URI 地址" prop="redirectUris">
<el-input v-model="form.redirectUris" placeholder="请输入可重定向的 URI 地址" />
</el-form-item>
</el-form>
<div slot="footer" class="dialog-footer">
<el-button type="primary" @click="submitForm"> </el-button>
<el-button @click="cancel"> </el-button>
</div>
</el-dialog>
</div>
</template>
<script>
import { createOAuth2Client, updateOAuth2Client, deleteOAuth2Client, getOAuth2Client, getOAuth2ClientPage } from "@/api/system/oauth2/oauth2Client";
import ImageUpload from '@/components/ImageUpload';
import Editor from '@/components/Editor';
import {CommonStatusEnum} from "@/utils/constants";
export default {
name: "OAuth2Client",
components: {
ImageUpload,
Editor,
},
data() {
return {
//
loading: true,
//
exportLoading: false,
//
showSearch: true,
//
total: 0,
// OAuth2
list: [],
//
title: "",
//
open: false,
//
queryParams: {
pageNo: 1,
pageSize: 10,
name: null,
status: null,
},
//
form: {},
//
rules: {
secret: [{ required: true, message: "客户端密钥不能为空", trigger: "blur" }],
name: [{ required: true, message: "应用名不能为空", trigger: "blur" }],
logo: [{ required: true, message: "应用图标不能为空", trigger: "blur" }],
status: [{ required: true, message: "状态不能为空", trigger: "blur" }],
accessTokenValiditySeconds: [{ required: true, message: "访问令牌的有效期不能为空", trigger: "blur" }],
refreshTokenValiditySeconds: [{ required: true, message: "刷新令牌的有效期不能为空", trigger: "blur" }],
redirectUris: [{ required: true, message: "可重定向的 URI 地址不能为空", trigger: "blur" }],
}
};
},
created() {
this.getList();
},
methods: {
/** 查询列表 */
getList() {
this.loading = true;
//
let params = {...this.queryParams};
//
getOAuth2ClientPage(params).then(response => {
this.list = response.data.list;
this.total = response.data.total;
this.loading = false;
});
},
/** 取消按钮 */
cancel() {
this.open = false;
this.reset();
},
/** 表单重置 */
reset() {
this.form = {
id: undefined,
secret: undefined,
name: undefined,
logo: undefined,
description: undefined,
status: CommonStatusEnum.ENABLE,
accessTokenValiditySeconds: undefined,
refreshTokenValiditySeconds: undefined,
redirectUris: undefined,
};
this.resetForm("form");
},
/** 搜索按钮操作 */
handleQuery() {
this.queryParams.pageNo = 1;
this.getList();
},
/** 重置按钮操作 */
resetQuery() {
this.resetForm("queryForm");
this.handleQuery();
},
/** 新增按钮操作 */
handleAdd() {
this.reset();
this.open = true;
this.title = "添加 OAuth2 客户端";
},
/** 修改按钮操作 */
handleUpdate(row) {
this.reset();
const id = row.id;
getOAuth2Client(id).then(response => {
this.form = response.data;
this.open = true;
this.title = "修改 OAuth2 客户端";
});
},
/** 提交按钮 */
submitForm() {
this.$refs["form"].validate(valid => {
if (!valid) {
return;
}
//
if (this.form.id != null) {
updateOAuth2Client(this.form).then(response => {
this.$modal.msgSuccess("修改成功");
this.open = false;
this.getList();
});
return;
}
//
createOAuth2Client(this.form).then(response => {
this.$modal.msgSuccess("新增成功");
this.open = false;
this.getList();
});
});
},
/** 删除按钮操作 */
handleDelete(row) {
const id = row.id;
this.$modal.confirm('是否确认删除 OAuth2 客户端编号为"' + id + '"的数据项?').then(function() {
return deleteOAuth2Client(id);
}).then(() => {
this.getList();
this.$modal.msgSuccess("删除成功");
}).catch(() => {});
}
}
};
</script>