mirror of
https://github.com/1024-lab/smart-admin.git
synced 2026-01-14 06:03:58 +08:00
v3.14.0 更新;【新增】EasyExcel重磅升级为FastExcel;【新增】使用最强Argon2算法作为密码存储;【新增】大家吐槽的数据字典改为可重复;【新增】前端布局再增加多种样式;
This commit is contained in:
@@ -49,6 +49,11 @@
|
||||
</exclusions>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.security</groupId>
|
||||
<artifactId>spring-security-crypto</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- sa-token start -->
|
||||
<dependency>
|
||||
<groupId>cn.dev33</groupId>
|
||||
@@ -172,6 +177,11 @@
|
||||
<artifactId>commons-io</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-compress</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>cn.hutool</groupId>
|
||||
<artifactId>hutool-all</artifactId>
|
||||
@@ -204,12 +214,18 @@
|
||||
|
||||
<dependency>
|
||||
<groupId>org.bouncycastle</groupId>
|
||||
<artifactId>bcprov-jdk15on</artifactId>
|
||||
<artifactId>bcprov-jdk18on</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>easyexcel</artifactId>
|
||||
<groupId>cn.idev.excel</groupId>
|
||||
<artifactId>fastexcel</artifactId>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<artifactId>logback-classic</artifactId>
|
||||
<groupId>ch.qos.logback</groupId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
@@ -268,7 +284,12 @@
|
||||
<artifactId>freemarker</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.tika</groupId>
|
||||
<artifactId>tika-core</artifactId>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
|
||||
</project>
|
||||
</project>
|
||||
|
||||
@@ -11,7 +11,7 @@ package net.lab1024.sa.base.common.constant;
|
||||
*/
|
||||
public class RequestHeaderConst {
|
||||
|
||||
public static final String TOKEN = "x-access-token";
|
||||
public static final String TOKEN = "Authorization";
|
||||
|
||||
public static final String USER_AGENT = "user-agent";
|
||||
|
||||
|
||||
@@ -1,52 +0,0 @@
|
||||
package net.lab1024.sa.base.common.json.serializer;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonGenerator;
|
||||
import com.fasterxml.jackson.databind.JsonSerializer;
|
||||
import com.fasterxml.jackson.databind.SerializerProvider;
|
||||
import com.google.common.collect.Lists;
|
||||
import jakarta.annotation.Resource;
|
||||
import net.lab1024.sa.base.module.support.dict.domain.vo.DictValueVO;
|
||||
import net.lab1024.sa.base.module.support.dict.service.DictCacheService;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 字典序列化
|
||||
*
|
||||
* @Author 1024创新实验室: 罗伊
|
||||
* @Date 2022-08-12 22:17:53
|
||||
* @Wechat zhuoda1024
|
||||
* @Email lab1024@163.com
|
||||
* @Copyright <a href="https://1024lab.net">1024创新实验室</a>
|
||||
*/
|
||||
public class DictValueVoSerializer extends JsonSerializer<String> {
|
||||
|
||||
@Resource
|
||||
private DictCacheService dictCacheService;
|
||||
|
||||
|
||||
@Override
|
||||
public void serialize(String value, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException {
|
||||
if (StringUtils.isEmpty(value)) {
|
||||
jsonGenerator.writeObject(Lists.newArrayList());
|
||||
return;
|
||||
}
|
||||
|
||||
String[] valueCodeArray = value.split(",");
|
||||
List<String> valueCodeList = Arrays.asList(valueCodeArray);
|
||||
List<DictValueVO> dictValueVOList = Lists.newArrayList();
|
||||
valueCodeList.forEach(e->{
|
||||
if(StringUtils.isNotBlank(e)){
|
||||
DictValueVO dictValueVO = dictCacheService.selectValueByValueCode(e);
|
||||
if(dictValueVO != null){
|
||||
dictValueVOList.add(dictValueVO);
|
||||
}
|
||||
}
|
||||
});
|
||||
jsonGenerator.writeObject(dictValueVOList);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,9 @@
|
||||
package net.lab1024.sa.base.common.util;
|
||||
|
||||
import com.alibaba.excel.EasyExcel;
|
||||
import com.alibaba.excel.write.handler.SheetWriteHandler;
|
||||
import com.alibaba.excel.write.metadata.holder.WriteSheetHolder;
|
||||
import com.alibaba.excel.write.metadata.holder.WriteWorkbookHolder;
|
||||
import cn.idev.excel.FastExcel;
|
||||
import cn.idev.excel.write.handler.SheetWriteHandler;
|
||||
import cn.idev.excel.write.metadata.holder.WriteSheetHolder;
|
||||
import cn.idev.excel.write.metadata.holder.WriteWorkbookHolder;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import lombok.Data;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
@@ -43,7 +43,7 @@ public final class SmartExcelUtil {
|
||||
// 设置下载消息头
|
||||
SmartResponseUtil.setDownloadFileHeader(response, fileName, null);
|
||||
// 下载
|
||||
EasyExcel.write(response.getOutputStream(), head)
|
||||
FastExcel.write(response.getOutputStream(), head)
|
||||
.autoCloseStream(Boolean.FALSE)
|
||||
.sheet(sheetName)
|
||||
.doWrite(data);
|
||||
@@ -58,7 +58,7 @@ public final class SmartExcelUtil {
|
||||
// 水印
|
||||
Watermark watermark = new Watermark(watermarkString);
|
||||
// 一定要inMemory
|
||||
EasyExcel.write(response.getOutputStream(), head)
|
||||
FastExcel.write(response.getOutputStream(), head)
|
||||
.inMemory(true)
|
||||
.sheet(sheetName)
|
||||
.registerWriteHandler(new CustomWaterMarkHandler(watermark))
|
||||
|
||||
@@ -9,8 +9,10 @@ import org.springframework.http.MediaType;
|
||||
import org.springframework.http.MediaTypeFactory;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.URLEncoder;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
import static cn.hutool.core.util.CharsetUtil.UTF_8;
|
||||
|
||||
/**
|
||||
* 返回工具栏
|
||||
@@ -27,8 +29,8 @@ public class SmartResponseUtil {
|
||||
|
||||
public static void write(HttpServletResponse response, ResponseDTO<?> responseDTO) {
|
||||
// 重置response
|
||||
response.setContentType("application/json");
|
||||
response.setCharacterEncoding("utf-8");
|
||||
response.setContentType(MediaType.APPLICATION_JSON_VALUE);
|
||||
response.setCharacterEncoding(UTF_8);
|
||||
|
||||
try {
|
||||
response.getWriter().write(JSON.toJSONString(responseDTO));
|
||||
@@ -44,20 +46,15 @@ public class SmartResponseUtil {
|
||||
}
|
||||
|
||||
public static void setDownloadFileHeader(HttpServletResponse response, String fileName, Long fileSize) {
|
||||
response.setCharacterEncoding("utf-8");
|
||||
try {
|
||||
if (fileSize != null) {
|
||||
response.setHeader(HttpHeaders.CONTENT_LENGTH, String.valueOf(fileSize));
|
||||
}
|
||||
response.setCharacterEncoding(UTF_8);
|
||||
if (fileSize != null) {
|
||||
response.setHeader(HttpHeaders.CONTENT_LENGTH, String.valueOf(fileSize));
|
||||
}
|
||||
|
||||
if (SmartStringUtil.isNotEmpty(fileName)) {
|
||||
response.setHeader(HttpHeaders.CONTENT_TYPE, MediaTypeFactory.getMediaType(fileName).orElse(MediaType.APPLICATION_OCTET_STREAM) + ";charset=utf-8");
|
||||
response.setHeader(HttpHeaders.CONTENT_DISPOSITION, "attachment;filename=" + URLEncoder.encode(fileName, "UTF-8").replaceAll("\\+", "%20"));
|
||||
response.setHeader(HttpHeaders.ACCESS_CONTROL_EXPOSE_HEADERS, HttpHeaders.CONTENT_DISPOSITION);
|
||||
}
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
log.error(e.getMessage(), e);
|
||||
throw new RuntimeException(e);
|
||||
if (SmartStringUtil.isNotEmpty(fileName)) {
|
||||
response.setHeader(HttpHeaders.CONTENT_TYPE, MediaTypeFactory.getMediaType(fileName).orElse(MediaType.APPLICATION_OCTET_STREAM) + ";charset=utf-8");
|
||||
response.setHeader(HttpHeaders.CONTENT_DISPOSITION, "attachment;filename=" + URLEncoder.encode(fileName, StandardCharsets.UTF_8).replaceAll("\\+", "%20"));
|
||||
response.setHeader(HttpHeaders.ACCESS_CONTROL_EXPOSE_HEADERS, HttpHeaders.CONTENT_DISPOSITION);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -77,7 +77,7 @@ public class SwaggerConfig {
|
||||
|
||||
private Components components() {
|
||||
return new Components()
|
||||
.addSecuritySchemes(RequestHeaderConst.TOKEN, new SecurityScheme().type(SecurityScheme.Type.APIKEY).in(SecurityScheme.In.HEADER).name(RequestHeaderConst.TOKEN));
|
||||
.addSecuritySchemes(RequestHeaderConst.TOKEN, new SecurityScheme().scheme("Bearer").description("请输入token,格式为[Bearer xxxxxxxx]").type(SecurityScheme.Type.APIKEY).in(SecurityScheme.In.HEADER).name(RequestHeaderConst.TOKEN));
|
||||
}
|
||||
|
||||
@Bean
|
||||
|
||||
@@ -18,5 +18,5 @@ import java.lang.annotation.Target;
|
||||
@Target(ElementType.FIELD)
|
||||
public @interface DataTracerFieldDict {
|
||||
|
||||
|
||||
String keyCode() default "";
|
||||
}
|
||||
|
||||
@@ -303,7 +303,7 @@ public class DataTracerChangeContentService {
|
||||
fieldContent = SmartEnumUtil.getEnumDescByValue(fieldValue, dataTracerFieldEnum.enumClass());
|
||||
}
|
||||
} else if (dataTracerFieldDict != null) {
|
||||
fieldContent = dictCacheService.selectValueNameByValueCodeSplit(fieldValue.toString());
|
||||
fieldContent = dictCacheService.selectValueNameByValueCodeSplit(dataTracerFieldDict.keyCode(), fieldValue.toString());
|
||||
} else if (dataTracerFieldSql != null) {
|
||||
fieldContent = this.getRelateDisplayValue(fieldValue, dataTracerFieldSql);
|
||||
} else if (fieldValue instanceof Date) {
|
||||
|
||||
@@ -52,5 +52,5 @@ public interface DictValueDao extends BaseMapper<DictValueEntity> {
|
||||
* 跟进code查询
|
||||
*
|
||||
*/
|
||||
DictValueEntity selectByCode(@Param("valueCode") String valueCode, @Param("deletedFlag") Boolean deletedFlag);
|
||||
DictValueEntity selectByCode(@Param("dictKeyId") Long dictKeyId,@Param("valueCode") String valueCode, @Param("deletedFlag") Boolean deletedFlag);
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@ import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@@ -41,8 +42,6 @@ public class DictCacheService {
|
||||
|
||||
private ConcurrentHashMap<String, List<DictValueVO>> DICT_CACHE = new ConcurrentHashMap<>();
|
||||
|
||||
private ConcurrentHashMap<String, DictValueVO> VALUE_CACHE = new ConcurrentHashMap<>();
|
||||
|
||||
|
||||
@PostConstruct
|
||||
public void dictCache() {
|
||||
@@ -63,10 +62,6 @@ public class DictCacheService {
|
||||
Long dictKeyId = dictKeyEntity.getDictKeyId();
|
||||
DICT_CACHE.put(keyCode, valueListMap.getOrDefault(dictKeyId, Lists.newArrayList()));
|
||||
}
|
||||
//字典值缓存
|
||||
dictValueVOList.forEach(e -> {
|
||||
VALUE_CACHE.put(e.getValueCode(), e);
|
||||
});
|
||||
log.info("################# 数据字典缓存初始化完毕 ###################");
|
||||
}
|
||||
|
||||
@@ -75,7 +70,6 @@ public class DictCacheService {
|
||||
*/
|
||||
public ResponseDTO<String> cacheRefresh() {
|
||||
DICT_CACHE.clear();
|
||||
VALUE_CACHE.clear();
|
||||
this.cacheInit();
|
||||
return ResponseDTO.ok();
|
||||
}
|
||||
@@ -92,37 +86,45 @@ public class DictCacheService {
|
||||
|
||||
/**
|
||||
* 查询值code名称
|
||||
*
|
||||
* @param keyCode
|
||||
* @param valueCode
|
||||
* @return
|
||||
*/
|
||||
public String selectValueNameByValueCode(String valueCode) {
|
||||
if (StrUtil.isEmpty(valueCode)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
DictValueVO dictValueVO = VALUE_CACHE.get(valueCode);
|
||||
if (dictValueVO == null) {
|
||||
public String selectValueNameByValueCode(String keyCode, String valueCode) {
|
||||
DictValueVO dictValueVO = this.selectValueByValueCode(keyCode, valueCode);
|
||||
if (dictValueVO == null){
|
||||
return "";
|
||||
}
|
||||
return dictValueVO.getValueName();
|
||||
return dictValueVO.getValueName()
|
||||
;
|
||||
}
|
||||
|
||||
public DictValueVO selectValueByValueCode(String valueCode) {
|
||||
public DictValueVO selectValueByValueCode(String keyCode, String valueCode) {
|
||||
if (StrUtil.isEmpty(valueCode)) {
|
||||
return null;
|
||||
}
|
||||
return VALUE_CACHE.get(valueCode);
|
||||
}
|
||||
if (StrUtil.isEmpty(keyCode)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
public String selectValueNameByValueCodeSplit(String valueCodes) {
|
||||
List<DictValueVO> dictValueVOList = DICT_CACHE.get(valueCode);
|
||||
if (CollectionUtils.isEmpty(dictValueVOList)) {
|
||||
return null;
|
||||
}
|
||||
Optional<DictValueVO> option = dictValueVOList.stream().filter(e->e.getValueCode().equals(valueCode)).findFirst();
|
||||
if(option.isPresent()){
|
||||
return option.get();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
public String selectValueNameByValueCodeSplit(String keyCode, String valueCodes) {
|
||||
if (StrUtil.isEmpty(valueCodes)) {
|
||||
return "";
|
||||
}
|
||||
List<String> valueNameList = Lists.newArrayList();
|
||||
String[] valueCodeArray = valueCodes.split(",");
|
||||
for (String valueCode : valueCodeArray) {
|
||||
DictValueVO dictValueVO = VALUE_CACHE.get(valueCode);
|
||||
DictValueVO dictValueVO = this.selectValueByValueCode(keyCode, valueCode);
|
||||
if (dictValueVO != null) {
|
||||
valueNameList.add(dictValueVO.getValueName());
|
||||
}
|
||||
@@ -130,4 +132,4 @@ public class DictCacheService {
|
||||
return StringUtils.join(valueNameList, ",");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -66,7 +66,7 @@ public class DictService {
|
||||
* @return
|
||||
*/
|
||||
public synchronized ResponseDTO<String> valueAdd(DictValueAddForm valueAddForm) {
|
||||
DictValueEntity dictValueEntity = dictValueDao.selectByCode(valueAddForm.getValueCode(), false);
|
||||
DictValueEntity dictValueEntity = dictValueDao.selectByCode(valueAddForm.getDictKeyId(),valueAddForm.getValueCode(), false);
|
||||
if (dictValueEntity != null) {
|
||||
return ResponseDTO.error(UserErrorCode.ALREADY_EXIST);
|
||||
}
|
||||
@@ -106,7 +106,7 @@ public class DictService {
|
||||
if (dictKeyEntity == null || dictKeyEntity.getDeletedFlag()) {
|
||||
return ResponseDTO.userErrorParam("key不能存在");
|
||||
}
|
||||
DictValueEntity dictValueEntity = dictValueDao.selectByCode(valueUpdateForm.getValueCode(), false);
|
||||
DictValueEntity dictValueEntity = dictValueDao.selectByCode(valueUpdateForm.getDictKeyId(),valueUpdateForm.getValueCode(), false);
|
||||
if (dictValueEntity != null && !dictValueEntity.getDictValueId().equals(valueUpdateForm.getDictValueId())) {
|
||||
return ResponseDTO.error(UserErrorCode.ALREADY_EXIST);
|
||||
}
|
||||
|
||||
@@ -161,6 +161,10 @@ public class Level3ProtectConfigService {
|
||||
this.maxUploadFileSizeMb = configForm.getMaxUploadFileSizeMb();
|
||||
}
|
||||
|
||||
if (configForm.getLoginFailMaxTimes() != null) {
|
||||
this.loginFailMaxTimes = configForm.getLoginFailMaxTimes();
|
||||
}
|
||||
|
||||
if (configForm.getLoginFailLockMinutes() != null) {
|
||||
this.loginFailLockSeconds = configForm.getLoginFailLockMinutes() * 60;
|
||||
}
|
||||
|
||||
@@ -1,14 +1,24 @@
|
||||
package net.lab1024.sa.base.module.support.securityprotect.service;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import jakarta.annotation.Resource;
|
||||
import net.lab1024.sa.base.common.domain.ResponseDTO;
|
||||
import org.apache.tika.config.TikaConfig;
|
||||
import org.apache.tika.exception.TikaException;
|
||||
import org.apache.tika.io.TikaInputStream;
|
||||
import org.apache.tika.metadata.Metadata;
|
||||
import org.apache.tika.metadata.TikaCoreProperties;
|
||||
import org.apache.tika.mime.MediaType;
|
||||
import org.apache.tika.mime.MimeTypes;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 三级等保 文件上传 相关
|
||||
* 三级等保 文件 相关
|
||||
*
|
||||
* @Author 1024创新实验室-主任:卓大
|
||||
* @Date 2024/08/22 19:25:59
|
||||
@@ -18,11 +28,34 @@ import java.io.File;
|
||||
*/
|
||||
|
||||
@Service
|
||||
@Slf4j
|
||||
public class SecurityFileService {
|
||||
|
||||
@Resource
|
||||
private Level3ProtectConfigService level3ProtectConfigService;
|
||||
|
||||
// 定义白名单MIME类型
|
||||
private static final List<String> ALLOWED_MIME_TYPES = Arrays.asList(
|
||||
"application/json",
|
||||
"application/zip",
|
||||
"application/x-7z-compressed",
|
||||
"application/pdf",
|
||||
"application/vnd.ms-excel",
|
||||
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
|
||||
"application/vnd.ms-powerpoint",
|
||||
"application/vnd.openxmlformats-officedocument.presentationml.presentation",
|
||||
"application/msword",
|
||||
"application/vnd.openxmlformats-officedocument.wordprocessingml.document",
|
||||
"application/vnd.ms-works",
|
||||
"text/csv",
|
||||
"audio/*",
|
||||
"video/*",
|
||||
// 图片类型 svg有安全隐患,所以不使用"image/*"
|
||||
"image/jpeg",
|
||||
"image/png",
|
||||
"image/gif",
|
||||
"image/bmp"
|
||||
);
|
||||
|
||||
/**
|
||||
* 检测文件安全类型
|
||||
@@ -38,15 +71,51 @@ public class SecurityFileService {
|
||||
}
|
||||
|
||||
// 文件类型安全检测
|
||||
if (!level3ProtectConfigService.isFileDetectFlag()) {
|
||||
return ResponseDTO.ok();
|
||||
if (level3ProtectConfigService.isFileDetectFlag()) {
|
||||
String fileType = getFileMimeType(file);
|
||||
if(ALLOWED_MIME_TYPES.stream()
|
||||
.noneMatch(allowedType -> matchesMimeType(fileType, allowedType))){
|
||||
return ResponseDTO.userErrorParam("禁止上传此文件类型");
|
||||
}
|
||||
}
|
||||
|
||||
// 检测文件类型
|
||||
// .....
|
||||
|
||||
return ResponseDTO.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取文件的 MIME 类型
|
||||
*
|
||||
* @param file 要检查的文件
|
||||
* @return 文件的 MIME 类型
|
||||
*
|
||||
*/
|
||||
public static String getFileMimeType(MultipartFile file) {
|
||||
try {
|
||||
TikaConfig tika = new TikaConfig();
|
||||
Metadata metadata = new Metadata();
|
||||
metadata.set(TikaCoreProperties.RESOURCE_NAME_KEY, file.getOriginalFilename());
|
||||
TikaInputStream stream = TikaInputStream.get(file.getInputStream());
|
||||
MediaType mimetype = tika.getDetector().detect(stream, metadata);
|
||||
return mimetype.toString();
|
||||
} catch (IOException | TikaException e) {
|
||||
log.error(e.getMessage(), e);
|
||||
return MimeTypes.OCTET_STREAM;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查文件的 MIME 类型是否与指定的MIME 类型匹配(支持通配符)
|
||||
*
|
||||
* @param fileType 文件的 MIME 类型
|
||||
* @param mimetype MIME 类型(支持通配符)
|
||||
* @return 是否匹配
|
||||
*/
|
||||
private static boolean matchesMimeType(String fileType, String mimetype) {
|
||||
if (mimetype.endsWith("/*")) {
|
||||
String prefix = mimetype.substring(0, mimetype.length() - 1);
|
||||
return fileType.startsWith(prefix);
|
||||
} else {
|
||||
return fileType.equalsIgnoreCase(mimetype);
|
||||
}
|
||||
}
|
||||
}
|
||||
;
|
||||
@@ -8,6 +8,7 @@ import net.lab1024.sa.base.module.support.securityprotect.dao.PasswordLogDao;
|
||||
import net.lab1024.sa.base.module.support.securityprotect.domain.PasswordLogEntity;
|
||||
import org.apache.commons.codec.digest.DigestUtils;
|
||||
import org.apache.commons.lang3.RandomStringUtils;
|
||||
import org.springframework.security.crypto.argon2.Argon2PasswordEncoder;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
@@ -34,10 +35,8 @@ public class SecurityPasswordService {
|
||||
|
||||
public static final String PASSWORD_FORMAT_MSG = "密码必须为长度8-20位且必须包含大小写字母、数字、特殊符号(如:@#$%^&*()_+-=)等三种字符";
|
||||
|
||||
|
||||
private static final int PASSWORD_LENGTH = 8;
|
||||
|
||||
private static final String PASSWORD_SALT_FORMAT = "smart_%s_admin_$^&*";
|
||||
|
||||
|
||||
@Resource
|
||||
@@ -46,6 +45,8 @@ public class SecurityPasswordService {
|
||||
@Resource
|
||||
private Level3ProtectConfigService level3ProtectConfigService;
|
||||
|
||||
static Argon2PasswordEncoder ARGON2_PASSWORD_ENCODER = Argon2PasswordEncoder.defaultsForSpringSecurity_v5_8();
|
||||
|
||||
/**
|
||||
* 校验密码复杂度
|
||||
*/
|
||||
@@ -84,8 +85,9 @@ public class SecurityPasswordService {
|
||||
|
||||
// 检查最近几次是否有重复密码
|
||||
List<String> oldPasswords = passwordLogDao.selectOldPassword(requestUser.getUserType().getValue(), requestUser.getUserId(), level3ProtectConfigService.getRegularChangePasswordNotAllowRepeatTimes());
|
||||
if (oldPasswords != null && oldPasswords.contains(getEncryptPwd(newPassword))) {
|
||||
return ResponseDTO.userErrorParam(String.format("与前%s个历史密码重复,请换个密码!", level3ProtectConfigService.getRegularChangePasswordNotAllowRepeatTimes()));
|
||||
boolean isDuplicate = oldPasswords.stream().anyMatch(oldPassword -> ARGON2_PASSWORD_ENCODER.matches(newPassword, oldPassword));
|
||||
if (isDuplicate) {
|
||||
return ResponseDTO.userErrorParam(String.format("与前%d个历史密码重复,请换个密码!", level3ProtectConfigService.getRegularChangePasswordNotAllowRepeatTimes()));
|
||||
}
|
||||
|
||||
return ResponseDTO.ok();
|
||||
@@ -143,7 +145,14 @@ public class SecurityPasswordService {
|
||||
* 获取 加密后 的密码
|
||||
*/
|
||||
public static String getEncryptPwd(String password) {
|
||||
return DigestUtils.md5Hex(String.format(PASSWORD_SALT_FORMAT, password));
|
||||
return ARGON2_PASSWORD_ENCODER.encode(password);
|
||||
}
|
||||
|
||||
/**
|
||||
* 校验密码是否匹配
|
||||
*/
|
||||
public static Boolean matchesPwd( String password, String encodedPassword){
|
||||
return ARGON2_PASSWORD_ENCODER.matches( password, encodedPassword);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -37,14 +37,14 @@ public interface ${name.upperCamel}Dao extends BaseMapper<${name.upperCamel}Enti
|
||||
/**
|
||||
* 更新删除状态
|
||||
*/
|
||||
long updateDeleted(@Param("${primaryKeyFieldName}")${primaryKeyJavaType} ${primaryKeyFieldName},@Param("deletedFlag")boolean deletedFlag);
|
||||
long updateDeleted(@Param("${primaryKeyFieldName}") ${primaryKeyJavaType} ${primaryKeyFieldName}, @Param("deletedFlag") boolean deletedFlag);
|
||||
|
||||
#end
|
||||
#if($deleteInfo.deleteEnum == "Batch" || $deleteInfo.deleteEnum == "SingleAndBatch")
|
||||
/**
|
||||
* 批量更新删除状态
|
||||
*/
|
||||
void batchUpdateDeleted(@Param("idList")List<${primaryKeyJavaType}> idList,@Param("deletedFlag")boolean deletedFlag);
|
||||
void batchUpdateDeleted(@Param("idList") List<${primaryKeyJavaType}> idList, @Param("deletedFlag") boolean deletedFlag);
|
||||
|
||||
#end
|
||||
#end
|
||||
|
||||
@@ -10,13 +10,13 @@ SET @parent_id = NULL;
|
||||
SELECT t_menu.menu_id INTO @parent_id FROM t_menu WHERE t_menu.menu_name = '${basic.description}';
|
||||
|
||||
INSERT INTO t_menu ( menu_name, menu_type, parent_id, frame_flag, cache_flag, visible_flag, disabled_flag, api_perms, perms_type, context_menu_id, create_user_id )
|
||||
VALUES ( '查询', 3, @parent_id, false, true, true, false, '${name.lowerCamel}:query', 1, @parent_id, 1 );
|
||||
VALUES ( '查询', 3, @parent_id, false, false, true, false, '${name.lowerCamel}:query', 1, @parent_id, 1 );
|
||||
|
||||
INSERT INTO t_menu ( menu_name, menu_type, parent_id, frame_flag, cache_flag, visible_flag, disabled_flag, api_perms, perms_type, context_menu_id, create_user_id )
|
||||
VALUES ( '添加', 3, @parent_id, false, true, true, false, '${name.lowerCamel}:add', 1, @parent_id, 1 );
|
||||
VALUES ( '添加', 3, @parent_id, false, false, true, false, '${name.lowerCamel}:add', 1, @parent_id, 1 );
|
||||
|
||||
INSERT INTO t_menu ( menu_name, menu_type, parent_id, frame_flag, cache_flag, visible_flag, disabled_flag, api_perms, perms_type, context_menu_id, create_user_id )
|
||||
VALUES ( '更新', 3, @parent_id, false, true, true, false, '${name.lowerCamel}:update', 1, @parent_id, 1 );
|
||||
VALUES ( '更新', 3, @parent_id, false, false, true, false, '${name.lowerCamel}:update', 1, @parent_id, 1 );
|
||||
|
||||
INSERT INTO t_menu ( menu_name, menu_type, parent_id, frame_flag, cache_flag, visible_flag, disabled_flag, api_perms, perms_type, context_menu_id, create_user_id )
|
||||
VALUES ( '删除', 3, @parent_id, false, true, true, false, '${name.lowerCamel}:delete', 1, @parent_id, 1 );
|
||||
VALUES ( '删除', 3, @parent_id, false, false, true, false, '${name.lowerCamel}:delete', 1, @parent_id, 1 );
|
||||
|
||||
@@ -132,7 +132,9 @@ reload:
|
||||
# sa-token 配置
|
||||
sa-token:
|
||||
# token 名称(同时也是 cookie 名称)
|
||||
token-name: x-access-token
|
||||
token-name: Authorization
|
||||
# token 前缀 例如:Bearer
|
||||
token-prefix: Bearer
|
||||
# token 有效期(单位:秒) 默认30天(2592000秒),-1 代表永久有效
|
||||
timeout: 2592000
|
||||
# token 最低活跃频率(单位:秒),如果 token 超过此时间没有访问系统就会被冻结,默认-1 代表不限制,永不冻结
|
||||
|
||||
@@ -29,7 +29,7 @@
|
||||
|
||||
<select id="selectByCode"
|
||||
resultType="net.lab1024.sa.base.module.support.dict.domain.entity.DictValueEntity">
|
||||
select * from t_dict_value where value_code = #{valueCode} and deleted_flag = #{deletedFlag}
|
||||
select * from t_dict_value where dict_Key_id = #{dictKeyId} and value_code = #{valueCode} and deleted_flag = #{deletedFlag}
|
||||
</select>
|
||||
|
||||
<select id="selectByDeletedFlag"
|
||||
|
||||
@@ -132,7 +132,9 @@ reload:
|
||||
# sa-token 配置
|
||||
sa-token:
|
||||
# token 名称(同时也是 cookie 名称)
|
||||
token-name: x-access-token
|
||||
token-name: Authorization
|
||||
# token 前缀 例如:Bear
|
||||
token-prefix: Bearer
|
||||
# token 有效期(单位:秒) 默认30天(2592000秒),-1 代表永久有效
|
||||
timeout: 2592000
|
||||
# token 最低活跃频率(单位:秒),如果 token 超过此时间没有访问系统就会被冻结,默认-1 代表不限制,永不冻结
|
||||
|
||||
@@ -129,7 +129,9 @@ reload:
|
||||
# sa-token 配置
|
||||
sa-token:
|
||||
# token 名称(同时也是 cookie 名称)
|
||||
token-name: x-access-token
|
||||
token-name: Authorization
|
||||
# token 前缀 例如:Bear
|
||||
token-prefix: Bearer
|
||||
# token 有效期(单位:秒) 默认30天(2592000秒),-1 代表永久有效
|
||||
timeout: 2592000
|
||||
# token 最低活跃频率(单位:秒),如果 token 超过此时间没有访问系统就会被冻结,默认-1 代表不限制,永不冻结
|
||||
|
||||
@@ -132,7 +132,9 @@ reload:
|
||||
# sa-token 配置
|
||||
sa-token:
|
||||
# token 名称(同时也是 cookie 名称)
|
||||
token-name: x-access-token
|
||||
token-name: Authorization
|
||||
# token 前缀 例如:Bear
|
||||
token-prefix: Bearer
|
||||
# token 有效期(单位:秒) 默认30天(2592000秒),-1 代表永久有效
|
||||
timeout: 2592000
|
||||
# token 最低活跃频率(单位:秒),如果 token 超过此时间没有访问系统就会被冻结,默认-1 代表不限制,永不冻结
|
||||
|
||||
Reference in New Issue
Block a user