Skip to content

Commit e1e25eb

Browse files
authored
fix: Modify code format (#274)
1 parent a6ea0de commit e1e25eb

File tree

16 files changed

+80
-66
lines changed

16 files changed

+80
-66
lines changed

base/src/main/java/com/tinyengine/it/controller/AppTemplateController.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,6 @@
3434
import org.springframework.web.bind.annotation.RequestParam;
3535
import org.springframework.web.bind.annotation.RestController;
3636

37-
import java.util.List;
38-
3937
/**
4038
* 应用模版api
4139
*

base/src/main/java/com/tinyengine/it/controller/TenantController.java

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
import org.springframework.web.bind.annotation.RestController;
2424

2525
import java.util.List;
26-
import java.util.Map;
2726

2827
@Validated
2928
@RestController
@@ -44,13 +43,13 @@ public class TenantController {
4443
@Operation(summary = "获取组织列表", description = "获取组织列表", responses = {
4544
@ApiResponse(responseCode = "200", description = "返回信息",
4645
content = @Content(mediaType = "application/json",
47-
schema = @Schema(implementation = Tenant.class))),
46+
schema = @Schema(implementation = Tenant.class))),
4847
@ApiResponse(responseCode = "400", description = "请求失败")
4948
})
5049
@SystemControllerLog(description = "获取组织列表")
5150
@GetMapping("/tenant/list")
5251
public Result<List<Tenant>> getAllTenant() {
53-
52+
5453
return Result.success(tenantService.findAllTenant());
5554
}
5655

@@ -61,12 +60,12 @@ public Result<List<Tenant>> getAllTenant() {
6160
* @return tenant
6261
*/
6362
@Operation(summary = "新建组织", description = "新建组织",
64-
parameters = {
65-
@Parameter(name = "tenant", description = "入参对象")
66-
}, responses = {
63+
parameters = {
64+
@Parameter(name = "tenant", description = "入参对象")
65+
}, responses = {
6766
@ApiResponse(responseCode = "200", description = "返回信息",
68-
content = @Content(mediaType = "application/json",
69-
schema = @Schema(implementation = Tenant.class))),
67+
content = @Content(mediaType = "application/json",
68+
schema = @Schema(implementation = Tenant.class))),
7069
@ApiResponse(responseCode = "400", description = "请求失败")
7170
})
7271
@SystemControllerLog(description = "新建组织")

base/src/main/java/com/tinyengine/it/login/config/SSOInterceptor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
package com.tinyengine.it.login.config;
1414

15-
import com.tinyengine.it.login.Utils.JwtUtil;
15+
import com.tinyengine.it.login.utils.JwtUtil;
1616
import com.tinyengine.it.login.config.context.DefaultLoginUserContext;
1717
import com.tinyengine.it.login.model.UserInfo;
1818
import com.tinyengine.it.model.entity.Tenant;

base/src/main/java/com/tinyengine/it/login/config/context/DefaultLoginUserContext.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,25 +13,25 @@
1313
@Component
1414
public class DefaultLoginUserContext implements LoginUserContext {
1515

16-
private static final ThreadLocal<UserInfo> currentUser = new ThreadLocal<>();
16+
private static final ThreadLocal<UserInfo> CURRENT_USER = new ThreadLocal<>();
1717

1818
private static final int DEFAULT_PLATFORM = 1;
1919

2020
@Override
2121
public List<Tenant> getTenants() {
22-
UserInfo userInfo = currentUser.get();
22+
UserInfo userInfo = CURRENT_USER.get();
2323
return userInfo != null ? userInfo.getTenants() : null;
2424
}
2525

2626
@Override
2727
public String getLoginUserId() {
28-
UserInfo userInfo = currentUser.get();
28+
UserInfo userInfo = CURRENT_USER.get();
2929
return userInfo != null ? userInfo.getUserId() : null;
3030
}
3131

3232
@Override
3333
public int getPlatformId() {
34-
UserInfo userInfo = currentUser.get();
34+
UserInfo userInfo = CURRENT_USER.get();
3535
return userInfo != null ? userInfo.getPlatformId() : DEFAULT_PLATFORM;
3636
}
3737

@@ -42,33 +42,33 @@ public int getPlatformId() {
4242
*/
4343
@Override
4444
public void setTenants(List<Tenant> tenants) {
45-
UserInfo userInfo = currentUser.get();
45+
UserInfo userInfo = CURRENT_USER.get();
4646
userInfo.setTenants(tenants);
47-
currentUser.set(userInfo);
47+
CURRENT_USER.set(userInfo);
4848
}
4949

5050
/**
5151
* 设置当前用户信息
5252
*/
5353
public static void setCurrentUser(UserInfo userInfo) {
5454

55-
currentUser.set(userInfo);
55+
CURRENT_USER.set(userInfo);
5656
}
5757

5858
/**
5959
* 获取当前用户完整信息
6060
*/
6161
public static UserInfo getCurrentUser() {
6262

63-
return currentUser.get();
63+
return CURRENT_USER.get();
6464
}
6565

6666
/**
6767
* 清理用户信息
6868
*/
6969
public static void clear() {
7070

71-
currentUser.remove();
71+
CURRENT_USER.remove();
7272
}
7373

7474

base/src/main/java/com/tinyengine/it/login/controller/LoginController.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
import com.tinyengine.it.common.context.LoginUserContext;
1717
import com.tinyengine.it.common.exception.ExceptionEnum;
1818
import com.tinyengine.it.common.log.SystemControllerLog;
19-
import com.tinyengine.it.login.Utils.JwtUtil;
20-
import com.tinyengine.it.login.Utils.SM3PasswordUtil;
19+
import com.tinyengine.it.login.utils.JwtUtil;
20+
import com.tinyengine.it.login.utils.SM3PasswordUtil;
2121
import com.tinyengine.it.login.config.context.DefaultLoginUserContext;
2222
import com.tinyengine.it.login.model.PasswordResult;
2323
import com.tinyengine.it.login.model.PasswordValidationResult;
@@ -56,8 +56,8 @@
5656
import java.util.ArrayList;
5757
import java.util.List;
5858

59-
import static com.tinyengine.it.login.Utils.SM2EncryptionUtil.decrypt;
60-
import static com.tinyengine.it.login.Utils.SM2EncryptionUtil.getPrivateKeyFromBase64;
59+
import static com.tinyengine.it.login.utils.SM2EncryptionUtil.decrypt;
60+
import static com.tinyengine.it.login.utils.SM2EncryptionUtil.getPrivateKeyFromBase64;
6161

6262
/**
6363
* Login Controller
@@ -111,7 +111,7 @@ public class LoginController {
111111
public Result createUser(@Valid @RequestBody User user) throws Exception {
112112
PasswordValidationResult passwordValidationResult = configurablePasswordValidator
113113
.validateWithPolicy(user.getPassword());
114-
if(!passwordValidationResult.isValid()) {
114+
if (!passwordValidationResult.isValid()) {
115115
return Result.failed("密码格式检验失败", passwordValidationResult.getErrorMessage());
116116
}
117117
PasswordResult password = SM3PasswordUtil.createPassword(user.getPassword());
@@ -150,7 +150,7 @@ public Result<SSOTicket> login(@RequestBody User user) throws Exception {
150150

151151
PrivateKey privateKey = getPrivateKeyFromBase64(userResult.getPrivateKey());
152152
String salt = decrypt(userResult.getSalt(), privateKey);
153-
if (authenticate(salt, user.getPassword(),userResult.getPassword())) {
153+
if (authenticate(salt, user.getPassword(), userResult.getPassword())) {
154154
List<Tenant> tenants = authUsersUnitsRolesMapper.queryAllTenantByUserId(Integer.valueOf(userResult.getId()));
155155
String token = jwtUtil.generateToken(user.getUsername(), "USER", userResult.getId(),
156156
tenants, 1);
@@ -186,7 +186,7 @@ public Result<SSOTicket> login(@RequestBody User user) throws Exception {
186186
public Result forgotPassword(@RequestBody User user) throws Exception {
187187
PasswordValidationResult passwordValidationResult = configurablePasswordValidator
188188
.validateWithPolicy(user.getPassword());
189-
if(!passwordValidationResult.isValid()) {
189+
if (!passwordValidationResult.isValid()) {
190190
return Result.success(passwordValidationResult);
191191
}
192192
PasswordResult password = SM3PasswordUtil.createPassword(user.getPassword());

base/src/main/java/com/tinyengine/it/login/model/UserInfo.java

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -36,19 +36,33 @@ public UserInfo(String userId, String username, List<Tenant> tenants) {
3636
}
3737

3838
// getter和setter方法
39-
public String getUserId() { return userId; }
40-
public void setUserId(String userId) { this.userId = userId; }
41-
public String getUsername() { return username; }
42-
public void setUsername(String username) { this.username = username; }
43-
public List<Tenant> getTenants() { return tenants; }
44-
public void setTenants(List<Tenant> tenants) { this.tenants = tenants; }
45-
public int getPlatformId() { return platformId; }
46-
public void setPlatformId(int platformId) { this.platformId = platformId; }
47-
public String getRoles() { return roles; }
48-
public void setRoles(String roles) { this.roles = roles; }
49-
public String getToken() { return token; }
50-
public void setToken(String token) { this.token = token; }
51-
public String getDepartment() { return department; }
52-
public void setDepartment(String department) { this.department = department; }
39+
public String getUserId() {
40+
return userId; }
41+
public void setUserId(String userId) {
42+
this.userId = userId; }
43+
public String getUsername() {
44+
return username; }
45+
public void setUsername(String username) {
46+
this.username = username; }
47+
public List<Tenant> getTenants() {
48+
return tenants; }
49+
public void setTenants(List<Tenant> tenants) {
50+
this.tenants = tenants; }
51+
public int getPlatformId() {
52+
return platformId; }
53+
public void setPlatformId(int platformId) {
54+
this.platformId = platformId; }
55+
public String getRoles() {
56+
return roles; }
57+
public void setRoles(String roles) {
58+
this.roles = roles; }
59+
public String getToken() {
60+
return token; }
61+
public void setToken(String token) {
62+
this.token = token; }
63+
public String getDepartment() {
64+
return department; }
65+
public void setDepartment(String department) {
66+
this.department = department; }
5367

5468
}

base/src/main/java/com/tinyengine/it/login/service/ConfigurablePasswordValidator.java

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import org.springframework.beans.factory.annotation.Autowired;
1818
import org.springframework.stereotype.Service;
1919

20+
import java.util.Locale;
2021
import java.util.regex.Pattern;
2122

2223
/**
@@ -28,6 +29,12 @@ public class ConfigurablePasswordValidator {
2829
@Autowired
2930
private PasswordPolicyConfig passwordPolicy;
3031

32+
// 预编译正则表达式,避免重复编译
33+
private static final Pattern LOWERCASE_PATTERN = Pattern.compile("[a-z]");
34+
private static final Pattern UPPERCASE_PATTERN = Pattern.compile("[A-Z]");
35+
private static final Pattern DIGIT_PATTERN = Pattern.compile("[0-9]");
36+
private static final Pattern CONSECUTIVE_CHARS_PATTERN = Pattern.compile("(.)\\1{2,}");
37+
3138
public PasswordValidationResult validateWithPolicy(String password) {
3239
PasswordValidationResult result = new PasswordValidationResult();
3340

@@ -40,29 +47,29 @@ public PasswordValidationResult validateWithPolicy(String password) {
4047
// 长度检查
4148
if (password.length() < passwordPolicy.getMinLength()) {
4249
result.setValid(false);
43-
result.addError(String.format("密码长度至少%d位", passwordPolicy.getMinLength()));
50+
result.addError(String.format(Locale.ROOT, "密码长度至少%d位", passwordPolicy.getMinLength()));
4451
}
4552

4653
if (password.length() > passwordPolicy.getMaxLength()) {
4754
result.setValid(false);
48-
result.addError(String.format("密码长度不能超过%d位", passwordPolicy.getMaxLength()));
55+
result.addError(String.format(Locale.ROOT, "密码长度不能超过%d位", passwordPolicy.getMaxLength()));
4956
}
5057

51-
// 字符类型检查
58+
// 字符类型检查 - 使用预编译的Pattern
5259
if (passwordPolicy.isRequireLowerCase() &&
53-
!Pattern.compile("[a-z]").matcher(password).find()) {
60+
!LOWERCASE_PATTERN.matcher(password).find()) {
5461
result.setValid(false);
5562
result.addError("密码必须包含小写字母");
5663
}
5764

5865
if (passwordPolicy.isRequireUpperCase() &&
59-
!Pattern.compile("[A-Z]").matcher(password).find()) {
66+
!UPPERCASE_PATTERN.matcher(password).find()) {
6067
result.setValid(false);
6168
result.addError("密码必须包含大写字母");
6269
}
6370

6471
if (passwordPolicy.isRequireDigit() &&
65-
!Pattern.compile("[0-9]").matcher(password).find()) {
72+
!DIGIT_PATTERN.matcher(password).find()) {
6673
result.setValid(false);
6774
result.addError("密码必须包含数字");
6875
}
@@ -76,9 +83,9 @@ public PasswordValidationResult validateWithPolicy(String password) {
7683
}
7784
}
7885

79-
// 其他安全检查
86+
// 其他安全检查 - 使用预编译的Pattern
8087
if (passwordPolicy.isCheckConsecutiveChars() &&
81-
Pattern.compile("(.)\\1{2,}").matcher(password).find()) {
88+
CONSECUTIVE_CHARS_PATTERN.matcher(password).find()) {
8289
result.setValid(false);
8390
result.addError("密码不能包含3个及以上连续相同字符");
8491
}

base/src/main/java/com/tinyengine/it/login/service/impl/LoginServiceImpl.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
import com.tinyengine.it.mapper.UserMapper;
2222
import com.tinyengine.it.model.entity.AuthUsersUnitsRoles;
2323
import com.tinyengine.it.model.entity.User;
24-
import lombok.extern.slf4j.Slf4j;
2524
import org.springframework.beans.factory.annotation.Autowired;
2625
import org.springframework.stereotype.Service;
2726

@@ -31,17 +30,18 @@
3130
import java.util.Base64;
3231
import java.util.List;
3332

34-
import static com.tinyengine.it.login.Utils.SM2EncryptionUtil.decrypt;
35-
import static com.tinyengine.it.login.Utils.SM2EncryptionUtil.encrypt;
36-
import static com.tinyengine.it.login.Utils.SM2EncryptionUtil.generateSM2KeyPair;
37-
import static com.tinyengine.it.login.Utils.SM2EncryptionUtil.getPrivateKeyFromBase64;
38-
import static com.tinyengine.it.login.Utils.SM2EncryptionUtil.getPublicKeyFromBase64;
33+
import static com.tinyengine.it.login.utils.SM2EncryptionUtil.decrypt;
34+
import static com.tinyengine.it.login.utils.SM2EncryptionUtil.encrypt;
35+
import static com.tinyengine.it.login.utils.SM2EncryptionUtil.generateSM2KeyPair;
36+
import static com.tinyengine.it.login.utils.SM2EncryptionUtil.getPrivateKeyFromBase64;
37+
import static com.tinyengine.it.login.utils.SM2EncryptionUtil.getPublicKeyFromBase64;
3938

4039
@Service
4140
public class LoginServiceImpl extends ServiceImpl<UserMapper, User> implements LoginService {
4241

4342
@Autowired
4443
AuthUsersUnitsRolesMapper authUsersUnitsRolesMapper;
44+
4545
/**
4646
* 新增表t_user数据
4747
*

base/src/main/java/com/tinyengine/it/login/Utils/JwtUtil.java renamed to base/src/main/java/com/tinyengine/it/login/utils/JwtUtil.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
*
1111
*/
1212

13-
package com.tinyengine.it.login.Utils;
13+
package com.tinyengine.it.login.utils;
1414

1515
import com.tinyengine.it.login.service.TokenBlacklistService;
1616
import com.tinyengine.it.model.entity.Tenant;
@@ -42,7 +42,7 @@ public class JwtUtil {
4242
@Autowired
4343
private TokenBlacklistService tokenBlacklistService;
4444

45-
private static final long EXPIRATION_TIME = 21600000; // 6小时 = 6 * 60 * 60 * 1000 = 21600000 毫秒
45+
private static final long EXPIRATION_TIME = 21600000L; // 6小时 = 6 * 60 * 60 * 1000 = 21600000 毫秒
4646
private static final String DEFAULT_SECRET = "tiny-engine-backend-secret-key-at-jwt-login";
4747

4848
// 避免启动时环境变量未加载的问题

base/src/main/java/com/tinyengine/it/login/Utils/SM2EncryptionUtil.java renamed to base/src/main/java/com/tinyengine/it/login/utils/SM2EncryptionUtil.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
*
1111
*/
1212

13-
package com.tinyengine.it.login.Utils;
13+
package com.tinyengine.it.login.utils;
1414

1515
import org.bouncycastle.jce.provider.BouncyCastleProvider;
1616

0 commit comments

Comments
 (0)