Commit 73d53dbaad60c25e5002206a658c51cd5e268606
1 parent
9aed06af
🔧 简化 oauth2 模块的 VO
Showing
15 changed files
with
101 additions
and
174 deletions
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/api/oauth2/OAuth2TokenApiImpl.java
| 1 | 1 | package cn.iocoder.yudao.module.system.api.oauth2; |
| 2 | 2 | |
| 3 | +import cn.iocoder.yudao.framework.common.util.object.BeanUtils; | |
| 3 | 4 | import cn.iocoder.yudao.module.system.api.oauth2.dto.OAuth2AccessTokenCheckRespDTO; |
| 4 | 5 | import cn.iocoder.yudao.module.system.api.oauth2.dto.OAuth2AccessTokenCreateReqDTO; |
| 5 | 6 | import cn.iocoder.yudao.module.system.api.oauth2.dto.OAuth2AccessTokenRespDTO; |
| 6 | -import cn.iocoder.yudao.module.system.convert.auth.OAuth2TokenConvert; | |
| 7 | 7 | import cn.iocoder.yudao.module.system.dal.dataobject.oauth2.OAuth2AccessTokenDO; |
| 8 | 8 | import cn.iocoder.yudao.module.system.service.oauth2.OAuth2TokenService; |
| 9 | 9 | import org.springframework.stereotype.Service; |
| ... | ... | @@ -25,24 +25,25 @@ public class OAuth2TokenApiImpl implements OAuth2TokenApi { |
| 25 | 25 | public OAuth2AccessTokenRespDTO createAccessToken(OAuth2AccessTokenCreateReqDTO reqDTO) { |
| 26 | 26 | OAuth2AccessTokenDO accessTokenDO = oauth2TokenService.createAccessToken( |
| 27 | 27 | reqDTO.getUserId(), reqDTO.getUserType(), reqDTO.getClientId(), reqDTO.getScopes()); |
| 28 | - return OAuth2TokenConvert.INSTANCE.convert2(accessTokenDO); | |
| 28 | + return BeanUtils.toBean(accessTokenDO, OAuth2AccessTokenRespDTO.class); | |
| 29 | 29 | } |
| 30 | 30 | |
| 31 | 31 | @Override |
| 32 | 32 | public OAuth2AccessTokenCheckRespDTO checkAccessToken(String accessToken) { |
| 33 | - return OAuth2TokenConvert.INSTANCE.convert(oauth2TokenService.checkAccessToken(accessToken)); | |
| 33 | + OAuth2AccessTokenDO accessTokenDO = oauth2TokenService.checkAccessToken(accessToken); | |
| 34 | + return BeanUtils.toBean(accessTokenDO, OAuth2AccessTokenCheckRespDTO.class); | |
| 34 | 35 | } |
| 35 | 36 | |
| 36 | 37 | @Override |
| 37 | 38 | public OAuth2AccessTokenRespDTO removeAccessToken(String accessToken) { |
| 38 | 39 | OAuth2AccessTokenDO accessTokenDO = oauth2TokenService.removeAccessToken(accessToken); |
| 39 | - return OAuth2TokenConvert.INSTANCE.convert2(accessTokenDO); | |
| 40 | + return BeanUtils.toBean(accessTokenDO, OAuth2AccessTokenRespDTO.class); | |
| 40 | 41 | } |
| 41 | 42 | |
| 42 | 43 | @Override |
| 43 | 44 | public OAuth2AccessTokenRespDTO refreshAccessToken(String refreshToken, String clientId) { |
| 44 | 45 | OAuth2AccessTokenDO accessTokenDO = oauth2TokenService.refreshAccessToken(refreshToken, clientId); |
| 45 | - return OAuth2TokenConvert.INSTANCE.convert2(accessTokenDO); | |
| 46 | + return BeanUtils.toBean(accessTokenDO, OAuth2AccessTokenRespDTO.class); | |
| 46 | 47 | } |
| 47 | 48 | |
| 48 | 49 | } | ... | ... |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/oauth2/OAuth2ClientController.java
| ... | ... | @@ -2,16 +2,15 @@ package cn.iocoder.yudao.module.system.controller.admin.oauth2; |
| 2 | 2 | |
| 3 | 3 | import cn.iocoder.yudao.framework.common.pojo.CommonResult; |
| 4 | 4 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 5 | -import cn.iocoder.yudao.module.system.controller.admin.oauth2.vo.client.OAuth2ClientCreateReqVO; | |
| 5 | +import cn.iocoder.yudao.framework.common.util.object.BeanUtils; | |
| 6 | 6 | import cn.iocoder.yudao.module.system.controller.admin.oauth2.vo.client.OAuth2ClientPageReqVO; |
| 7 | 7 | import cn.iocoder.yudao.module.system.controller.admin.oauth2.vo.client.OAuth2ClientRespVO; |
| 8 | -import cn.iocoder.yudao.module.system.controller.admin.oauth2.vo.client.OAuth2ClientUpdateReqVO; | |
| 9 | -import cn.iocoder.yudao.module.system.convert.auth.OAuth2ClientConvert; | |
| 8 | +import cn.iocoder.yudao.module.system.controller.admin.oauth2.vo.client.OAuth2ClientSaveReqVO; | |
| 10 | 9 | import cn.iocoder.yudao.module.system.dal.dataobject.oauth2.OAuth2ClientDO; |
| 11 | 10 | import cn.iocoder.yudao.module.system.service.oauth2.OAuth2ClientService; |
| 12 | -import io.swagger.v3.oas.annotations.tags.Tag; | |
| 13 | 11 | import io.swagger.v3.oas.annotations.Operation; |
| 14 | 12 | import io.swagger.v3.oas.annotations.Parameter; |
| 13 | +import io.swagger.v3.oas.annotations.tags.Tag; | |
| 15 | 14 | import org.springframework.security.access.prepost.PreAuthorize; |
| 16 | 15 | import org.springframework.validation.annotation.Validated; |
| 17 | 16 | import org.springframework.web.bind.annotation.*; |
| ... | ... | @@ -33,14 +32,14 @@ public class OAuth2ClientController { |
| 33 | 32 | @PostMapping("/create") |
| 34 | 33 | @Operation(summary = "创建 OAuth2 客户端") |
| 35 | 34 | @PreAuthorize("@ss.hasPermission('system:oauth2-client:create')") |
| 36 | - public CommonResult<Long> createOAuth2Client(@Valid @RequestBody OAuth2ClientCreateReqVO createReqVO) { | |
| 35 | + public CommonResult<Long> createOAuth2Client(@Valid @RequestBody OAuth2ClientSaveReqVO createReqVO) { | |
| 37 | 36 | return success(oAuth2ClientService.createOAuth2Client(createReqVO)); |
| 38 | 37 | } |
| 39 | 38 | |
| 40 | 39 | @PutMapping("/update") |
| 41 | 40 | @Operation(summary = "更新 OAuth2 客户端") |
| 42 | 41 | @PreAuthorize("@ss.hasPermission('system:oauth2-client:update')") |
| 43 | - public CommonResult<Boolean> updateOAuth2Client(@Valid @RequestBody OAuth2ClientUpdateReqVO updateReqVO) { | |
| 42 | + public CommonResult<Boolean> updateOAuth2Client(@Valid @RequestBody OAuth2ClientSaveReqVO updateReqVO) { | |
| 44 | 43 | oAuth2ClientService.updateOAuth2Client(updateReqVO); |
| 45 | 44 | return success(true); |
| 46 | 45 | } |
| ... | ... | @@ -59,16 +58,16 @@ public class OAuth2ClientController { |
| 59 | 58 | @Parameter(name = "id", description = "编号", required = true, example = "1024") |
| 60 | 59 | @PreAuthorize("@ss.hasPermission('system:oauth2-client:query')") |
| 61 | 60 | public CommonResult<OAuth2ClientRespVO> getOAuth2Client(@RequestParam("id") Long id) { |
| 62 | - OAuth2ClientDO oAuth2Client = oAuth2ClientService.getOAuth2Client(id); | |
| 63 | - return success(OAuth2ClientConvert.INSTANCE.convert(oAuth2Client)); | |
| 61 | + OAuth2ClientDO client = oAuth2ClientService.getOAuth2Client(id); | |
| 62 | + return success(BeanUtils.toBean(client, OAuth2ClientRespVO.class)); | |
| 64 | 63 | } |
| 65 | 64 | |
| 66 | 65 | @GetMapping("/page") |
| 67 | - @Operation(summary = "获得OAuth2 客户端分页") | |
| 66 | + @Operation(summary = "获得 OAuth2 客户端分页") | |
| 68 | 67 | @PreAuthorize("@ss.hasPermission('system:oauth2-client:query')") |
| 69 | 68 | public CommonResult<PageResult<OAuth2ClientRespVO>> getOAuth2ClientPage(@Valid OAuth2ClientPageReqVO pageVO) { |
| 70 | 69 | PageResult<OAuth2ClientDO> pageResult = oAuth2ClientService.getOAuth2ClientPage(pageVO); |
| 71 | - return success(OAuth2ClientConvert.INSTANCE.convertPage(pageResult)); | |
| 70 | + return success(BeanUtils.toBean(pageResult, OAuth2ClientRespVO.class)); | |
| 72 | 71 | } |
| 73 | 72 | |
| 74 | 73 | } | ... | ... |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/oauth2/OAuth2TokenController.java
| ... | ... | @@ -2,16 +2,16 @@ package cn.iocoder.yudao.module.system.controller.admin.oauth2; |
| 2 | 2 | |
| 3 | 3 | import cn.iocoder.yudao.framework.common.pojo.CommonResult; |
| 4 | 4 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 5 | +import cn.iocoder.yudao.framework.common.util.object.BeanUtils; | |
| 5 | 6 | import cn.iocoder.yudao.module.system.controller.admin.oauth2.vo.token.OAuth2AccessTokenPageReqVO; |
| 6 | 7 | import cn.iocoder.yudao.module.system.controller.admin.oauth2.vo.token.OAuth2AccessTokenRespVO; |
| 7 | -import cn.iocoder.yudao.module.system.convert.auth.OAuth2TokenConvert; | |
| 8 | 8 | import cn.iocoder.yudao.module.system.dal.dataobject.oauth2.OAuth2AccessTokenDO; |
| 9 | 9 | import cn.iocoder.yudao.module.system.enums.logger.LoginLogTypeEnum; |
| 10 | 10 | import cn.iocoder.yudao.module.system.service.auth.AdminAuthService; |
| 11 | 11 | import cn.iocoder.yudao.module.system.service.oauth2.OAuth2TokenService; |
| 12 | -import io.swagger.v3.oas.annotations.tags.Tag; | |
| 13 | -import io.swagger.v3.oas.annotations.Parameter; | |
| 14 | 12 | import io.swagger.v3.oas.annotations.Operation; |
| 13 | +import io.swagger.v3.oas.annotations.Parameter; | |
| 14 | +import io.swagger.v3.oas.annotations.tags.Tag; | |
| 15 | 15 | import org.springframework.security.access.prepost.PreAuthorize; |
| 16 | 16 | import org.springframework.web.bind.annotation.*; |
| 17 | 17 | |
| ... | ... | @@ -35,7 +35,7 @@ public class OAuth2TokenController { |
| 35 | 35 | @PreAuthorize("@ss.hasPermission('system:oauth2-token:page')") |
| 36 | 36 | public CommonResult<PageResult<OAuth2AccessTokenRespVO>> getAccessTokenPage(@Valid OAuth2AccessTokenPageReqVO reqVO) { |
| 37 | 37 | PageResult<OAuth2AccessTokenDO> pageResult = oauth2TokenService.getAccessTokenPage(reqVO); |
| 38 | - return success(OAuth2TokenConvert.INSTANCE.convert(pageResult)); | |
| 38 | + return success(BeanUtils.toBean(pageResult, OAuth2AccessTokenRespVO.class)); | |
| 39 | 39 | } |
| 40 | 40 | |
| 41 | 41 | @DeleteMapping("/delete") | ... | ... |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/oauth2/OAuth2UserController.java
| ... | ... | @@ -2,17 +2,18 @@ package cn.iocoder.yudao.module.system.controller.admin.oauth2; |
| 2 | 2 | |
| 3 | 3 | import cn.hutool.core.collection.CollUtil; |
| 4 | 4 | import cn.iocoder.yudao.framework.common.pojo.CommonResult; |
| 5 | +import cn.iocoder.yudao.framework.common.util.object.BeanUtils; | |
| 5 | 6 | import cn.iocoder.yudao.module.system.controller.admin.oauth2.vo.user.OAuth2UserInfoRespVO; |
| 6 | 7 | import cn.iocoder.yudao.module.system.controller.admin.oauth2.vo.user.OAuth2UserUpdateReqVO; |
| 7 | -import cn.iocoder.yudao.module.system.convert.oauth2.OAuth2UserConvert; | |
| 8 | +import cn.iocoder.yudao.module.system.controller.admin.user.vo.profile.UserProfileUpdateReqVO; | |
| 8 | 9 | import cn.iocoder.yudao.module.system.dal.dataobject.dept.DeptDO; |
| 9 | 10 | import cn.iocoder.yudao.module.system.dal.dataobject.dept.PostDO; |
| 10 | 11 | import cn.iocoder.yudao.module.system.dal.dataobject.user.AdminUserDO; |
| 11 | 12 | import cn.iocoder.yudao.module.system.service.dept.DeptService; |
| 12 | 13 | import cn.iocoder.yudao.module.system.service.dept.PostService; |
| 13 | 14 | import cn.iocoder.yudao.module.system.service.user.AdminUserService; |
| 14 | -import io.swagger.v3.oas.annotations.tags.Tag; | |
| 15 | 15 | import io.swagger.v3.oas.annotations.Operation; |
| 16 | +import io.swagger.v3.oas.annotations.tags.Tag; | |
| 16 | 17 | import lombok.extern.slf4j.Slf4j; |
| 17 | 18 | import org.springframework.security.access.prepost.PreAuthorize; |
| 18 | 19 | import org.springframework.validation.annotation.Validated; |
| ... | ... | @@ -53,16 +54,16 @@ public class OAuth2UserController { |
| 53 | 54 | public CommonResult<OAuth2UserInfoRespVO> getUserInfo() { |
| 54 | 55 | // 获得用户基本信息 |
| 55 | 56 | AdminUserDO user = userService.getUser(getLoginUserId()); |
| 56 | - OAuth2UserInfoRespVO resp = OAuth2UserConvert.INSTANCE.convert(user); | |
| 57 | + OAuth2UserInfoRespVO resp = BeanUtils.toBean(user, OAuth2UserInfoRespVO.class); | |
| 57 | 58 | // 获得部门信息 |
| 58 | 59 | if (user.getDeptId() != null) { |
| 59 | 60 | DeptDO dept = deptService.getDept(user.getDeptId()); |
| 60 | - resp.setDept(OAuth2UserConvert.INSTANCE.convert(dept)); | |
| 61 | + resp.setDept(BeanUtils.toBean(dept, OAuth2UserInfoRespVO.Dept.class)); | |
| 61 | 62 | } |
| 62 | 63 | // 获得岗位信息 |
| 63 | 64 | if (CollUtil.isNotEmpty(user.getPostIds())) { |
| 64 | 65 | List<PostDO> posts = postService.getPostList(user.getPostIds()); |
| 65 | - resp.setPosts(OAuth2UserConvert.INSTANCE.convertList(posts)); | |
| 66 | + resp.setPosts(BeanUtils.toBean(posts, OAuth2UserInfoRespVO.Post.class)); | |
| 66 | 67 | } |
| 67 | 68 | return success(resp); |
| 68 | 69 | } |
| ... | ... | @@ -73,7 +74,7 @@ public class OAuth2UserController { |
| 73 | 74 | public CommonResult<Boolean> updateUserInfo(@Valid @RequestBody OAuth2UserUpdateReqVO reqVO) { |
| 74 | 75 | // 这里将 UserProfileUpdateReqVO =》UserProfileUpdateReqVO 对象,实现接口的复用。 |
| 75 | 76 | // 主要是,AdminUserService 没有自己的 BO 对象,所以复用只能这么做 |
| 76 | - userService.updateUserProfile(getLoginUserId(), OAuth2UserConvert.INSTANCE.convert(reqVO)); | |
| 77 | + userService.updateUserProfile(getLoginUserId(), BeanUtils.toBean(reqVO, UserProfileUpdateReqVO.class)); | |
| 77 | 78 | return success(true); |
| 78 | 79 | } |
| 79 | 80 | ... | ... |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/oauth2/vo/client/OAuth2ClientCreateReqVO.java deleted
| 1 | -package cn.iocoder.yudao.module.system.controller.admin.oauth2.vo.client; | |
| 2 | - | |
| 3 | -import io.swagger.v3.oas.annotations.media.Schema; | |
| 4 | -import lombok.*; | |
| 5 | - | |
| 6 | -@Schema(description = "管理后台 - OAuth2 客户端创建 Request VO") | |
| 7 | -@Data | |
| 8 | -@EqualsAndHashCode(callSuper = true) | |
| 9 | -@ToString(callSuper = true) | |
| 10 | -public class OAuth2ClientCreateReqVO extends OAuth2ClientBaseVO { | |
| 11 | - | |
| 12 | -} |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/oauth2/vo/client/OAuth2ClientRespVO.java
| ... | ... | @@ -2,20 +2,62 @@ package cn.iocoder.yudao.module.system.controller.admin.oauth2.vo.client; |
| 2 | 2 | |
| 3 | 3 | import io.swagger.v3.oas.annotations.media.Schema; |
| 4 | 4 | import lombok.Data; |
| 5 | -import lombok.EqualsAndHashCode; | |
| 6 | -import lombok.ToString; | |
| 7 | 5 | |
| 8 | 6 | import java.time.LocalDateTime; |
| 7 | +import java.util.List; | |
| 9 | 8 | |
| 10 | 9 | @Schema(description = "管理后台 - OAuth2 客户端 Response VO") |
| 11 | 10 | @Data |
| 12 | -@EqualsAndHashCode(callSuper = true) | |
| 13 | -@ToString(callSuper = true) | |
| 14 | -public class OAuth2ClientRespVO extends OAuth2ClientBaseVO { | |
| 11 | +public class OAuth2ClientRespVO { | |
| 15 | 12 | |
| 16 | 13 | @Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") |
| 17 | 14 | private Long id; |
| 18 | 15 | |
| 16 | + @Schema(description = "客户端编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "tudou") | |
| 17 | + private String clientId; | |
| 18 | + | |
| 19 | + @Schema(description = "客户端密钥", requiredMode = Schema.RequiredMode.REQUIRED, example = "fan") | |
| 20 | + private String secret; | |
| 21 | + | |
| 22 | + @Schema(description = "应用名", requiredMode = Schema.RequiredMode.REQUIRED, example = "土豆") | |
| 23 | + private String name; | |
| 24 | + | |
| 25 | + @Schema(description = "应用图标", requiredMode = Schema.RequiredMode.REQUIRED, example = "https://www.iocoder.cn/xx.png") | |
| 26 | + private String logo; | |
| 27 | + | |
| 28 | + @Schema(description = "应用描述", example = "我是一个应用") | |
| 29 | + private String description; | |
| 30 | + | |
| 31 | + @Schema(description = "状态,参见 CommonStatusEnum 枚举", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") | |
| 32 | + private Integer status; | |
| 33 | + | |
| 34 | + @Schema(description = "访问令牌的有效期", requiredMode = Schema.RequiredMode.REQUIRED, example = "8640") | |
| 35 | + private Integer accessTokenValiditySeconds; | |
| 36 | + | |
| 37 | + @Schema(description = "刷新令牌的有效期", requiredMode = Schema.RequiredMode.REQUIRED, example = "8640000") | |
| 38 | + private Integer refreshTokenValiditySeconds; | |
| 39 | + | |
| 40 | + @Schema(description = "可重定向的 URI 地址", requiredMode = Schema.RequiredMode.REQUIRED, example = "https://www.iocoder.cn") | |
| 41 | + private List<String> redirectUris; | |
| 42 | + | |
| 43 | + @Schema(description = "授权类型,参见 OAuth2GrantTypeEnum 枚举", requiredMode = Schema.RequiredMode.REQUIRED, example = "password") | |
| 44 | + private List<String> authorizedGrantTypes; | |
| 45 | + | |
| 46 | + @Schema(description = "授权范围", example = "user_info") | |
| 47 | + private List<String> scopes; | |
| 48 | + | |
| 49 | + @Schema(description = "自动通过的授权范围", example = "user_info") | |
| 50 | + private List<String> autoApproveScopes; | |
| 51 | + | |
| 52 | + @Schema(description = "权限", example = "system:user:query") | |
| 53 | + private List<String> authorities; | |
| 54 | + | |
| 55 | + @Schema(description = "资源", example = "1024") | |
| 56 | + private List<String> resourceIds; | |
| 57 | + | |
| 58 | + @Schema(description = "附加信息", example = "{yunai: true}") | |
| 59 | + private String additionalInformation; | |
| 60 | + | |
| 19 | 61 | @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED) |
| 20 | 62 | private LocalDateTime createTime; |
| 21 | 63 | ... | ... |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/oauth2/vo/client/OAuth2ClientBaseVO.java renamed to yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/oauth2/vo/client/OAuth2ClientSaveReqVO.java
| ... | ... | @@ -3,7 +3,7 @@ package cn.iocoder.yudao.module.system.controller.admin.oauth2.vo.client; |
| 3 | 3 | import cn.hutool.core.util.StrUtil; |
| 4 | 4 | import cn.iocoder.yudao.framework.common.util.json.JsonUtils; |
| 5 | 5 | import io.swagger.v3.oas.annotations.media.Schema; |
| 6 | -import lombok.Data; | |
| 6 | +import lombok.*; | |
| 7 | 7 | import org.hibernate.validator.constraints.URL; |
| 8 | 8 | |
| 9 | 9 | import javax.validation.constraints.AssertTrue; |
| ... | ... | @@ -11,12 +11,12 @@ import javax.validation.constraints.NotEmpty; |
| 11 | 11 | import javax.validation.constraints.NotNull; |
| 12 | 12 | import java.util.List; |
| 13 | 13 | |
| 14 | -/** | |
| 15 | -* OAuth2 客户端 Base VO,提供给添加、修改、详细的子 VO 使用 | |
| 16 | -* 如果子 VO 存在差异的字段,请不要添加到这里,影响 Swagger 文档生成 | |
| 17 | -*/ | |
| 14 | +@Schema(description = "管理后台 - OAuth2 客户端创建/修改 Request VO") | |
| 18 | 15 | @Data |
| 19 | -public class OAuth2ClientBaseVO { | |
| 16 | +public class OAuth2ClientSaveReqVO { | |
| 17 | + | |
| 18 | + @Schema(description = "编号", example = "1024") | |
| 19 | + private Long id; | |
| 20 | 20 | |
| 21 | 21 | @Schema(description = "客户端编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "tudou") |
| 22 | 22 | @NotNull(message = "客户端编号不能为空") |
| ... | ... | @@ -52,8 +52,7 @@ public class OAuth2ClientBaseVO { |
| 52 | 52 | |
| 53 | 53 | @Schema(description = "可重定向的 URI 地址", requiredMode = Schema.RequiredMode.REQUIRED, example = "https://www.iocoder.cn") |
| 54 | 54 | @NotNull(message = "可重定向的 URI 地址不能为空") |
| 55 | - private List<@NotEmpty(message = "重定向的 URI 不能为空") | |
| 56 | - @URL(message = "重定向的 URI 格式不正确") String> redirectUris; | |
| 55 | + private List<@NotEmpty(message = "重定向的 URI 不能为空") @URL(message = "重定向的 URI 格式不正确") String> redirectUris; | |
| 57 | 56 | |
| 58 | 57 | @Schema(description = "授权类型,参见 OAuth2GrantTypeEnum 枚举", requiredMode = Schema.RequiredMode.REQUIRED, example = "password") |
| 59 | 58 | @NotNull(message = "授权类型不能为空") | ... | ... |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/oauth2/vo/client/OAuth2ClientUpdateReqVO.java deleted
| 1 | -package cn.iocoder.yudao.module.system.controller.admin.oauth2.vo.client; | |
| 2 | - | |
| 3 | -import io.swagger.v3.oas.annotations.media.Schema; | |
| 4 | -import lombok.Data; | |
| 5 | -import lombok.EqualsAndHashCode; | |
| 6 | -import lombok.ToString; | |
| 7 | - | |
| 8 | -import javax.validation.constraints.NotNull; | |
| 9 | - | |
| 10 | -@Schema(description = "管理后台 - OAuth2 客户端更新 Request VO") | |
| 11 | -@Data | |
| 12 | -@EqualsAndHashCode(callSuper = true) | |
| 13 | -@ToString(callSuper = true) | |
| 14 | -public class OAuth2ClientUpdateReqVO extends OAuth2ClientBaseVO { | |
| 15 | - | |
| 16 | - @Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") | |
| 17 | - @NotNull(message = "编号不能为空") | |
| 18 | - private Long id; | |
| 19 | - | |
| 20 | -} |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/auth/OAuth2ClientConvert.java deleted
| 1 | -package cn.iocoder.yudao.module.system.convert.auth; | |
| 2 | - | |
| 3 | -import cn.iocoder.yudao.framework.common.pojo.PageResult; | |
| 4 | -import cn.iocoder.yudao.module.system.controller.admin.oauth2.vo.client.OAuth2ClientCreateReqVO; | |
| 5 | -import cn.iocoder.yudao.module.system.controller.admin.oauth2.vo.client.OAuth2ClientRespVO; | |
| 6 | -import cn.iocoder.yudao.module.system.controller.admin.oauth2.vo.client.OAuth2ClientUpdateReqVO; | |
| 7 | -import cn.iocoder.yudao.module.system.dal.dataobject.oauth2.OAuth2ClientDO; | |
| 8 | -import org.mapstruct.Mapper; | |
| 9 | -import org.mapstruct.factory.Mappers; | |
| 10 | - | |
| 11 | -import java.util.List; | |
| 12 | - | |
| 13 | -/** | |
| 14 | - * OAuth2 客户端 Convert | |
| 15 | - * | |
| 16 | - * @author 芋道源码 | |
| 17 | - */ | |
| 18 | -@Mapper | |
| 19 | -public interface OAuth2ClientConvert { | |
| 20 | - | |
| 21 | - OAuth2ClientConvert INSTANCE = Mappers.getMapper(OAuth2ClientConvert.class); | |
| 22 | - | |
| 23 | - OAuth2ClientDO convert(OAuth2ClientCreateReqVO bean); | |
| 24 | - | |
| 25 | - OAuth2ClientDO convert(OAuth2ClientUpdateReqVO bean); | |
| 26 | - | |
| 27 | - OAuth2ClientRespVO convert(OAuth2ClientDO bean); | |
| 28 | - | |
| 29 | - List<OAuth2ClientRespVO> convertList(List<OAuth2ClientDO> list); | |
| 30 | - | |
| 31 | - PageResult<OAuth2ClientRespVO> convertPage(PageResult<OAuth2ClientDO> page); | |
| 32 | - | |
| 33 | -} |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/auth/OAuth2TokenConvert.java deleted
| 1 | -package cn.iocoder.yudao.module.system.convert.auth; | |
| 2 | - | |
| 3 | -import cn.iocoder.yudao.framework.common.pojo.PageResult; | |
| 4 | -import cn.iocoder.yudao.module.system.api.oauth2.dto.OAuth2AccessTokenCheckRespDTO; | |
| 5 | -import cn.iocoder.yudao.module.system.api.oauth2.dto.OAuth2AccessTokenRespDTO; | |
| 6 | -import cn.iocoder.yudao.module.system.controller.admin.oauth2.vo.token.OAuth2AccessTokenRespVO; | |
| 7 | -import cn.iocoder.yudao.module.system.dal.dataobject.oauth2.OAuth2AccessTokenDO; | |
| 8 | -import org.mapstruct.Mapper; | |
| 9 | -import org.mapstruct.factory.Mappers; | |
| 10 | - | |
| 11 | -@Mapper | |
| 12 | -public interface OAuth2TokenConvert { | |
| 13 | - | |
| 14 | - OAuth2TokenConvert INSTANCE = Mappers.getMapper(OAuth2TokenConvert.class); | |
| 15 | - | |
| 16 | - OAuth2AccessTokenCheckRespDTO convert(OAuth2AccessTokenDO bean); | |
| 17 | - | |
| 18 | - PageResult<OAuth2AccessTokenRespVO> convert(PageResult<OAuth2AccessTokenDO> page); | |
| 19 | - | |
| 20 | - OAuth2AccessTokenRespDTO convert2(OAuth2AccessTokenDO bean); | |
| 21 | - | |
| 22 | -} |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/oauth2/OAuth2OpenConvert.java
| ... | ... | @@ -4,6 +4,7 @@ import cn.hutool.core.date.LocalDateTimeUtil; |
| 4 | 4 | import cn.iocoder.yudao.framework.common.core.KeyValue; |
| 5 | 5 | import cn.iocoder.yudao.framework.common.enums.UserTypeEnum; |
| 6 | 6 | import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; |
| 7 | +import cn.iocoder.yudao.framework.common.util.object.BeanUtils; | |
| 7 | 8 | import cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils; |
| 8 | 9 | import cn.iocoder.yudao.module.system.controller.admin.oauth2.vo.open.OAuth2OpenAccessTokenRespVO; |
| 9 | 10 | import cn.iocoder.yudao.module.system.controller.admin.oauth2.vo.open.OAuth2OpenAuthorizeInfoRespVO; |
| ... | ... | @@ -25,21 +26,19 @@ public interface OAuth2OpenConvert { |
| 25 | 26 | OAuth2OpenConvert INSTANCE = Mappers.getMapper(OAuth2OpenConvert.class); |
| 26 | 27 | |
| 27 | 28 | default OAuth2OpenAccessTokenRespVO convert(OAuth2AccessTokenDO bean) { |
| 28 | - OAuth2OpenAccessTokenRespVO respVO = convert0(bean); | |
| 29 | + OAuth2OpenAccessTokenRespVO respVO = BeanUtils.toBean(bean, OAuth2OpenAccessTokenRespVO.class); | |
| 29 | 30 | respVO.setTokenType(SecurityFrameworkUtils.AUTHORIZATION_BEARER.toLowerCase()); |
| 30 | 31 | respVO.setExpiresIn(OAuth2Utils.getExpiresIn(bean.getExpiresTime())); |
| 31 | 32 | respVO.setScope(OAuth2Utils.buildScopeStr(bean.getScopes())); |
| 32 | 33 | return respVO; |
| 33 | 34 | } |
| 34 | - OAuth2OpenAccessTokenRespVO convert0(OAuth2AccessTokenDO bean); | |
| 35 | 35 | |
| 36 | 36 | default OAuth2OpenCheckTokenRespVO convert2(OAuth2AccessTokenDO bean) { |
| 37 | - OAuth2OpenCheckTokenRespVO respVO = convert3(bean); | |
| 37 | + OAuth2OpenCheckTokenRespVO respVO = BeanUtils.toBean(bean, OAuth2OpenCheckTokenRespVO.class); | |
| 38 | 38 | respVO.setExp(LocalDateTimeUtil.toEpochMilli(bean.getExpiresTime()) / 1000L); |
| 39 | 39 | respVO.setUserType(UserTypeEnum.ADMIN.getValue()); |
| 40 | 40 | return respVO; |
| 41 | 41 | } |
| 42 | - OAuth2OpenCheckTokenRespVO convert3(OAuth2AccessTokenDO bean); | |
| 43 | 42 | |
| 44 | 43 | default OAuth2OpenAuthorizeInfoRespVO convert(OAuth2ClientDO client, List<OAuth2ApproveDO> approves) { |
| 45 | 44 | // 构建 scopes | ... | ... |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/oauth2/OAuth2UserConvert.java deleted
| 1 | -package cn.iocoder.yudao.module.system.convert.oauth2; | |
| 2 | - | |
| 3 | -import cn.iocoder.yudao.module.system.controller.admin.oauth2.vo.user.OAuth2UserInfoRespVO; | |
| 4 | -import cn.iocoder.yudao.module.system.controller.admin.oauth2.vo.user.OAuth2UserUpdateReqVO; | |
| 5 | -import cn.iocoder.yudao.module.system.controller.admin.user.vo.profile.UserProfileUpdateReqVO; | |
| 6 | -import cn.iocoder.yudao.module.system.dal.dataobject.dept.DeptDO; | |
| 7 | -import cn.iocoder.yudao.module.system.dal.dataobject.dept.PostDO; | |
| 8 | -import cn.iocoder.yudao.module.system.dal.dataobject.user.AdminUserDO; | |
| 9 | -import org.mapstruct.Mapper; | |
| 10 | -import org.mapstruct.factory.Mappers; | |
| 11 | - | |
| 12 | -import java.util.List; | |
| 13 | - | |
| 14 | -@Mapper | |
| 15 | -public interface OAuth2UserConvert { | |
| 16 | - | |
| 17 | - OAuth2UserConvert INSTANCE = Mappers.getMapper(OAuth2UserConvert.class); | |
| 18 | - | |
| 19 | - OAuth2UserInfoRespVO convert(AdminUserDO bean); | |
| 20 | - OAuth2UserInfoRespVO.Dept convert(DeptDO dept); | |
| 21 | - List<OAuth2UserInfoRespVO.Post> convertList(List<PostDO> list); | |
| 22 | - | |
| 23 | - UserProfileUpdateReqVO convert(OAuth2UserUpdateReqVO bean); | |
| 24 | - | |
| 25 | -} |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/oauth2/OAuth2ClientService.java
| 1 | 1 | package cn.iocoder.yudao.module.system.service.oauth2; |
| 2 | 2 | |
| 3 | 3 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 4 | -import cn.iocoder.yudao.module.system.controller.admin.oauth2.vo.client.OAuth2ClientCreateReqVO; | |
| 5 | 4 | import cn.iocoder.yudao.module.system.controller.admin.oauth2.vo.client.OAuth2ClientPageReqVO; |
| 6 | -import cn.iocoder.yudao.module.system.controller.admin.oauth2.vo.client.OAuth2ClientUpdateReqVO; | |
| 5 | +import cn.iocoder.yudao.module.system.controller.admin.oauth2.vo.client.OAuth2ClientSaveReqVO; | |
| 7 | 6 | import cn.iocoder.yudao.module.system.dal.dataobject.oauth2.OAuth2ClientDO; |
| 8 | 7 | |
| 9 | 8 | import javax.validation.Valid; |
| ... | ... | @@ -24,14 +23,14 @@ public interface OAuth2ClientService { |
| 24 | 23 | * @param createReqVO 创建信息 |
| 25 | 24 | * @return 编号 |
| 26 | 25 | */ |
| 27 | - Long createOAuth2Client(@Valid OAuth2ClientCreateReqVO createReqVO); | |
| 26 | + Long createOAuth2Client(@Valid OAuth2ClientSaveReqVO createReqVO); | |
| 28 | 27 | |
| 29 | 28 | /** |
| 30 | 29 | * 更新 OAuth2 客户端 |
| 31 | 30 | * |
| 32 | 31 | * @param updateReqVO 更新信息 |
| 33 | 32 | */ |
| 34 | - void updateOAuth2Client(@Valid OAuth2ClientUpdateReqVO updateReqVO); | |
| 33 | + void updateOAuth2Client(@Valid OAuth2ClientSaveReqVO updateReqVO); | |
| 35 | 34 | |
| 36 | 35 | /** |
| 37 | 36 | * 删除 OAuth2 客户端 | ... | ... |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/oauth2/OAuth2ClientServiceImpl.java
| ... | ... | @@ -6,11 +6,10 @@ import cn.hutool.core.util.StrUtil; |
| 6 | 6 | import cn.hutool.extra.spring.SpringUtil; |
| 7 | 7 | import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; |
| 8 | 8 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 9 | +import cn.iocoder.yudao.framework.common.util.object.BeanUtils; | |
| 9 | 10 | import cn.iocoder.yudao.framework.common.util.string.StrUtils; |
| 10 | -import cn.iocoder.yudao.module.system.controller.admin.oauth2.vo.client.OAuth2ClientCreateReqVO; | |
| 11 | 11 | import cn.iocoder.yudao.module.system.controller.admin.oauth2.vo.client.OAuth2ClientPageReqVO; |
| 12 | -import cn.iocoder.yudao.module.system.controller.admin.oauth2.vo.client.OAuth2ClientUpdateReqVO; | |
| 13 | -import cn.iocoder.yudao.module.system.convert.auth.OAuth2ClientConvert; | |
| 12 | +import cn.iocoder.yudao.module.system.controller.admin.oauth2.vo.client.OAuth2ClientSaveReqVO; | |
| 14 | 13 | import cn.iocoder.yudao.module.system.dal.dataobject.oauth2.OAuth2ClientDO; |
| 15 | 14 | import cn.iocoder.yudao.module.system.dal.mysql.oauth2.OAuth2ClientMapper; |
| 16 | 15 | import cn.iocoder.yudao.module.system.dal.redis.RedisKeyConstants; |
| ... | ... | @@ -41,25 +40,25 @@ public class OAuth2ClientServiceImpl implements OAuth2ClientService { |
| 41 | 40 | private OAuth2ClientMapper oauth2ClientMapper; |
| 42 | 41 | |
| 43 | 42 | @Override |
| 44 | - public Long createOAuth2Client(OAuth2ClientCreateReqVO createReqVO) { | |
| 43 | + public Long createOAuth2Client(OAuth2ClientSaveReqVO createReqVO) { | |
| 45 | 44 | validateClientIdExists(null, createReqVO.getClientId()); |
| 46 | 45 | // 插入 |
| 47 | - OAuth2ClientDO oauth2Client = OAuth2ClientConvert.INSTANCE.convert(createReqVO); | |
| 48 | - oauth2ClientMapper.insert(oauth2Client); | |
| 49 | - return oauth2Client.getId(); | |
| 46 | + OAuth2ClientDO client = BeanUtils.toBean(createReqVO, OAuth2ClientDO.class); | |
| 47 | + oauth2ClientMapper.insert(client); | |
| 48 | + return client.getId(); | |
| 50 | 49 | } |
| 51 | 50 | |
| 52 | 51 | @Override |
| 53 | 52 | @CacheEvict(cacheNames = RedisKeyConstants.OAUTH_CLIENT, |
| 54 | 53 | allEntries = true) // allEntries 清空所有缓存,因为可能修改到 clientId 字段,不好清理 |
| 55 | - public void updateOAuth2Client(OAuth2ClientUpdateReqVO updateReqVO) { | |
| 54 | + public void updateOAuth2Client(OAuth2ClientSaveReqVO updateReqVO) { | |
| 56 | 55 | // 校验存在 |
| 57 | 56 | validateOAuth2ClientExists(updateReqVO.getId()); |
| 58 | 57 | // 校验 Client 未被占用 |
| 59 | 58 | validateClientIdExists(updateReqVO.getId(), updateReqVO.getClientId()); |
| 60 | 59 | |
| 61 | 60 | // 更新 |
| 62 | - OAuth2ClientDO updateObj = OAuth2ClientConvert.INSTANCE.convert(updateReqVO); | |
| 61 | + OAuth2ClientDO updateObj = BeanUtils.toBean(updateReqVO, OAuth2ClientDO.class); | |
| 63 | 62 | oauth2ClientMapper.updateById(updateObj); |
| 64 | 63 | } |
| 65 | 64 | ... | ... |
yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/oauth2/OAuth2ClientServiceImplTest.java
| ... | ... | @@ -4,9 +4,8 @@ import cn.hutool.extra.spring.SpringUtil; |
| 4 | 4 | import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; |
| 5 | 5 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 6 | 6 | import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest; |
| 7 | -import cn.iocoder.yudao.module.system.controller.admin.oauth2.vo.client.OAuth2ClientCreateReqVO; | |
| 8 | 7 | import cn.iocoder.yudao.module.system.controller.admin.oauth2.vo.client.OAuth2ClientPageReqVO; |
| 9 | -import cn.iocoder.yudao.module.system.controller.admin.oauth2.vo.client.OAuth2ClientUpdateReqVO; | |
| 8 | +import cn.iocoder.yudao.module.system.controller.admin.oauth2.vo.client.OAuth2ClientSaveReqVO; | |
| 10 | 9 | import cn.iocoder.yudao.module.system.dal.dataobject.oauth2.OAuth2ClientDO; |
| 11 | 10 | import cn.iocoder.yudao.module.system.dal.mysql.oauth2.OAuth2ClientMapper; |
| 12 | 11 | import org.junit.jupiter.api.Test; |
| ... | ... | @@ -42,8 +41,9 @@ public class OAuth2ClientServiceImplTest extends BaseDbUnitTest { |
| 42 | 41 | @Test |
| 43 | 42 | public void testCreateOAuth2Client_success() { |
| 44 | 43 | // 准备参数 |
| 45 | - OAuth2ClientCreateReqVO reqVO = randomPojo(OAuth2ClientCreateReqVO.class, | |
| 46 | - o -> o.setLogo(randomString())); | |
| 44 | + OAuth2ClientSaveReqVO reqVO = randomPojo(OAuth2ClientSaveReqVO.class, | |
| 45 | + o -> o.setLogo(randomString())) | |
| 46 | + .setId(null); // 防止 id 被赋值 | |
| 47 | 47 | |
| 48 | 48 | // 调用 |
| 49 | 49 | Long oauth2ClientId = oauth2ClientService.createOAuth2Client(reqVO); |
| ... | ... | @@ -51,7 +51,7 @@ public class OAuth2ClientServiceImplTest extends BaseDbUnitTest { |
| 51 | 51 | assertNotNull(oauth2ClientId); |
| 52 | 52 | // 校验记录的属性是否正确 |
| 53 | 53 | OAuth2ClientDO oAuth2Client = oauth2ClientMapper.selectById(oauth2ClientId); |
| 54 | - assertPojoEquals(reqVO, oAuth2Client); | |
| 54 | + assertPojoEquals(reqVO, oAuth2Client, "id"); | |
| 55 | 55 | } |
| 56 | 56 | |
| 57 | 57 | @Test |
| ... | ... | @@ -60,7 +60,7 @@ public class OAuth2ClientServiceImplTest extends BaseDbUnitTest { |
| 60 | 60 | OAuth2ClientDO dbOAuth2Client = randomPojo(OAuth2ClientDO.class); |
| 61 | 61 | oauth2ClientMapper.insert(dbOAuth2Client);// @Sql: 先插入出一条存在的数据 |
| 62 | 62 | // 准备参数 |
| 63 | - OAuth2ClientUpdateReqVO reqVO = randomPojo(OAuth2ClientUpdateReqVO.class, o -> { | |
| 63 | + OAuth2ClientSaveReqVO reqVO = randomPojo(OAuth2ClientSaveReqVO.class, o -> { | |
| 64 | 64 | o.setId(dbOAuth2Client.getId()); // 设置更新的 ID |
| 65 | 65 | o.setLogo(randomString()); |
| 66 | 66 | }); |
| ... | ... | @@ -75,7 +75,7 @@ public class OAuth2ClientServiceImplTest extends BaseDbUnitTest { |
| 75 | 75 | @Test |
| 76 | 76 | public void testUpdateOAuth2Client_notExists() { |
| 77 | 77 | // 准备参数 |
| 78 | - OAuth2ClientUpdateReqVO reqVO = randomPojo(OAuth2ClientUpdateReqVO.class); | |
| 78 | + OAuth2ClientSaveReqVO reqVO = randomPojo(OAuth2ClientSaveReqVO.class); | |
| 79 | 79 | |
| 80 | 80 | // 调用, 并断言异常 |
| 81 | 81 | assertServiceException(() -> oauth2ClientService.updateOAuth2Client(reqVO), OAUTH2_CLIENT_NOT_EXISTS); | ... | ... |