mirror of
https://gitee.com/dromara/RuoYi-Vue-Plus.git
synced 2026-09-21 02:25:56 +08:00
Pre Merge pull request !310 from 杨不易呀/4.X
This commit is contained in:
commit
6c3318e7f4
@ -19,9 +19,6 @@ import org.springframework.context.annotation.Configuration;
|
|||||||
@ConditionalOnProperty(value = "mybatis-encryptor.enable", havingValue = "true")
|
@ConditionalOnProperty(value = "mybatis-encryptor.enable", havingValue = "true")
|
||||||
public class EncryptorConfig {
|
public class EncryptorConfig {
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private EncryptorProperties properties;
|
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
public EncryptorManager encryptorManager() {
|
public EncryptorManager encryptorManager() {
|
||||||
return new EncryptorManager();
|
return new EncryptorManager();
|
||||||
@ -29,11 +26,11 @@ public class EncryptorConfig {
|
|||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
public MybatisEncryptInterceptor mybatisEncryptInterceptor(EncryptorManager encryptorManager) {
|
public MybatisEncryptInterceptor mybatisEncryptInterceptor(EncryptorManager encryptorManager) {
|
||||||
return new MybatisEncryptInterceptor(encryptorManager, properties);
|
return new MybatisEncryptInterceptor(encryptorManager);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
public MybatisDecryptInterceptor mybatisDecryptInterceptor(EncryptorManager encryptorManager) {
|
public MybatisDecryptInterceptor mybatisDecryptInterceptor(EncryptorManager encryptorManager) {
|
||||||
return new MybatisDecryptInterceptor(encryptorManager, properties);
|
return new MybatisDecryptInterceptor(encryptorManager);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -0,0 +1,38 @@
|
|||||||
|
package com.ruoyi.framework.encrypt;
|
||||||
|
|
||||||
|
import cn.hutool.extra.spring.SpringUtil;
|
||||||
|
import com.ruoyi.common.annotation.EncryptField;
|
||||||
|
import com.ruoyi.common.encrypt.EncryptContext;
|
||||||
|
import com.ruoyi.common.enums.AlgorithmType;
|
||||||
|
import com.ruoyi.common.enums.EncodeType;
|
||||||
|
import com.ruoyi.common.utils.StringUtils;
|
||||||
|
import com.ruoyi.framework.config.properties.EncryptorProperties;
|
||||||
|
|
||||||
|
import java.lang.reflect.Field;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 构建加解密
|
||||||
|
* @author Yang Shuai
|
||||||
|
* {@code @create} 2023/3/24:15:50
|
||||||
|
* {@code @desc} |
|
||||||
|
**/
|
||||||
|
public class EncryptContextBuild {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 构建
|
||||||
|
*
|
||||||
|
* @param field 字段
|
||||||
|
* @return {@link EncryptContext}
|
||||||
|
*/
|
||||||
|
public static EncryptContext build(Field field) {
|
||||||
|
EncryptorProperties defaultProperties = SpringUtil.getBean(EncryptorProperties.class);
|
||||||
|
EncryptField encryptField = field.getAnnotation(EncryptField.class);
|
||||||
|
EncryptContext encryptContext = new EncryptContext();
|
||||||
|
encryptContext.setAlgorithm(encryptField.algorithm() == AlgorithmType.DEFAULT ? defaultProperties.getAlgorithm() : encryptField.algorithm());
|
||||||
|
encryptContext.setEncode(encryptField.encode() == EncodeType.DEFAULT ? defaultProperties.getEncode() : encryptField.encode());
|
||||||
|
encryptContext.setPassword(StringUtils.isBlank(encryptField.password()) ? defaultProperties.getPassword() : encryptField.password());
|
||||||
|
encryptContext.setPrivateKey(StringUtils.isBlank(encryptField.privateKey()) ? defaultProperties.getPrivateKey() : encryptField.privateKey());
|
||||||
|
encryptContext.setPublicKey(StringUtils.isBlank(encryptField.publicKey()) ? defaultProperties.getPublicKey() : encryptField.publicKey());
|
||||||
|
return encryptContext;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -2,12 +2,6 @@ package com.ruoyi.framework.encrypt;
|
|||||||
|
|
||||||
import cn.hutool.core.collection.CollectionUtil;
|
import cn.hutool.core.collection.CollectionUtil;
|
||||||
import cn.hutool.core.util.ObjectUtil;
|
import cn.hutool.core.util.ObjectUtil;
|
||||||
import com.ruoyi.common.annotation.EncryptField;
|
|
||||||
import com.ruoyi.common.encrypt.EncryptContext;
|
|
||||||
import com.ruoyi.common.enums.AlgorithmType;
|
|
||||||
import com.ruoyi.common.enums.EncodeType;
|
|
||||||
import com.ruoyi.common.utils.StringUtils;
|
|
||||||
import com.ruoyi.framework.config.properties.EncryptorProperties;
|
|
||||||
import com.ruoyi.framework.manager.EncryptorManager;
|
import com.ruoyi.framework.manager.EncryptorManager;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
@ -34,7 +28,7 @@ import java.util.*;
|
|||||||
public class MybatisDecryptInterceptor implements Interceptor {
|
public class MybatisDecryptInterceptor implements Interceptor {
|
||||||
|
|
||||||
private final EncryptorManager encryptorManager;
|
private final EncryptorManager encryptorManager;
|
||||||
private final EncryptorProperties defaultProperties;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object intercept(Invocation invocation) throws Throwable {
|
public Object intercept(Invocation invocation) throws Throwable {
|
||||||
@ -91,14 +85,7 @@ public class MybatisDecryptInterceptor implements Interceptor {
|
|||||||
* @return 加密后结果
|
* @return 加密后结果
|
||||||
*/
|
*/
|
||||||
private String decryptField(String value, Field field) {
|
private String decryptField(String value, Field field) {
|
||||||
EncryptField encryptField = field.getAnnotation(EncryptField.class);
|
return this.encryptorManager.decrypt(value, EncryptContextBuild.build(field));
|
||||||
EncryptContext encryptContext = new EncryptContext();
|
|
||||||
encryptContext.setAlgorithm(encryptField.algorithm() == AlgorithmType.DEFAULT ? defaultProperties.getAlgorithm() : encryptField.algorithm());
|
|
||||||
encryptContext.setEncode(encryptField.encode() == EncodeType.DEFAULT ? defaultProperties.getEncode() : encryptField.encode());
|
|
||||||
encryptContext.setPassword(StringUtils.isBlank(encryptField.password()) ? defaultProperties.getPassword() : encryptField.password());
|
|
||||||
encryptContext.setPrivateKey(StringUtils.isBlank(encryptField.privateKey()) ? defaultProperties.getPrivateKey() : encryptField.privateKey());
|
|
||||||
encryptContext.setPublicKey(StringUtils.isBlank(encryptField.publicKey()) ? defaultProperties.getPublicKey() : encryptField.publicKey());
|
|
||||||
return this.encryptorManager.decrypt(value, encryptContext);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@ -37,7 +37,6 @@ import java.util.*;
|
|||||||
public class MybatisEncryptInterceptor implements Interceptor {
|
public class MybatisEncryptInterceptor implements Interceptor {
|
||||||
|
|
||||||
private final EncryptorManager encryptorManager;
|
private final EncryptorManager encryptorManager;
|
||||||
private final EncryptorProperties defaultProperties;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object intercept(Invocation invocation) throws Throwable {
|
public Object intercept(Invocation invocation) throws Throwable {
|
||||||
@ -101,14 +100,7 @@ public class MybatisEncryptInterceptor implements Interceptor {
|
|||||||
* @return 加密后结果
|
* @return 加密后结果
|
||||||
*/
|
*/
|
||||||
private String encryptField(String value, Field field) {
|
private String encryptField(String value, Field field) {
|
||||||
EncryptField encryptField = field.getAnnotation(EncryptField.class);
|
return this.encryptorManager.encrypt(value, EncryptContextBuild.build(field));
|
||||||
EncryptContext encryptContext = new EncryptContext();
|
|
||||||
encryptContext.setAlgorithm(encryptField.algorithm() == AlgorithmType.DEFAULT ? defaultProperties.getAlgorithm() : encryptField.algorithm());
|
|
||||||
encryptContext.setEncode(encryptField.encode() == EncodeType.DEFAULT ? defaultProperties.getEncode() : encryptField.encode());
|
|
||||||
encryptContext.setPassword(StringUtils.isBlank(encryptField.password()) ? defaultProperties.getPassword() : encryptField.password());
|
|
||||||
encryptContext.setPrivateKey(StringUtils.isBlank(encryptField.privateKey()) ? defaultProperties.getPrivateKey() : encryptField.privateKey());
|
|
||||||
encryptContext.setPublicKey(StringUtils.isBlank(encryptField.publicKey()) ? defaultProperties.getPublicKey() : encryptField.publicKey());
|
|
||||||
return this.encryptorManager.encrypt(value, encryptContext);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user