Skip to content

Commit

Permalink
🎉 4.4.0.RELEASE 新增黑白名单、脱敏工具、BladeRedis新版工具
Browse files Browse the repository at this point in the history
  • Loading branch information
smallchill committed Jan 18, 2025
1 parent 74669ce commit cd04e83
Show file tree
Hide file tree
Showing 18 changed files with 376 additions and 77 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<p align="center">
<img src="https://img.shields.io/badge/Release-V4.3.0-green.svg" alt="Downloads">
<img src="https://img.shields.io/badge/Release-V4.4.0-green.svg" alt="Downloads">
<img src="https://img.shields.io/badge/JDK-17+-green.svg" alt="Build Status">
<img src="https://img.shields.io/badge/license-Apache%202-blue.svg" alt="Build Status">
<img src="https://img.shields.io/badge/Spring%20Cloud-2023-blue.svg" alt="Coverage Status">
Expand Down Expand Up @@ -33,8 +33,8 @@
|----------------------|------------|
| Java | 17+ |
| NodeJS | 18+ |
| Spring | 6.1.14 |
| Spring Boot | 3.2.10 |
| Spring | 6.1.15 |
| Spring Boot | 3.2.12 |
| Spring Cloud | 2023.0.3 |
| Spring Cloud Alibaba | 2023.0.1.2 |
| Nacos Alibaba | 2.3.2 |
Expand Down
4 changes: 4 additions & 0 deletions blade-auth/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@
<groupId>org.springblade</groupId>
<artifactId>blade-starter-social</artifactId>
</dependency>
<dependency>
<groupId>org.springblade</groupId>
<artifactId>blade-starter-redis</artifactId>
</dependency>
<dependency>
<groupId>org.springblade</groupId>
<artifactId>blade-user-api</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@
import org.springblade.auth.granter.TokenParameter;
import org.springblade.auth.utils.TokenUtil;
import org.springblade.common.cache.CacheNames;
import org.springblade.core.redis.cache.BladeRedis;
import org.springblade.core.secure.AuthInfo;
import org.springblade.core.tool.api.R;
import org.springblade.core.tool.support.Kv;
import org.springblade.core.tool.utils.Func;
import org.springblade.core.tool.utils.RedisUtil;
import org.springblade.core.tool.utils.WebUtil;
import org.springblade.system.user.entity.UserInfo;
import org.springframework.web.bind.annotation.GetMapping;
Expand All @@ -50,7 +50,7 @@
@Tag(name = "用户授权认证", description = "授权接口")
public class AuthController {

private RedisUtil redisUtil;
private BladeRedis bladeRedis;

@PostMapping("token")
@Operation(summary = "获取认证token", description = "传入租户ID:tenantId,账号:account,密码:password")
Expand Down Expand Up @@ -87,7 +87,7 @@ public R<Kv> captcha() {
String verCode = specCaptcha.text().toLowerCase();
String key = UUID.randomUUID().toString();
// 存入redis并设置过期时间为30分钟
redisUtil.set(CacheNames.CAPTCHA_KEY + key, verCode, 30L, TimeUnit.MINUTES);
bladeRedis.setEx(CacheNames.CAPTCHA_KEY + key, verCode, 30L, TimeUnit.MINUTES);
// 将key和base64返回给前端
return R.data(Kv.init().set("key", key).set("image", specCaptcha.toBase64()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.springblade.auth.utils.TokenUtil;
import org.springblade.common.cache.CacheNames;
import org.springblade.core.log.exception.ServiceException;
import org.springblade.core.redis.cache.BladeRedis;
import org.springblade.core.secure.props.BladeAuthProperties;
import org.springblade.core.tool.api.R;
import org.springblade.core.tool.utils.*;
Expand All @@ -41,7 +42,7 @@ public class CaptchaTokenGranter implements ITokenGranter {
public static final String GRANT_TYPE = "captcha";

private IUserClient userClient;
private RedisUtil redisUtil;
private BladeRedis bladeRedis;

private BladeAuthProperties authProperties;

Expand All @@ -52,7 +53,7 @@ public UserInfo grant(TokenParameter tokenParameter) {
String key = request.getHeader(TokenUtil.CAPTCHA_HEADER_KEY);
String code = request.getHeader(TokenUtil.CAPTCHA_HEADER_CODE);
// 获取验证码
String redisCode = String.valueOf(redisUtil.get(CacheNames.CAPTCHA_KEY + key));
String redisCode = Func.toStr(bladeRedis.get(CacheNames.CAPTCHA_KEY + key));
// 判断验证码
if (code == null || !StringUtil.equalsIgnoreCase(redisCode, code)) {
throw new ServiceException(TokenUtil.CAPTCHA_NOT_CORRECT);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,29 +17,25 @@


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.v3.oas.annotations.Hidden;
import io.swagger.v3.oas.annotations.Parameter;
import lombok.AllArgsConstructor;
import org.springblade.core.log.model.LogApi;
import org.springblade.core.log.model.LogApiVo;
import org.springblade.core.log.pojo.LogApiVO;
import org.springblade.core.log.service.ILogApiService;
import org.springblade.core.log.wrapper.LogApiWrapper;
import org.springblade.core.mp.support.Condition;
import org.springblade.core.mp.support.Query;
import org.springblade.core.secure.annotation.PreAuth;
import org.springblade.core.tool.api.R;
import org.springblade.core.tool.constant.RoleConstant;
import org.springblade.core.tool.utils.BeanUtil;
import org.springblade.core.tool.utils.Func;
import org.springblade.core.tool.utils.StringPool;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
* 控制器
Expand All @@ -59,27 +55,22 @@ public class LogApiController {
* 查询单条
*/
@GetMapping("/detail")
@PreAuth(RoleConstant.HAS_ROLE_ADMIN)
public R<LogApi> detail(LogApi log) {
return R.data(logService.getOne(Condition.getQueryWrapper(log)));
LogApi logApi = logService.getOne(Condition.getQueryWrapper(log));
return R.data(LogApiWrapper.build().entity(logApi));
}

/**
* 查询多条(分页)
*/
@GetMapping("/list")
@PreAuth(RoleConstant.HAS_ROLE_ADMIN)
public R<IPage<LogApiVo>> list(@Parameter(hidden = true) @RequestParam Map<String, Object> log, Query query) {
public R<IPage<LogApiVO>> list(@Parameter(hidden = true) @RequestParam Map<String, Object> log, Query query) {
query.setAscs("create_time");
query.setDescs(StringPool.EMPTY);
IPage<LogApi> pages = logService.page(Condition.getPage(query), Condition.getQueryWrapper(log, LogApi.class));
List<LogApiVo> records = pages.getRecords().stream().map(logApi -> {
LogApiVo vo = BeanUtil.copyProperties(logApi, LogApiVo.class);
vo.setStrId(Func.toStr(logApi.getId()));
return vo;
}).collect(Collectors.toList());
IPage<LogApiVo> pageVo = new Page<>(pages.getCurrent(), pages.getSize(), pages.getTotal());
pageVo.setRecords(records);
return R.data(pageVo);
return R.data(LogApiWrapper.build().pageVO(pages));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,29 +17,25 @@


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.v3.oas.annotations.Hidden;
import io.swagger.v3.oas.annotations.Parameter;
import lombok.AllArgsConstructor;
import org.springblade.core.log.model.LogError;
import org.springblade.core.log.model.LogErrorVo;
import org.springblade.core.log.pojo.LogErrorVO;
import org.springblade.core.log.service.ILogErrorService;
import org.springblade.core.log.wrapper.LogErrorWrapper;
import org.springblade.core.mp.support.Condition;
import org.springblade.core.mp.support.Query;
import org.springblade.core.secure.annotation.PreAuth;
import org.springblade.core.tool.api.R;
import org.springblade.core.tool.constant.RoleConstant;
import org.springblade.core.tool.utils.BeanUtil;
import org.springblade.core.tool.utils.Func;
import org.springblade.core.tool.utils.StringPool;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
* 控制器
Expand All @@ -59,27 +55,22 @@ public class LogErrorController {
* 查询单条
*/
@GetMapping("/detail")
public R<LogError> detail(LogError logError) {
return R.data(errorLogService.getOne(Condition.getQueryWrapper(logError)));
@PreAuth(RoleConstant.HAS_ROLE_ADMIN)
public R<LogError> detail(LogError log) {
LogError logError = errorLogService.getOne(Condition.getQueryWrapper(log));
return R.data(LogErrorWrapper.build().entity(logError));
}

/**
* 查询多条(分页)
*/
@GetMapping("/list")
@PreAuth(RoleConstant.HAS_ROLE_ADMIN)
public R<IPage<LogErrorVo>> list(@Parameter(hidden = true) @RequestParam Map<String, Object> logError, Query query) {
public R<IPage<LogErrorVO>> list(@Parameter(hidden = true) @RequestParam Map<String, Object> logError, Query query) {
query.setAscs("create_time");
query.setDescs(StringPool.EMPTY);
IPage<LogError> pages = errorLogService.page(Condition.getPage(query), Condition.getQueryWrapper(logError, LogError.class));
List<LogErrorVo> records = pages.getRecords().stream().map(logApi -> {
LogErrorVo vo = BeanUtil.copyProperties(logApi, LogErrorVo.class);
vo.setStrId(Func.toStr(logApi.getId()));
return vo;
}).collect(Collectors.toList());
IPage<LogErrorVo> pageVo = new Page<>(pages.getCurrent(), pages.getSize(), pages.getTotal());
pageVo.setRecords(records);
return R.data(pageVo);
return R.data(LogErrorWrapper.build().pageVO(pages));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,29 +17,25 @@


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.v3.oas.annotations.Hidden;
import io.swagger.v3.oas.annotations.Parameter;
import lombok.AllArgsConstructor;
import org.springblade.core.log.model.LogUsual;
import org.springblade.core.log.model.LogUsualVo;
import org.springblade.core.log.pojo.LogUsualVO;
import org.springblade.core.log.service.ILogUsualService;
import org.springblade.core.log.wrapper.LogUsualWrapper;
import org.springblade.core.mp.support.Condition;
import org.springblade.core.mp.support.Query;
import org.springblade.core.secure.annotation.PreAuth;
import org.springblade.core.tool.api.R;
import org.springblade.core.tool.constant.RoleConstant;
import org.springblade.core.tool.utils.BeanUtil;
import org.springblade.core.tool.utils.Func;
import org.springblade.core.tool.utils.StringPool;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
* 控制器
Expand All @@ -59,27 +55,22 @@ public class LogUsualController {
* 查询单条
*/
@GetMapping("/detail")
@PreAuth(RoleConstant.HAS_ROLE_ADMIN)
public R<LogUsual> detail(LogUsual log) {
return R.data(logService.getOne(Condition.getQueryWrapper(log)));
LogUsual logUsual = logService.getOne(Condition.getQueryWrapper(log));
return R.data(LogUsualWrapper.build().entity(logUsual));
}

/**
* 查询多条(分页)
*/
@GetMapping("/list")
@PreAuth(RoleConstant.HAS_ROLE_ADMIN)
public R<IPage<LogUsualVo>> list(@Parameter(hidden = true) @RequestParam Map<String, Object> log, Query query) {
public R<IPage<LogUsualVO>> list(@Parameter(hidden = true) @RequestParam Map<String, Object> log, Query query) {
query.setAscs("create_time");
query.setDescs(StringPool.EMPTY);
IPage<LogUsual> pages = logService.page(Condition.getPage(query), Condition.getQueryWrapper(log, LogUsual.class));
List<LogUsualVo> records = pages.getRecords().stream().map(logApi -> {
LogUsualVo vo = BeanUtil.copyProperties(logApi, LogUsualVo.class);
vo.setStrId(Func.toStr(logApi.getId()));
return vo;
}).collect(Collectors.toList());
IPage<LogUsualVo> pageVo = new Page<>(pages.getCurrent(), pages.getSize(), pages.getTotal());
pageVo.setRecords(records);
return R.data(pageVo);
return R.data(LogUsualWrapper.build().pageVO(pages));
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/**
* Copyright (c) 2018-2099, Chill Zhuang 庄骞 ([email protected]).
* <p>
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springblade.core.log.pojo;

import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.springblade.core.log.model.LogApi;

import java.io.Serial;

/**
* LogApiVO
*
* @author Chill
*/
@Data
@EqualsAndHashCode(callSuper = true)
public class LogApiVO extends LogApi {

@Serial
private static final long serialVersionUID = 1L;

/**
* 操作提交的数据
*/
@JsonIgnore
private String params;


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/**
* Copyright (c) 2018-2099, Chill Zhuang 庄骞 ([email protected]).
* <p>
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springblade.core.log.pojo;

import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.springblade.core.log.model.LogError;

import java.io.Serial;

/**
* LogErrorVO
*
* @author Chill
*/
@Data
@EqualsAndHashCode(callSuper = true)
public class LogErrorVO extends LogError {

@Serial
private static final long serialVersionUID = 1L;

/**
* 操作提交的数据
*/
@JsonIgnore
private String params;

/**
* 堆栈信息
*/
@JsonIgnore
private String stackTrace;

/**
* 异常消息
*/
@JsonIgnore
private String message;
}
Loading

0 comments on commit cd04e83

Please sign in to comment.