Skip to content

Commit

Permalink
Dev (#314)
Browse files Browse the repository at this point in the history
* Refactor/replace deprecated usage (#236)

* chore: 修正README锚点不跳转的问题

* fix:#190

* fix:#184

* chore(deps-dev): bump freemarker from 2.3.30 to 2.3.31

Bumps freemarker from 2.3.30 to 2.3.31.

Signed-off-by: dependabot[bot] <[email protected]>

* chore(deps): bump lin-cms-spring-boot-starter

Bumps [lin-cms-spring-boot-starter](https://github.com/TaleLin/lin-cms-java-core) from 0.2.0-RC2 to 0.2.0-RELEASE.
- [Release notes](https://github.com/TaleLin/lin-cms-java-core/releases)
- [Commits](https://github.com/TaleLin/lin-cms-java-core/commits)

Signed-off-by: dependabot[bot] <[email protected]>

* Chore/upgrade version (#200)

* chore: 修正README锚点不跳转的问题

* fix:#190

* fix:#184

* chore: 升级主工程以及核心库版本号

Co-authored-by: ToWeLong <[email protected]>

* chore(deps): bump spring-boot-starter-parent from 2.4.3 to 2.5.0

Bumps [spring-boot-starter-parent](https://github.com/spring-projects/spring-boot) from 2.4.3 to 2.5.0.
- [Release notes](https://github.com/spring-projects/spring-boot/releases)
- [Commits](spring-projects/spring-boot@v2.4.3...v2.5.0)

Signed-off-by: dependabot[bot] <[email protected]>

* Dev (#226)

* chore(deps): bump spring-boot-starter-parent from 2.5.0 to 2.5.2 (#220)

Bumps [spring-boot-starter-parent](https://github.com/spring-projects/spring-boot) from 2.5.0 to 2.5.2.
- [Release notes](https://github.com/spring-projects/spring-boot/releases)
- [Commits](spring-projects/spring-boot@v2.5.0...v2.5.2)

---
updated-dependencies:
- dependency-name: org.springframework.boot:spring-boot-starter-parent
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <[email protected]>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* refactor: optimize ci action config

* Update maven.yml

* Update maven.yml

* fix issue #131

* chore(deps): bump qiniu-java-sdk from 7.4.0 to 7.8.0

Bumps [qiniu-java-sdk](https://github.com/qiniu/java-sdk) from 7.4.0 to 7.8.0.
- [Release notes](https://github.com/qiniu/java-sdk/releases)
- [Changelog](https://github.com/qiniu/java-sdk/blob/master/CHANGELOG.md)
- [Commits](qiniu/java-sdk@v7.4.0...v7.8.0)

---
updated-dependencies:
- dependency-name: com.qiniu:qiniu-java-sdk
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <[email protected]>

* Chore/replace expired configurations (#222)

* chore: 修正README锚点不跳转的问题

* fix:#190

* fix:#184

* chore: 替换过期的配置项

* test: 临时解决 CI 单元测试异常(原因未明)

Co-authored-by: ToWeLong <[email protected]>
Co-authored-by: 华钦 <[email protected]>

* Docs/upgrade readme (#225)

* chore: 修正README锚点不跳转的问题

* fix:#190

* fix:#184

* docs: 更新 readme 中 springboot 版本号

Co-authored-by: ToWeLong <[email protected]>
Co-authored-by: 华钦 <[email protected]>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: dengliming <[email protected]>
Co-authored-by: fuhao <[email protected]>
Co-authored-by: ToWeLong <[email protected]>
Co-authored-by: 华钦 <[email protected]>

* refactor: 替换jackson已过期的配置引用

Co-authored-by: ToWeLong <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: 华钦 <[email protected]>
Co-authored-by: dengliming <[email protected]>
Co-authored-by: fuhao <[email protected]>

* chore(pom.xml): 升级框架版本为0.2.1-RELEASE

* fix #223 & test去除deprecated api等问题修复

* fix: #247

* fix: 反代后IP获取错误

* feat: 登录验证码

* fix: 无用字段

* fix: 不开启验证码时要求header的错误

* fix: sout clean

* fix: aes192 to 256

* fix: 修复错误修改的配置

* fix: 增加aes配置校验,避免输入参数不合法

* fix: 部分情况下fileMap.size()不可靠&校验信息不需要${}

* fix: 属性前缀

* fix: fix #264

配置文件中未配置字段时,spring不会调用set方法

* chore(application-dev.yml): 默认关闭验证码

* refactor: 数据库新增 is_deleted 字段,作为删除标识

* refactor: non null copy (#300)

* Refactor/code specification (#312)

* refactor: 数据库新增 is_deleted 字段,作为删除标识

* refactor: 整理代码规范

* refactor: 整理代码规范

Co-authored-by: ToWeLong <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: 华钦 <[email protected]>
Co-authored-by: dengliming <[email protected]>
Co-authored-by: fuhao <[email protected]>
Co-authored-by: Gadfly <[email protected]>
  • Loading branch information
7 people authored Nov 29, 2022
1 parent 417a3e4 commit 3fc25bd
Show file tree
Hide file tree
Showing 103 changed files with 533 additions and 202 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

/**
* @author pedro@TaleLin
* 启动入口类
*/
@RestController
@MapperScan(basePackages = {"io.github.talelin.latticy.mapper"})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
* @author pedro@TaleLin
* @author Juzi@TaleLin
* @author colorful@TaleLin
* 分组权限业务对象
*/
@Data
@NoArgsConstructor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
/**
* @author Gadfly
* @since 2021-11-19 15:20
* 登录验证码业务对象
*/
@Data
@NoArgsConstructor
Expand Down
16 changes: 10 additions & 6 deletions src/main/java/io/github/talelin/latticy/common/LocalUser.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,25 @@
import io.github.talelin.latticy.model.UserDO;

/**
* 线程安全的当前登录用户,如果用户为登录,则得到 null
* 线程安全的当前登录用户,如果用户未登录,则得到 null
*
* @author pedro@TaleLin
*/
public class LocalUser {

private static ThreadLocal<UserDO> local = new ThreadLocal<>();
private LocalUser() {
throw new IllegalStateException("Utility class");
}

private static final ThreadLocal<UserDO> LOCAL = new ThreadLocal<>();

/**
* 得到当前登录用户
*
* @return user | null
*/
public static UserDO getLocalUser() {
return LocalUser.local.get();
return LocalUser.LOCAL.get();
}

/**
Expand All @@ -26,17 +30,17 @@ public static UserDO getLocalUser() {
* @param user user
*/
public static void setLocalUser(UserDO user) {
LocalUser.local.set(user);
LocalUser.LOCAL.set(user);
}

public static <T> T getLocalUser(Class<T> clazz) {
return (T) local.get();
return (T) LOCAL.get();
}

/**
* 清理当前用户
*/
public static void clearLocalUser() {
LocalUser.local.remove();
LOCAL.remove();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import org.springframework.util.StringUtils;

/**
* 处理返回结果为 UnifyResponseVO 的 Controller
* 处理返回结果为 UnifyResponseVO 的控制器层方法
* message 默认为 null,在此处通过 code 设置为对应消息
*
* @author pedro@TaleLin
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

/**
* @author pedro@TaleLin
*
* 消息码配置类
*/
@SuppressWarnings("ConfigurationProperties")
@Component
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
/**
* @author pedro@TaleLin
* @author colorful@TaleLin
*
* 公共配置
*/
@Configuration(proxyBeanMethods = false)
public class CommonConfiguration {
Expand All @@ -29,8 +31,6 @@ public RequestLogInterceptor requestLogInterceptor() {

/**
* 新的分页插件,一缓和二缓遵循mybatis的规则
* 需要设置 MybatisConfiguration#useDeprecatedExecutor = false 避免缓存出现问题(该属性会在旧插件移除后一同移除)
* 参考链接:https://mp.baomidou.com/guide/interceptor.html
*/
@Bean
public MybatisPlusInterceptor mybatisPlusInterceptor() {
Expand All @@ -39,9 +39,6 @@ public MybatisPlusInterceptor mybatisPlusInterceptor() {
return interceptor;
}

/**
* 参考链接:https://mp.baomidou.com/guide/interceptor.html
*/
@Bean
@SuppressWarnings("deprecation")
public ConfigurationCustomizer configurationCustomizer() {
Expand Down Expand Up @@ -70,7 +67,6 @@ public PermissionMetaCollector postProcessBeans() {
@Bean
public Jackson2ObjectMapperBuilderCustomizer customJackson() {
return jacksonObjectMapperBuilder -> {
// jacksonObjectMapperBuilder.serializationInclusion(JsonInclude.Include.NON_NULL);
jacksonObjectMapperBuilder.failOnUnknownProperties(false);
jacksonObjectMapperBuilder.propertyNamingStrategy(PropertyNamingStrategies.SNAKE_CASE);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@

/**
* @author Gadfly
*
* A customizing Servlet-specific ModelAttributeMethodProcessor that applies data binding through
* a WebDataBinder of type CustomServletModelAttributeMethodProcessor.
*/

public class CustomServletModelAttributeMethodProcessor extends ServletModelAttributeMethodProcessor {

public CustomServletModelAttributeMethodProcessor(final boolean annotationNotRequired) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

/**
* @author Gadfly
*
* 自定义servlet请求参数绑定类
*/

public class CustomServletRequestDataBinder extends ServletRequestDataBinder {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@

/**
* @author Gadfly
*
* 登录图形验证码配置类
*
*/
@Slf4j
@Getter
Expand All @@ -31,9 +34,12 @@ public class LoginCaptchaProperties {
private Boolean enabled = Boolean.FALSE;

public void setSecret(String secret) {
final long ivLen1 = 16;
final long ivLen2 = 24;
final long ivLen3 = 32;
if (StringUtils.hasText(secret)) {
byte[] bytes = secret.getBytes();
if (bytes.length == 16 || bytes.length == 24 || bytes.length == 32) {
if (bytes.length == ivLen1 || bytes.length == ivLen2 || bytes.length == ivLen3) {
this.secret = secret;
} else {
log.warn("AES密钥必须为128/192/256bit,输入的密钥为{}bit,已启用随机密钥{}", bytes.length * 8, this.secret);
Expand All @@ -42,9 +48,10 @@ public void setSecret(String secret) {
}

public void setIv(String iv) {
final long ivLen = 16;
if (StringUtils.hasText(iv)) {
byte[] bytes = iv.getBytes();
if (bytes.length == 16) {
if (bytes.length == ivLen) {
this.iv = iv;
} else {
log.warn("AES初始向量必须为128bit,输入的密钥为{}bit,已启用随机向量{}", bytes.length * 8, this.iv);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,8 @@ public class IdentityConstant {
*/
public static final String USERNAME_PASSWORD_IDENTITY = "USERNAME_PASSWORD";

private IdentityConstant() {
throw new IllegalStateException("Utility class");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
/**
* @author colorful@TaleLin
* @author Juzi@TaleLin
*
* 分组级别枚举类
*/
public enum GroupLevelEnum implements IEnum<Integer> {
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
* @author pedro@TaleLin
* @author colorful@TaleLin
* @author Juzi@TaleLin
*
* Restful 接口异常配置类
*/
@Order
@RestControllerAdvice
Expand Down Expand Up @@ -76,7 +78,7 @@ public UnifyResponseVO<Map<String, Object>> processException(BindException excep
HttpServletRequest request,
HttpServletResponse response) {
log.error(exception.toString());
Map<String, Object> msg = new HashMap<>();
Map<String, Object> msg = new HashMap<>(3);
exception.getAllErrors().forEach(error -> {
if (error instanceof FieldError) {
FieldError fieldError = (FieldError) error;
Expand All @@ -98,7 +100,7 @@ public UnifyResponseVO<Map<String, Object>> processException(ConstraintViolation
HttpServletRequest request,
HttpServletResponse response) {
log.error("", exception);
Map<String, Object> msg = new HashMap<>();
Map<String, Object> msg = new HashMap<>(3);
exception.getConstraintViolations().forEach(constraintViolation -> {
String template = constraintViolation.getMessage();
String path = constraintViolation.getPropertyPath().toString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

/**
* @author Juzi@TaleLin
* YAML配置预加载
*/
public class YamlPropertySourceFactory implements PropertySourceFactory {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,14 @@
/**
* @author pedro@TaleLin
* @author Juzi@TaleLin
* 鉴权实现类
*/
@Component
public class AuthorizeVerifyResolverImpl implements AuthorizeVerifyResolver {

public final static String AUTHORIZATION_HEADER = "Authorization";
public static final String AUTHORIZATION_HEADER = "Authorization";

public final static String BEARER_PATTERN = "^Bearer$";
public static final String BEARER_PATTERN = "^Bearer$";

@Autowired
private DoubleJWT jwt;
Expand All @@ -58,7 +59,7 @@ public class AuthorizeVerifyResolverImpl implements AuthorizeVerifyResolver {

@Override
public boolean handleLogin(HttpServletRequest request, HttpServletResponse response, MetaInfo meta) {
String tokenStr = verifyHeader(request, response);
String tokenStr = verifyHeader(request);
Map<String, Claim> claims;
try {
claims = jwt.decodeAccessToken(tokenStr);
Expand Down Expand Up @@ -101,7 +102,7 @@ public boolean handleAdmin(HttpServletRequest request, HttpServletResponse respo

@Override
public boolean handleRefresh(HttpServletRequest request, HttpServletResponse response, MetaInfo meta) {
String tokenStr = verifyHeader(request, response);
String tokenStr = verifyHeader(request);
Map<String, Claim> claims;
try {
claims = jwt.decodeRefreshToken(tokenStr);
Expand Down Expand Up @@ -134,9 +135,10 @@ private boolean getClaim(Map<String, Claim> claims) {
throw new NotFoundException(10021);
}
String avatarUrl;
final String protocolPrefix = "http";
if (user.getAvatar() == null) {
avatarUrl = null;
} else if (user.getAvatar().startsWith("http")) {
} else if (user.getAvatar().startsWith(protocolPrefix)) {
avatarUrl = user.getAvatar();
} else {
avatarUrl = domain + servePath.split("/")[0] + "/" + user.getAvatar();
Expand All @@ -155,14 +157,15 @@ private boolean verifyAdmin(UserDO user) {
return groupService.checkIsRootByUserId(user.getId());
}

private String verifyHeader(HttpServletRequest request, HttpServletResponse response) {
private String verifyHeader(HttpServletRequest request) {
// 处理头部header,带有access_token的可以访问
String authorization = request.getHeader(AUTHORIZATION_HEADER);
if (authorization == null || Strings.isBlank(authorization)) {
throw new AuthorizationException(10012);
}
String[] splits = authorization.split(" ");
if (splits.length != 2) {
final int tokenSplitLen = 2;
if (splits.length != tokenSplitLen) {
throw new AuthorizationException(10013);
}
// Bearer 字段
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
Expand All @@ -21,6 +20,7 @@
* @author pedro@TaleLin
* @author Juzi@TaleLin
* @author colorful@TaleLin
* 行为日志实现类
*/
@Slf4j
@Component
Expand All @@ -41,7 +41,7 @@ public void handle(PermissionMeta meta, Logger logger, HttpServletRequest reques
template = this.parseTemplate(template, user, request, response);
String permission = "";
if (meta != null) {
permission = !StringUtils.hasLength(meta.value()) ? meta.value() : meta.value();
permission = meta.value();
}
Integer userId = user.getId();
String username = user.getUsername();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,28 @@
/**
* @author pedro@TaleLin
* @author colorful@TaleLin
* 请求日志拦截器
*/
@Slf4j
public class RequestLogInterceptor implements AsyncHandlerInterceptor {


private ThreadLocal<Long> startTime = new ThreadLocal<>();
private final ThreadLocal<Long> startTime = new ThreadLocal<>();

@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) {
startTime.set(System.currentTimeMillis());
return true;
}

@Override
public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) {
log.info("[{}] -> [{}] from: {} costs: {}ms",
request.getMethod(),
request.getServletPath(),
IPUtil.getIPFromRequest(request),
System.currentTimeMillis() - startTime.get()
);
startTime.remove();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
/**
* @author pedro@TaleLin
* @author colorful@TaleLin
* 权限监听器
*/
@Component
public class PermissionHandleListener implements ApplicationListener<ContextRefreshedEvent> {
Expand Down
Loading

0 comments on commit 3fc25bd

Please sign in to comment.