| | |
| | | import com.panzhihua.common.model.helper.encrypt.EncryptQuery; |
| | | import com.panzhihua.common.model.helper.encrypt.EncryptQueryClass; |
| | | import com.panzhihua.common.model.helper.encrypt.IEncryptDecrypt; |
| | | import com.panzhihua.common.model.helper.sensitive.Sensitive; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.ibatis.binding.BindingException; |
| | | import org.apache.ibatis.binding.MapperMethod; |
| | |
| | | import java.lang.reflect.Field; |
| | | import java.sql.PreparedStatement; |
| | | import java.util.*; |
| | | import java.util.stream.Stream; |
| | | |
| | | /** |
| | | * 加密拦截器 |
| | |
| | | |
| | | @Override |
| | | public Object intercept(Invocation invocation) throws Throwable { |
| | | |
| | | //拦截 ParameterHandler 的 setParameters 方法 动态设置参数 |
| | | if (invocation.getTarget() instanceof ParameterHandler) { |
| | | ParameterHandler parameterHandler = (ParameterHandler) invocation.getTarget(); |
| | |
| | | Map.Entry<String, Object> entry = (Map.Entry<String, Object>) iterator.next(); |
| | | if (entry.getKey().startsWith("param")) { |
| | | Object v = entry.getValue(); |
| | | EncryptQueryClass encryptQueryClass = AnnotationUtils.findAnnotation(v.getClass(), EncryptQueryClass.class); |
| | | if (Objects.nonNull(encryptQueryClass)) { |
| | | Field[] declaredFields = v.getClass().getDeclaredFields(); |
| | | for (Field field : declaredFields) { |
| | | if (field.isAnnotationPresent(EncryptQuery.class)) { |
| | | try { |
| | | final Object encrypt = encryptDecrypt.encrypt(new Field[]{field}, v); |
| | | paramMap.put("encrypted", true); |
| | | } catch (IllegalAccessException e) { |
| | | e.printStackTrace(); |
| | | if(v!=null) { |
| | | EncryptQueryClass encryptQueryClass = AnnotationUtils.findAnnotation(v.getClass(), EncryptQueryClass.class); |
| | | if (Objects.nonNull(encryptQueryClass)) { |
| | | Field[] declaredFields = v.getClass().getDeclaredFields(); |
| | | for (Field field : declaredFields) { |
| | | if (field.isAnnotationPresent(EncryptQuery.class)) { |
| | | try { |
| | | final Object encrypt = encryptDecrypt.encrypt(new Field[]{field}, v); |
| | | paramMap.put("encrypted", true); |
| | | } catch (IllegalAccessException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | } |
| | | } |