package com.qianwen.core.api.crypto.core;
|
|
import java.lang.reflect.Parameter;
|
import com.qianwen.core.api.crypto.annotation.decrypt.ApiDecrypt;
|
import com.qianwen.core.api.crypto.bean.CryptoInfoBean;
|
import com.qianwen.core.api.crypto.config.ApiCryptoProperties;
|
import com.qianwen.core.api.crypto.util.ApiCryptoUtil;
|
import com.qianwen.core.tool.jackson.JsonUtil;
|
import com.qianwen.core.tool.utils.Charsets;
|
import com.qianwen.core.tool.utils.StringUtil;
|
import org.springframework.core.MethodParameter;
|
import org.springframework.core.annotation.AnnotatedElementUtils;
|
import org.springframework.lang.Nullable;
|
import org.springframework.web.bind.support.WebDataBinderFactory;
|
import org.springframework.web.context.request.NativeWebRequest;
|
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
|
import org.springframework.web.method.support.ModelAndViewContainer;
|
|
/* loaded from: blade-starter-api-crypto-9.3.0.0-SNAPSHOT.jar:org/springblade/core/api/crypto/core/ApiDecryptParamResolver.class */
|
public class ApiDecryptParamResolver implements HandlerMethodArgumentResolver {
|
private final ApiCryptoProperties properties;
|
|
public ApiDecryptParamResolver(final ApiCryptoProperties properties) {
|
this.properties = properties;
|
}
|
|
public boolean supportsParameter(MethodParameter parameter) {
|
return AnnotatedElementUtils.hasAnnotation(parameter.getParameter(), ApiDecrypt.class);
|
}
|
|
@Nullable
|
public Object resolveArgument(MethodParameter methodParameter, ModelAndViewContainer mavContainer, NativeWebRequest webRequest, WebDataBinderFactory binderFactory) {
|
Parameter parameter = methodParameter.getParameter();
|
ApiDecrypt apiDecrypt = (ApiDecrypt) AnnotatedElementUtils.getMergedAnnotation(parameter, ApiDecrypt.class);
|
String text = webRequest.getParameter(this.properties.getParamName());
|
if (StringUtil.isBlank(text)) {
|
return null;
|
}
|
CryptoInfoBean infoBean = new CryptoInfoBean(apiDecrypt.value(), apiDecrypt.secretKey());
|
byte[] textBytes = text.getBytes(Charsets.UTF_8);
|
byte[] decryptData = ApiCryptoUtil.decryptData(this.properties, textBytes, infoBean);
|
return JsonUtil.readValue(decryptData, parameter.getType());
|
}
|
}
|