Skip to content

Commit 55f7abf

Browse files
authored
Merge pull request #44 from CJP2004/dev
Dev
2 parents 6aa98f8 + 23af461 commit 55f7abf

29 files changed

Lines changed: 1756 additions & 1529 deletions

auth-service/pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,11 @@
6262
<artifactId>poi-ooxml</artifactId>
6363
<version>5.2.5</version>
6464
</dependency>
65+
<dependency>
66+
<groupId>com.github.xingfudeshi</groupId>
67+
<artifactId>knife4j-openapi3-jakarta-spring-boot-starter</artifactId>
68+
<version>4.6.0</version>
69+
</dependency>
6570

6671
<dependency>
6772
<groupId>org.springframework.boot</groupId>
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package com.servicegovernance.auth.controller;
2+
3+
import com.servicegovernance.auth.common.core.ApiResponse;
4+
import com.servicegovernance.auth.service.ApiReverseAuthorizationService;
5+
import io.swagger.v3.oas.annotations.Operation;
6+
import io.swagger.v3.oas.annotations.tags.Tag;
7+
import java.util.Map;
8+
import org.springframework.web.bind.annotation.PostMapping;
9+
import org.springframework.web.bind.annotation.RequestBody;
10+
import org.springframework.web.bind.annotation.RequestMapping;
11+
import org.springframework.web.bind.annotation.RestController;
12+
13+
@Tag(name = "API 反向授权")
14+
@RestController
15+
@RequestMapping("/api/authorization")
16+
public class ApiReverseAuthorizationController {
17+
18+
private final ApiReverseAuthorizationService apiReverseAuthorizationService;
19+
20+
public ApiReverseAuthorizationController(ApiReverseAuthorizationService apiReverseAuthorizationService) {
21+
this.apiReverseAuthorizationService = apiReverseAuthorizationService;
22+
}
23+
24+
/** 查询 API 反向授权列表。 */
25+
@Operation(summary = "查询反向授权列表", description = "按被调用方、调用方和授权状态等条件查询反向授权列表。")
26+
@PostMapping("/reverse/list")
27+
public ApiResponse<Map<String, Object>> reverseList(@RequestBody Map<String, Object> query) {
28+
return ApiResponse.success(apiReverseAuthorizationService.reverseList(query));
29+
}
30+
31+
/** 查询 API 反向授权详情。 */
32+
@Operation(summary = "查询反向授权详情", description = "根据请求参数查询反向授权详情及其关联 API 配置。")
33+
@PostMapping("/reverse/detail")
34+
public ApiResponse<Map<String, Object>> reverseDetail(@RequestBody Map<String, Object> payload) {
35+
return ApiResponse.success(apiReverseAuthorizationService.reverseDetail(payload));
36+
}
37+
38+
/** 保存 API 反向授权配置。 */
39+
@Operation(summary = "保存反向授权配置", description = "保存反向授权关系和对应的 API 权限配置。")
40+
@PostMapping("/reverse/save")
41+
public ApiResponse<Boolean> saveReverse(@RequestBody Map<String, Object> payload) {
42+
apiReverseAuthorizationService.saveReverse(payload);
43+
return ApiResponse.success(true);
44+
}
45+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package com.servicegovernance.auth.controller;
2+
3+
import com.servicegovernance.auth.common.core.ApiResponse;
4+
import com.servicegovernance.auth.service.AuthorizationAccessService;
5+
import io.swagger.v3.oas.annotations.Operation;
6+
import io.swagger.v3.oas.annotations.tags.Tag;
7+
import java.util.Map;
8+
import org.springframework.web.bind.annotation.PostMapping;
9+
import org.springframework.web.bind.annotation.RequestBody;
10+
import org.springframework.web.bind.annotation.RequestHeader;
11+
import org.springframework.web.bind.annotation.RequestMapping;
12+
import org.springframework.web.bind.annotation.RestController;
13+
14+
@Tag(name = "授权访问校验")
15+
@RestController
16+
@RequestMapping("/api/authorization")
17+
public class AuthorizationAccessController {
18+
19+
private final AuthorizationAccessService authorizationAccessService;
20+
21+
public AuthorizationAccessController(AuthorizationAccessService authorizationAccessService) {
22+
this.authorizationAccessService = authorizationAccessService;
23+
}
24+
25+
/** 供远程服务调用,校验服务身份和授权关系。 */
26+
@Operation(summary = "校验授权关系", description = "根据调用关系和接口信息校验当前授权配置是否满足访问要求。")
27+
@PostMapping("/check")
28+
public ApiResponse<Map<String, Object>> check(@RequestBody Map<String, Object> payload) {
29+
return ApiResponse.success(authorizationAccessService.check(payload));
30+
}
31+
32+
/** 供远程服务按 Basic 认证查询可访问资源。 */
33+
@Operation(summary = "查询资源权限列表", description = "结合请求头中的 Authorization 信息和查询条件,返回当前资源权限列表。")
34+
@PostMapping("/resource/list")
35+
public ApiResponse<Map<String, Object>> resourceList(
36+
@RequestHeader(value = "Authorization", required = false) String authorization,
37+
@RequestBody Map<String, Object> payload) {
38+
return ApiResponse.success(authorizationAccessService.resourceList(authorization, payload));
39+
}
40+
}

auth-service/src/main/java/com/servicegovernance/auth/controller/AuthorizationController.java

Lines changed: 0 additions & 122 deletions
This file was deleted.
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
package com.servicegovernance.auth.controller;
2+
3+
import com.servicegovernance.auth.common.core.ApiResponse;
4+
import com.servicegovernance.auth.service.SingleAppAuthorizationService;
5+
import io.swagger.v3.oas.annotations.Operation;
6+
import io.swagger.v3.oas.annotations.tags.Tag;
7+
import jakarta.servlet.http.HttpServletResponse;
8+
import java.util.Map;
9+
import org.springframework.web.bind.annotation.PostMapping;
10+
import org.springframework.web.bind.annotation.RequestBody;
11+
import org.springframework.web.bind.annotation.RequestMapping;
12+
import org.springframework.web.bind.annotation.RestController;
13+
14+
@Tag(name = "单应用授权")
15+
@RestController
16+
@RequestMapping("/api/authorization")
17+
public class SingleAppAuthorizationController {
18+
19+
private final SingleAppAuthorizationService singleAppAuthorizationService;
20+
21+
public SingleAppAuthorizationController(SingleAppAuthorizationService singleAppAuthorizationService) {
22+
this.singleAppAuthorizationService = singleAppAuthorizationService;
23+
}
24+
25+
/** 查询单应用授权列表。 */
26+
@Operation(summary = "查询单应用授权列表", description = "按调用方、被调用方和授权状态等条件查询单应用授权列表。")
27+
@PostMapping("/single-app/list")
28+
public ApiResponse<Map<String, Object>> singleAppList(@RequestBody Map<String, Object> query) {
29+
return ApiResponse.success(singleAppAuthorizationService.singleAppList(query));
30+
}
31+
32+
/** 查询单应用授权详情和可配置 API。 */
33+
@Operation(summary = "查询单应用授权详情", description = "根据请求参数查询单应用授权详情及其关联 API 配置。")
34+
@PostMapping("/single-app/detail")
35+
public ApiResponse<Map<String, Object>> singleAppDetail(@RequestBody Map<String, Object> payload) {
36+
return ApiResponse.success(singleAppAuthorizationService.singleAppDetail(payload));
37+
}
38+
39+
/** 保存单应用授权配置。 */
40+
@Operation(summary = "保存单应用授权配置", description = "保存单应用授权关系和对应的 API 权限配置。")
41+
@PostMapping("/single-app/save")
42+
public ApiResponse<Boolean> saveSingleApp(@RequestBody Map<String, Object> payload) {
43+
return ApiResponse.success(singleAppAuthorizationService.saveSingleApp(payload));
44+
}
45+
46+
/** 导出单应用授权数据为 Excel。 */
47+
@Operation(summary = "导出单应用授权 Excel", description = "根据搜索条件查询全量授权数据,生成 .xlsx 文件通过 HTTP 文件流返回。")
48+
@PostMapping("/single-app/export")
49+
public void exportExcel(@RequestBody Map<String, Object> query, HttpServletResponse response) {
50+
singleAppAuthorizationService.exportExcel(query, response);
51+
}
52+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package com.servicegovernance.auth.mapper;
2+
3+
import java.util.List;
4+
import java.util.Map;
5+
import org.apache.ibatis.annotations.Mapper;
6+
import org.apache.ibatis.annotations.Param;
7+
8+
@Mapper
9+
public interface ApiReverseAuthorizationMapper {
10+
11+
List<Map<String, Object>> selectReverseList(@Param("query") Map<String, Object> query);
12+
13+
Long countReverseList(@Param("query") Map<String, Object> query);
14+
15+
List<Map<String, Object>> selectReverseSelectedApis(@Param("apiIds") List<Long> apiIds);
16+
17+
List<Map<String, Object>> selectReverseCheckedApps(@Param("apiIds") List<Long> apiIds,
18+
@Param("apiCount") int apiCount);
19+
20+
List<Map<String, Object>> selectReverseDetailApps(@Param("apiId") Long apiId);
21+
22+
Long selectAppIdByCode(@Param("appCode") String appCode);
23+
24+
int insertAuth(@Param("callerAppId") Long callerAppId, @Param("calleeAppId") Long calleeAppId,
25+
@Param("apiId") Long apiId);
26+
27+
Long nextAuthLogId();
28+
29+
Map<String, Object> selectAuthLogDetail(@Param("callerAppId") Long callerAppId,
30+
@Param("calleeAppId") Long calleeAppId, @Param("apiId") Long apiId);
31+
32+
int insertAuthLog(@Param("logId") Long logId, @Param("detail") Map<String, Object> detail,
33+
@Param("operationType") int operationType);
34+
35+
Long countActiveAuth(@Param("callerAppId") Long callerAppId, @Param("calleeAppId") Long calleeAppId,
36+
@Param("apiId") Long apiId);
37+
38+
int revokeOne(@Param("callerAppId") Long callerAppId, @Param("calleeAppId") Long calleeAppId,
39+
@Param("apiId") Long apiId);
40+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package com.servicegovernance.auth.mapper;
2+
3+
import java.util.List;
4+
import java.util.Map;
5+
import org.apache.ibatis.annotations.Mapper;
6+
import org.apache.ibatis.annotations.Param;
7+
8+
@Mapper
9+
public interface AuthorizationAccessMapper {
10+
11+
Long selectAppIdByCode(@Param("appCode") String appCode);
12+
13+
Map<String, Object> selectAppCredentialByCode(@Param("appCode") String appCode);
14+
15+
Long countAnyActiveAuth(@Param("callerAppId") Long callerAppId, @Param("calleeAppId") Long calleeAppId);
16+
17+
Long nextCallDecisionLogId();
18+
19+
int insertCallDecisionLog(@Param("logId") Long logId, @Param("caller") Map<String, Object> caller,
20+
@Param("callee") Map<String, Object> callee, @Param("decisionResult") int decisionResult,
21+
@Param("decisionReason") String decisionReason);
22+
23+
List<String> selectAuthorizedUrls(@Param("callerAppId") Long callerAppId,
24+
@Param("calleeAppId") Long calleeAppId);
25+
26+
Long selectResourceVersion(@Param("calleeAppId") Long calleeAppId);
27+
}

0 commit comments

Comments
 (0)