| | |
| | | package com.panzhihua.service_community.model.helper.encrypt; |
| | | |
| | | import com.panzhihua.common.model.helper.encrypt.EncryptDecryptClass; |
| | | import com.panzhihua.common.model.helper.encrypt.IEncryptDecrypt; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import java.sql.Statement; |
| | | import java.util.ArrayList; |
| | | import java.util.Objects; |
| | | import java.util.Properties; |
| | | |
| | | import org.apache.ibatis.executor.resultset.ResultSetHandler; |
| | | import org.apache.ibatis.plugin.*; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | |
| | | import org.springframework.core.annotation.Order; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import java.sql.Statement; |
| | | import java.util.ArrayList; |
| | | import java.util.Objects; |
| | | import java.util.Properties; |
| | | import com.panzhihua.common.model.helper.encrypt.EncryptDecryptClass; |
| | | import com.panzhihua.common.model.helper.encrypt.IEncryptDecrypt; |
| | | |
| | | import lombok.extern.slf4j.Slf4j; |
| | | |
| | | /** |
| | | * 解密拦截器 |
| | |
| | | * @author cedoo |
| | | * @since 2021-4-1 10:40:52 |
| | | */ |
| | | @Intercepts({ |
| | | @Signature(type = ResultSetHandler.class, method = "handleResultSets", args={Statement.class}) |
| | | }) |
| | | @Intercepts({@Signature(type = ResultSetHandler.class, method = "handleResultSets", args = {Statement.class})}) |
| | | @ConditionalOnProperty(value = "domain.decrypt", havingValue = "true") |
| | | @Component |
| | | @Slf4j |
| | |
| | | @Override |
| | | public Object intercept(Invocation invocation) throws Throwable { |
| | | Object result = invocation.proceed(); |
| | | if (Objects.isNull(result)){ |
| | | if (Objects.isNull(result)) { |
| | | return null; |
| | | } |
| | | |
| | | if (result instanceof ArrayList) { |
| | | ArrayList resultList = (ArrayList) result; |
| | | if (resultList!=null && resultList.size()>0 && needToDecrypt(resultList.get(0))){ |
| | | ArrayList resultList = (ArrayList)result; |
| | | if (resultList != null && resultList.size() > 0 && needToDecrypt(resultList.get(0))) { |
| | | for (int i = 0; i < resultList.size(); i++) { |
| | | encryptDecrypt.decrypt(resultList.get(i)); |
| | | } |
| | | } |
| | | }else { |
| | | if (needToDecrypt(result)){ |
| | | } else { |
| | | if (needToDecrypt(result)) { |
| | | encryptDecrypt.decrypt(result); |
| | | } |
| | | } |
| | | return result; |
| | | } |
| | | |
| | | public boolean needToDecrypt(Object object){ |
| | | if(object!=null) { |
| | | public boolean needToDecrypt(Object object) { |
| | | if (object != null) { |
| | | Class<?> objectClass = object.getClass(); |
| | | EncryptDecryptClass encryptDecryptClass = AnnotationUtils.findAnnotation(objectClass, EncryptDecryptClass.class); |
| | | if (Objects.nonNull(encryptDecryptClass)) { |
| | | return true; |
| | | } |
| | | EncryptDecryptClass encryptDecryptClass = |
| | | AnnotationUtils.findAnnotation(objectClass, EncryptDecryptClass.class); |
| | | return Objects.nonNull(encryptDecryptClass); |
| | | } |
| | | return false; |
| | | } |