mirror of
http://git.pig4cloud.com/pig/pigx.git
synced 2026-11-08 04:39:00 +08:00
fix(upms): 收紧客户端详情查询接口权限
This commit is contained in:
1 parent
a043c4f19e
commit
0aaaee14fb
2 files changed
+81
-8
No files matched your search
+20
-8
@@ -20,6 +20,7 @@
|
||||
package com.pig4cloud.pigx.admin.controller;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.util.ObjUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
@@ -36,6 +37,7 @@ import com.pig4cloud.pigx.common.excel.annotation.ResponseExcel;
|
||||
import com.pig4cloud.pigx.common.log.annotation.SysLog;
|
||||
import com.pig4cloud.pigx.common.security.annotation.HasPermission;
|
||||
import com.pig4cloud.pigx.common.security.annotation.Inner;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import jakarta.validation.Valid;
|
||||
@@ -65,14 +67,20 @@ public class SysClientController {
|
||||
private final SysOauthClientDetailsService clientDetailsService;
|
||||
|
||||
/**
|
||||
* 通过ID查询
|
||||
* @param clientId clientId
|
||||
* @return SysOauthClientDetails
|
||||
* 根据客户端 ID 查询管理端展示详情。
|
||||
*
|
||||
* @param clientId OAuth2 客户端 ID
|
||||
* @return 客户端详情查询结果;客户端不存在时响应数据为 {@code null}
|
||||
*/
|
||||
@Operation(summary = "根据客户端 ID 查询详情")
|
||||
@GetMapping("/{clientId}")
|
||||
public R getByClientId(@PathVariable String clientId) {
|
||||
public R<SysOauthClientDetailsDTO> getByClientId(@PathVariable String clientId) {
|
||||
SysOauthClientDetails details = clientDetailsService
|
||||
.getOne(Wrappers.<SysOauthClientDetails>lambdaQuery().eq(SysOauthClientDetails::getClientId, clientId));
|
||||
.getOne(Wrappers.<SysOauthClientDetails>lambdaQuery().eq(SysOauthClientDetails::getClientId, clientId), false);
|
||||
if (ObjUtil.isNull(details)) {
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
String information = details.getAdditionalInformation();
|
||||
String captchaFlag = JSONUtil.parseObj(information).getStr(CommonConstants.CAPTCHA_FLAG);
|
||||
String encFlag = JSONUtil.parseObj(information).getStr(CommonConstants.ENC_FLAG);
|
||||
@@ -142,11 +150,15 @@ public class SysClientController {
|
||||
}
|
||||
|
||||
/**
|
||||
* Feign 查询客户端信息的接口
|
||||
* @param clientId 客户端 ID
|
||||
* @return 基本信息
|
||||
* 根据客户端 ID 查询 OAuth2 客户端详情。
|
||||
* <p>
|
||||
* 仅供认证中心通过 Feign 发起内部调用;{@link Inner} 校验内部调用标识,不对外提供公开访问。
|
||||
* </p>
|
||||
* @param clientId OAuth2 客户端 ID
|
||||
* @return 客户端详情查询结果;客户端不存在时响应数据为 {@code null}
|
||||
*/
|
||||
@Inner
|
||||
@Operation(summary = "查询 OAuth2 客户端详情(内部调用)", hidden = true)
|
||||
@GetMapping("/getClientDetailsById/{clientId}")
|
||||
public R getClientDetailsById(@PathVariable String clientId) {
|
||||
return R.ok(clientDetailsService.getOne(
|
||||
|
||||
+61
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
* Copyright (c) 2018-2026, lengleng 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 pig4cloud.com nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
* Author: lengleng (wangiegie@gmail.com)
|
||||
*/
|
||||
|
||||
package com.pig4cloud.pigx.admin.controller;
|
||||
|
||||
import com.pig4cloud.pigx.admin.api.dto.SysOauthClientDetailsDTO;
|
||||
import com.pig4cloud.pigx.admin.api.entity.SysOauthClientDetails;
|
||||
import com.pig4cloud.pigx.admin.service.SysOauthClientDetailsService;
|
||||
import com.pig4cloud.pigx.common.core.util.R;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
class SysClientControllerTests {
|
||||
|
||||
@Test
|
||||
void getByClientIdReturnsNullDataWhenClientDoesNotExist() {
|
||||
SysOauthClientDetailsService clientDetailsService = mock(SysOauthClientDetailsService.class);
|
||||
SysClientController controller = new SysClientController(clientDetailsService);
|
||||
when(clientDetailsService.getOne(any(), eq(false))).thenReturn(null);
|
||||
|
||||
R<SysOauthClientDetailsDTO> result = controller.getByClientId("missing-client");
|
||||
|
||||
assertThat(result.isOk()).isTrue();
|
||||
assertThat(result.getData()).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
void getByClientIdHandlesNullAdditionalInformation() {
|
||||
SysOauthClientDetailsService clientDetailsService = mock(SysOauthClientDetailsService.class);
|
||||
SysClientController controller = new SysClientController(clientDetailsService);
|
||||
SysOauthClientDetails details = new SysOauthClientDetails();
|
||||
details.setClientId("client-without-additional-information");
|
||||
when(clientDetailsService.getOne(any(), eq(false))).thenReturn(details);
|
||||
|
||||
R<SysOauthClientDetailsDTO> result = controller.getByClientId(details.getClientId());
|
||||
|
||||
assertThat(result.isOk()).isTrue();
|
||||
assertThat(result.getData()).isNotNull();
|
||||
assertThat(result.getData().getClientId()).isEqualTo(details.getClientId());
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user