Skip to content

Commit 44d81e0

Browse files
committed
修改单元测试
1 parent d5be526 commit 44d81e0

24 files changed

+348
-289
lines changed

assets/src/main/resources/sql/table-ddl.sql renamed to assets/src/main/resources/schema.sql

+3-3
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ create table categories
88
id bigserial not null primary key,
99
name varchar(127) not null UNIQUE,
1010
description varchar(255),
11-
is_enabled boolean not null default true,
11+
enabled boolean not null default true,
1212
created_by varchar(32) not null,
1313
created_date timestamp not null default CURRENT_TIMESTAMP,
1414
last_modified_by varchar(32) not null,
@@ -29,7 +29,7 @@ CREATE TABLE posts
2929
tags varchar[],
3030
cover varchar(127),
3131
category_id bigint not null,
32-
is_enabled boolean not null default true,
32+
enabled boolean not null default true,
3333
created_by varchar(32) not null,
3434
created_date timestamp not null default CURRENT_TIMESTAMP,
3535
last_modified_by varchar(32) not null,
@@ -66,7 +66,7 @@ CREATE UNIQUE INDEX idx_unique_post_id ON post_content (post_id);
6666
drop table if exists comments;
6767

6868
/*
69-
* Copyright 2018-2024 little3201.
69+
* Copyright 2018-2025 little3201.
7070
*
7171
* Licensed under the Apache License, Version 2.0 (the "License");
7272
* you may not use this file except in compliance with the License.

auth/src/main/java/io/leafage/auth/config/AuthorizationServerConfiguration.java

+32
Original file line numberDiff line numberDiff line change
@@ -30,21 +30,30 @@
3030
import org.springframework.jdbc.core.JdbcTemplate;
3131
import org.springframework.security.config.Customizer;
3232
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
33+
import org.springframework.security.core.GrantedAuthority;
3334
import org.springframework.security.oauth2.jwt.JwtDecoder;
3435
import org.springframework.security.oauth2.server.authorization.JdbcOAuth2AuthorizationConsentService;
3536
import org.springframework.security.oauth2.server.authorization.JdbcOAuth2AuthorizationService;
37+
import org.springframework.security.oauth2.server.authorization.OAuth2TokenType;
3638
import org.springframework.security.oauth2.server.authorization.client.JdbcRegisteredClientRepository;
3739
import org.springframework.security.oauth2.server.authorization.client.RegisteredClientRepository;
3840
import org.springframework.security.oauth2.server.authorization.config.annotation.web.configuration.OAuth2AuthorizationServerConfiguration;
3941
import org.springframework.security.oauth2.server.authorization.config.annotation.web.configurers.OAuth2AuthorizationServerConfigurer;
4042
import org.springframework.security.oauth2.server.authorization.settings.AuthorizationServerSettings;
43+
import org.springframework.security.oauth2.server.authorization.token.JwtEncodingContext;
44+
import org.springframework.security.oauth2.server.authorization.token.OAuth2TokenCustomizer;
4145
import org.springframework.security.web.SecurityFilterChain;
4246
import org.springframework.security.web.authentication.LoginUrlAuthenticationEntryPoint;
4347
import org.springframework.security.web.util.matcher.MediaTypeRequestMatcher;
4448
import org.springframework.web.cors.CorsConfiguration;
4549
import org.springframework.web.cors.CorsConfigurationSource;
4650
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
4751

52+
import java.util.Collection;
53+
import java.util.Optional;
54+
import java.util.Set;
55+
import java.util.stream.Collectors;
56+
4857
import static org.springframework.security.oauth2.server.authorization.config.annotation.web.configurers.OAuth2AuthorizationServerConfigurer.authorizationServer;
4958

5059
/**
@@ -114,6 +123,29 @@ public JwtDecoder jwtDecoder(JWKSource<SecurityContext> jwkSource) {
114123
return OAuth2AuthorizationServerConfiguration.jwtDecoder(jwkSource);
115124
}
116125

126+
@Bean
127+
public OAuth2TokenCustomizer<JwtEncodingContext> jwtTokenCustomizer() {
128+
return (context -> {
129+
if (OAuth2TokenType.ACCESS_TOKEN.equals(context.getTokenType())) {
130+
context.getClaims().claims(claims -> {
131+
// 获取原有的 scope,若不存在则初始化
132+
Set<String> scope = Optional.ofNullable((Collection<?>) claims.get("scope"))
133+
.stream()
134+
.flatMap(Collection::stream)
135+
.filter(String.class::isInstance)
136+
.map(String.class::cast)
137+
.collect(Collectors.toSet());
138+
claims.put("scope", scope);
139+
140+
// 获取用户权限并添加到 scope
141+
context.getPrincipal().getAuthorities().stream()
142+
.map(GrantedAuthority::getAuthority)
143+
.forEach(scope::add);
144+
});
145+
}
146+
});
147+
}
148+
117149
@Bean
118150
public CorsConfigurationSource corsConfigurationSource() {
119151
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();

hypervisor/src/main/java/io/leafage/basic/hypervisor/bo/PrivilegeBO.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,10 @@ public abstract class PrivilegeBO {
4242
*/
4343
@NotBlank(message = "icon must not be empty.")
4444
private String icon;
45-
4645
/**
4746
* 路径
4847
*/
4948
private String path;
50-
5149
/**
5250
* redirect
5351
*/
@@ -56,7 +54,9 @@ public abstract class PrivilegeBO {
5654
* component
5755
*/
5856
private String component;
59-
57+
/**
58+
* 操作
59+
*/
6060
private Set<String> actions;
6161
/**
6262
* 描述

hypervisor/src/main/java/io/leafage/basic/hypervisor/controller/AccessLogController.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2018-2024 little3201.
2+
* Copyright 2018-2025 little3201.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -47,7 +47,7 @@ public class AccessLogController {
4747
/**
4848
* <p>Constructor for AccessLogController.</p>
4949
*
50-
* @param accessLogService a {@link io.leafage.basic.hypervisor.service.AccessLogService} object
50+
* @param accessLogService a {@link AccessLogService} object
5151
*/
5252
public AccessLogController(AccessLogService accessLogService) {
5353
this.accessLogService = accessLogService;

hypervisor/src/main/java/io/leafage/basic/hypervisor/controller/DictionaryController.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2018-2024 little3201.
2+
* Copyright 2018-2025 little3201.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -48,7 +48,7 @@ public class DictionaryController {
4848
/**
4949
* <p>Constructor for DictionaryController.</p>
5050
*
51-
* @param dictionaryService a {@link io.leafage.basic.hypervisor.service.DictionaryService} object
51+
* @param dictionaryService a {@link DictionaryService} object
5252
*/
5353
public DictionaryController(DictionaryService dictionaryService) {
5454
this.dictionaryService = dictionaryService;

hypervisor/src/main/java/io/leafage/basic/hypervisor/controller/GroupController.java

+27-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2018-2024 little3201.
2+
* Copyright 2018-2025 little3201.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -18,8 +18,10 @@
1818
package io.leafage.basic.hypervisor.controller;
1919

2020
import io.leafage.basic.hypervisor.domain.GroupMembers;
21+
import io.leafage.basic.hypervisor.domain.GroupPrivileges;
2122
import io.leafage.basic.hypervisor.dto.GroupDTO;
2223
import io.leafage.basic.hypervisor.service.GroupMembersService;
24+
import io.leafage.basic.hypervisor.service.GroupPrivilegesService;
2325
import io.leafage.basic.hypervisor.service.GroupService;
2426
import io.leafage.basic.hypervisor.vo.GroupVO;
2527
import jakarta.validation.Valid;
@@ -33,6 +35,7 @@
3335
import reactor.core.publisher.Mono;
3436

3537
import java.util.List;
38+
import java.util.Set;
3639

3740
/**
3841
* group controller
@@ -48,16 +51,19 @@ public class GroupController {
4851

4952
private final GroupMembersService groupMembersService;
5053
private final GroupService groupService;
54+
private final GroupPrivilegesService groupPrivilegesService;
5155

5256
/**
5357
* <p>Constructor for GroupController.</p>
5458
*
55-
* @param groupMembersService a {@link io.leafage.basic.hypervisor.service.GroupMembersService} object
56-
* @param groupService a {@link io.leafage.basic.hypervisor.service.GroupService} object
59+
* @param groupMembersService a {@link GroupMembersService} object
60+
* @param groupService a {@link GroupService} object
61+
* @param groupPrivilegesService a {@link GroupPrivilegesService} object
5762
*/
58-
public GroupController(GroupMembersService groupMembersService, GroupService groupService) {
63+
public GroupController(GroupMembersService groupMembersService, GroupService groupService, GroupPrivilegesService groupPrivilegesService) {
5964
this.groupMembersService = groupMembersService;
6065
this.groupService = groupService;
66+
this.groupPrivilegesService = groupPrivilegesService;
6167
}
6268

6369
/**
@@ -189,4 +195,21 @@ public ResponseEntity<Mono<List<GroupMembers>>> members(@PathVariable Long id) {
189195
return ResponseEntity.ok(listMono);
190196
}
191197

198+
/**
199+
* 关联权限
200+
*
201+
* @param id 组id
202+
* @return 查询到的数据集,异常时返回204状态码
203+
*/
204+
@PatchMapping("/{id}/privileges/{privilegeId}")
205+
public ResponseEntity<Mono<GroupPrivileges>> relation(@PathVariable Long id, @PathVariable Long privilegeId, @RequestBody Set<String> actions) {
206+
Mono<GroupPrivileges> mono;
207+
try {
208+
mono = groupPrivilegesService.relation(id, privilegeId, actions);
209+
} catch (Exception e) {
210+
logger.error("Relation group privileges occurred an error: ", e);
211+
return ResponseEntity.noContent().build();
212+
}
213+
return ResponseEntity.ok(mono);
214+
}
192215
}

hypervisor/src/main/java/io/leafage/basic/hypervisor/controller/MessageController.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2018-2024 little3201.
2+
* Copyright 2018-2025 little3201.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -47,7 +47,7 @@ public class MessageController {
4747
/**
4848
* <p>Constructor for MessageController.</p>
4949
*
50-
* @param messageService a {@link io.leafage.basic.hypervisor.service.MessageService} object
50+
* @param messageService a {@link MessageService} object
5151
*/
5252
public MessageController(MessageService messageService) {
5353
this.messageService = messageService;

hypervisor/src/main/java/io/leafage/basic/hypervisor/controller/UserController.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public class UserController {
4949
/**
5050
* <p>Constructor for UserController.</p>
5151
*
52-
* @param userService a {@link io.leafage.basic.hypervisor.service.UserService} object
52+
* @param userService a {@link UserService} object
5353
*/
5454
public UserController(UserService userService) {
5555
this.userService = userService;

hypervisor/src/main/java/io/leafage/basic/hypervisor/domain/GroupRoles.java renamed to hypervisor/src/main/java/io/leafage/basic/hypervisor/domain/GroupPrivileges.java

+26-14
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2018-2024 little3201.
2+
* Copyright 2018-2025 little3201.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -21,13 +21,15 @@
2121
import org.springframework.data.relational.core.mapping.Column;
2222
import org.springframework.data.relational.core.mapping.Table;
2323

24+
import java.util.Set;
25+
2426
/**
25-
* model class for group roles
27+
* model class for group privileges
2628
*
2729
* @author wq li
2830
*/
29-
@Table(name = "group_roles")
30-
public class GroupRoles {
31+
@Table(name = "group_privileges")
32+
public class GroupPrivileges {
3133

3234
/**
3335
* 主键
@@ -40,10 +42,12 @@ public class GroupRoles {
4042
@Column(value = "group_id")
4143
private Long groupId;
4244
/**
43-
* role主键
45+
* privilege主键
4446
*/
45-
@Column(value = "role_id")
46-
private Long roleId;
47+
@Column(value = "privilege_id")
48+
private Long privilegeId;
49+
50+
private Set<String> actions;
4751

4852
/**
4953
* <p>Getter for the field <code>id</code>.</p>
@@ -82,20 +86,28 @@ public void setGroupId(Long groupId) {
8286
}
8387

8488
/**
85-
* <p>Getter for the field <code>roleId</code>.</p>
89+
* <p>Getter for the field <code>privilegeId</code>.</p>
8690
*
8791
* @return a {@link java.lang.Long} object
8892
*/
89-
public Long getRoleId() {
90-
return roleId;
93+
public Long getPrivilegeId() {
94+
return privilegeId;
9195
}
9296

9397
/**
94-
* <p>Setter for the field <code>roleId</code>.</p>
98+
* <p>Setter for the field <code>privilegeId</code>.</p>
9599
*
96-
* @param roleId a {@link java.lang.Long} object
100+
* @param privilegeId a {@link java.lang.Long} object
97101
*/
98-
public void setRoleId(Long roleId) {
99-
this.roleId = roleId;
102+
public void setPrivilegeId(Long privilegeId) {
103+
this.privilegeId = privilegeId;
104+
}
105+
106+
public Set<String> getActions() {
107+
return actions;
108+
}
109+
110+
public void setActions(Set<String> actions) {
111+
this.actions = actions;
100112
}
101113
}

hypervisor/src/main/java/io/leafage/basic/hypervisor/repository/GroupMembersRepository.java

+1-10
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2018-2024 little3201.
2+
* Copyright 2018-2025 little3201.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -21,7 +21,6 @@
2121
import org.springframework.data.r2dbc.repository.R2dbcRepository;
2222
import org.springframework.stereotype.Repository;
2323
import reactor.core.publisher.Flux;
24-
import reactor.core.publisher.Mono;
2524

2625
/**
2726
* group members repository
@@ -31,14 +30,6 @@
3130
@Repository
3231
public interface GroupMembersRepository extends R2dbcRepository<GroupMembers, Long> {
3332

34-
/**
35-
* 统计关联member
36-
*
37-
* @param groupId 组ID
38-
* @return result
39-
*/
40-
Mono<Long> countByGroupId(Long groupId);
41-
4233
/**
4334
* 根据group查member
4435
*

0 commit comments

Comments
 (0)