init web
This commit is contained in:
+47
-40
@@ -1,14 +1,22 @@
|
||||
package com.sunyard.ssp.common.exception;
|
||||
|
||||
import com.sunyard.chsm.model.R;
|
||||
import com.sunyard.chsm.utils.ThrowableUtils;
|
||||
import com.sunyard.ssp.common.Result;
|
||||
import com.sunyard.ssp.utils.ResultUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.mybatis.spring.MyBatisSystemException;
|
||||
import org.springframework.validation.BindException;
|
||||
import org.springframework.validation.FieldError;
|
||||
import org.springframework.web.bind.annotation.ControllerAdvice;
|
||||
import org.springframework.web.bind.MethodArgumentNotValidException;
|
||||
import org.springframework.web.bind.annotation.ExceptionHandler;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
import org.springframework.web.bind.annotation.RestControllerAdvice;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.IllegalFormatException;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* 全局controller异常处理
|
||||
@@ -19,7 +27,7 @@ import org.springframework.web.bind.annotation.ResponseBody;
|
||||
* @date: 2020/5/25 16:24
|
||||
*/
|
||||
@Slf4j
|
||||
@ControllerAdvice
|
||||
@RestControllerAdvice
|
||||
public class GlobalExceptionResolver {
|
||||
|
||||
/**
|
||||
@@ -41,7 +49,7 @@ public class GlobalExceptionResolver {
|
||||
@ExceptionHandler(MyBatisSystemException.class)
|
||||
@ResponseBody
|
||||
public Result<Object> handleMyBatisSystemException(MyBatisSystemException e) {
|
||||
System.out.println("数据持久层");
|
||||
log.info("数据持久层");
|
||||
return new ResultUtil().setErrorMsg(e.getLocalizedMessage());
|
||||
}
|
||||
|
||||
@@ -51,46 +59,45 @@ public class GlobalExceptionResolver {
|
||||
@ExceptionHandler(BindException.class)
|
||||
@ResponseBody
|
||||
public Result<Object> handleBindException(BindException e) {
|
||||
System.out.println("校验器");
|
||||
log.info("校验器");
|
||||
FieldError fieldError = e.getBindingResult().getFieldError();
|
||||
return new ResultUtil().setErrorMsg(fieldError.getDefaultMessage());
|
||||
}
|
||||
|
||||
// @ExceptionHandler(MethodArgumentNotValidException.class)
|
||||
// public R<?> validExceptionHandler(MethodArgumentNotValidException ex) {
|
||||
//
|
||||
// return Optional.of(ex.getBindingResult())
|
||||
// .map(BindingResult::getFieldError)
|
||||
// .map(FieldError::getDefaultMessage)
|
||||
// .map(message -> R.error(400, message))
|
||||
// .get();
|
||||
// }
|
||||
//
|
||||
// private static final List<Class<? extends Exception>> EX_CLASS = Arrays.asList(
|
||||
// IllegalArgumentException.class, IllegalStateException.class,
|
||||
// IllegalFormatException.class,
|
||||
// SspwebException.class,
|
||||
// UnsupportedOperationException.class);
|
||||
//
|
||||
// @ExceptionHandler(Exception.class)
|
||||
// public R<?> exceptionHandler(Exception ex) {
|
||||
// String errorMessage = ThrowableUtils.buildErrorMessage(ex);
|
||||
// SspwebException serviceException = ThrowableUtils.findException(SspwebException.class, ex);
|
||||
// if (serviceException != null) {
|
||||
// log.warn("Validation failed -> {}, errorMessage: \n {}", serviceException.getMessage(), errorMessage);
|
||||
// return R.error(400, serviceException.getMessage());
|
||||
// }
|
||||
//
|
||||
// for (Class<? extends Exception> eClass : EX_CLASS) {
|
||||
// Exception exception = ThrowableUtils.findException(eClass, ex);
|
||||
// if (exception == null) {
|
||||
// continue;
|
||||
// }
|
||||
// log.warn("Validation failed -> {} ", errorMessage);
|
||||
// return R.error(400, exception.getMessage());
|
||||
// }
|
||||
// log.error("系统异常 -> ", ex);
|
||||
// return R.error("系统异常");
|
||||
// }
|
||||
@ExceptionHandler(MethodArgumentNotValidException.class)
|
||||
public R<?> validExceptionHandler(MethodArgumentNotValidException ex) {
|
||||
return Optional.of(ex)
|
||||
.map(MethodArgumentNotValidException::getFieldError)
|
||||
.map(FieldError::getDefaultMessage)
|
||||
.map(message -> R.error(400, message))
|
||||
.get();
|
||||
}
|
||||
|
||||
private static final List<Class<? extends Exception>> EX_CLASS = Arrays.asList(
|
||||
IllegalArgumentException.class, IllegalStateException.class,
|
||||
IllegalFormatException.class,
|
||||
SspwebException.class,
|
||||
UnsupportedOperationException.class);
|
||||
|
||||
@ExceptionHandler(Exception.class)
|
||||
public R<?> exceptionHandler(Exception ex) {
|
||||
String errorMessage = ThrowableUtils.buildErrorMessage(ex);
|
||||
SspwebException serviceException = ThrowableUtils.findException(SspwebException.class, ex);
|
||||
if (serviceException != null) {
|
||||
log.warn("Validation failed -> {}, errorMessage: \n {}", serviceException.getMessage(), errorMessage);
|
||||
return R.error(400, serviceException.getMessage());
|
||||
}
|
||||
|
||||
for (Class<? extends Exception> eClass : EX_CLASS) {
|
||||
Exception exception = ThrowableUtils.findException(eClass, ex);
|
||||
if (exception == null) {
|
||||
continue;
|
||||
}
|
||||
log.warn("Validation failed -> {} ", errorMessage);
|
||||
return R.error(400, exception.getMessage());
|
||||
}
|
||||
log.error("系统异常 -> ", ex);
|
||||
return R.error("系统异常");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+1
-2
@@ -70,7 +70,6 @@ public class ParamConfServiceImpl extends ServiceImpl<ParamConfMapper, ParamConf
|
||||
paramConf = new ParamConf();
|
||||
paramConf.setItem(item);
|
||||
paramConf.setStatus(0);
|
||||
System.out.println(LocalDateTime.now());
|
||||
paramConf.setCreatTime(LocalDateTime.now());
|
||||
paramConf.setKey(key);
|
||||
paramConf.setValue(String.valueOf(map.get(key)));
|
||||
@@ -157,7 +156,7 @@ public class ParamConfServiceImpl extends ServiceImpl<ParamConfMapper, ParamConf
|
||||
*/
|
||||
@Override
|
||||
public void run(ApplicationArguments args) throws Exception {
|
||||
System.out.println("初始化系统参数-----------------");
|
||||
// System.out.println("初始化系统参数-----------------");
|
||||
// List<ParamConf> paramConfs = getParamConfByJsonFile();
|
||||
// paramConfs.forEach(paramConf -> {
|
||||
// ParamConf temp = selectByKey(paramConf.getKey());
|
||||
|
||||
@@ -31,7 +31,7 @@ public class RedisConfig {
|
||||
MessageListenerAdapter messageListener() {
|
||||
//abstract methods overwrite
|
||||
return new MessageListenerAdapter((MessageListener) (message, pattern) -> {
|
||||
System.out.println("Message received: " + message.toString());
|
||||
log.info("Message received: " + message.toString());
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ import com.google.protobuf.UInt64Value;
|
||||
import com.sunyard.ssp.proto.control.Control;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import lombok.val;
|
||||
import redis.clients.jedis.BinaryJedisPubSub;
|
||||
|
||||
@@ -18,6 +19,7 @@ import java.util.List;
|
||||
* @date:2020/3/19
|
||||
* @description:
|
||||
*/
|
||||
@Slf4j
|
||||
public class ServerTest {
|
||||
|
||||
/**
|
||||
@@ -105,7 +107,6 @@ public class ServerTest {
|
||||
System.err.println("接收命令响应超时!");
|
||||
} else {
|
||||
val list = res.getData().unpack( Control.VOChannelList.class );
|
||||
System.out.println(list);
|
||||
|
||||
}
|
||||
} catch (Exception e) {
|
||||
@@ -138,7 +139,6 @@ public class ServerTest {
|
||||
System.err.println("接收命令响应超时!");
|
||||
} else {
|
||||
val list = res.getData().unpack( Control.VOChannelList.class );
|
||||
System.out.println(list);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.sunyard.ssp.utils;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.bouncycastle.asn1.ASN1InputStream;
|
||||
import org.bouncycastle.asn1.ASN1ObjectIdentifier;
|
||||
import org.bouncycastle.asn1.ASN1Sequence;
|
||||
@@ -54,6 +55,7 @@ import java.util.Set;
|
||||
* @date:2020/4/27
|
||||
* @description:
|
||||
*/
|
||||
@Slf4j
|
||||
public class CaUtil {
|
||||
|
||||
static {
|
||||
@@ -61,7 +63,7 @@ public class CaUtil {
|
||||
BouncyCastleProvider bc = new BouncyCastleProvider();
|
||||
Set<Provider.Service> services = bc.getServices();
|
||||
for (Provider.Service s:services){
|
||||
if (s.toString().toUpperCase().contains("CIPHER")) System.out.println(s.toString());
|
||||
if (s.toString().toUpperCase().contains("CIPHER")) log.info(s.toString());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -75,7 +77,7 @@ public class CaUtil {
|
||||
}
|
||||
|
||||
public static void genGMCACert() throws Exception {
|
||||
System.out.println("=============测试生成国密CA根证书=============");
|
||||
log.info("=============测试生成国密CA根证书=============");
|
||||
KeyPairGenerator g = KeyPairGenerator.getInstance("EC", "BC");
|
||||
|
||||
g.initialize(new ECNamedCurveGenParameterSpec("sm2p256v1"));
|
||||
@@ -85,7 +87,7 @@ public class CaUtil {
|
||||
PrivateKey privKey = p.getPrivate();
|
||||
PublicKey pubKey = p.getPublic();
|
||||
|
||||
System.out.println("CA PrivateKey:" + Base64.toBase64String(privKey.getEncoded()));
|
||||
log.info("CA PrivateKey:" + Base64.toBase64String(privKey.getEncoded()));
|
||||
|
||||
X500Principal iss = new X500Principal("CN=test GM ROOT CA,OU=test,C=CN,S=Guangdong,O=test");
|
||||
|
||||
@@ -121,16 +123,16 @@ public class CaUtil {
|
||||
|
||||
cert = (X509Certificate) fact.generateCertificate(bIn);
|
||||
|
||||
System.out.println("CA Cert:" + Base64.toBase64String(cert.getEncoded()));
|
||||
log.info("CA Cert:" + Base64.toBase64String(cert.getEncoded()));
|
||||
|
||||
saveFile("CAPrikey", privKey.getEncoded());
|
||||
saveFile("CARootCert.cer", cert.getEncoded());
|
||||
System.out.println("=============测试生成国密CA根证书=============");
|
||||
log.info("=============测试生成国密CA根证书=============");
|
||||
}
|
||||
|
||||
|
||||
public static void genCertWithCaSign() throws Exception {
|
||||
System.out.println("=============测试国密CA根证书签发国密证书=============");
|
||||
log.info("=============测试国密CA根证书签发国密证书=============");
|
||||
KeyFactory keyFactory = KeyFactory.getInstance("EC");
|
||||
|
||||
PKCS8EncodedKeySpec pkcs8EncodedKeySpec = new PKCS8EncodedKeySpec(readFile("CAPrikey"));
|
||||
@@ -182,16 +184,16 @@ public class CaUtil {
|
||||
|
||||
cert = (X509Certificate) fact.generateCertificate(bIn);
|
||||
|
||||
System.out.println("custCert:" + Base64.toBase64String(cert.getEncoded()));
|
||||
System.out.println("custPrivateKey:" + Base64.toBase64String(privKey.getEncoded()));
|
||||
log.info("custCert:" + Base64.toBase64String(cert.getEncoded()));
|
||||
log.info("custPrivateKey:" + Base64.toBase64String(privKey.getEncoded()));
|
||||
saveFile("custCert.cer", cert.getEncoded());
|
||||
saveFile("custPrivateKey", privKey.getEncoded());
|
||||
System.out.println("=============测试国密CA根证书签发国密证书=============");
|
||||
log.info("=============测试国密CA根证书签发国密证书=============");
|
||||
|
||||
}
|
||||
|
||||
public static void testDigitalSign() throws Exception {
|
||||
System.out.println("=============测试国密证书数字签名=============");
|
||||
log.info("=============测试国密证书数字签名=============");
|
||||
PKCS8EncodedKeySpec pkcs8EncodedKeySpec = new PKCS8EncodedKeySpec(readFile("custPrivateKey"));
|
||||
|
||||
KeyFactory keyFactory = KeyFactory.getInstance("EC");
|
||||
@@ -211,9 +213,9 @@ public class CaUtil {
|
||||
|
||||
byte[] digitalsignature = signature.sign();
|
||||
|
||||
System.out.println("signText:" + signText);
|
||||
log.info("signText:" + signText);
|
||||
|
||||
System.out.println("digitalsignature:" + Base64.toBase64String(digitalsignature));
|
||||
log.info("digitalsignature:" + Base64.toBase64String(digitalsignature));
|
||||
|
||||
Signature signature1 = Signature.getInstance("SM3withSM2", "BC");
|
||||
|
||||
@@ -223,7 +225,7 @@ public class CaUtil {
|
||||
|
||||
boolean result = signature1.verify(digitalsignature);
|
||||
|
||||
System.out.println("verifyResult:" + result);
|
||||
log.info("verifyResult:" + result);
|
||||
|
||||
Signature signature2 = Signature.getInstance("SM3withSM2", "BC");
|
||||
|
||||
@@ -233,15 +235,15 @@ public class CaUtil {
|
||||
|
||||
boolean exceptionResult = signature2.verify(digitalsignature);
|
||||
|
||||
System.out.println("exceptionVerifyResult:" + exceptionResult);
|
||||
log.info("exceptionVerifyResult:" + exceptionResult);
|
||||
|
||||
System.out.println("=============测试国密证书数字签名=============");
|
||||
log.info("=============测试国密证书数字签名=============");
|
||||
}
|
||||
|
||||
|
||||
public static void testSM2EcDc() throws Exception {
|
||||
|
||||
System.out.println("=============测试国密SM2加解密=============");
|
||||
log.info("=============测试国密SM2加解密=============");
|
||||
|
||||
//从证书获取公钥
|
||||
CertificateFactory certificateFactory = CertificateFactory.getInstance("X509", "BC");
|
||||
@@ -258,14 +260,14 @@ public class CaUtil {
|
||||
//待加密数据
|
||||
byte[] ebs = "123sssss测试".getBytes("UTF-8");
|
||||
|
||||
System.out.println("原文:"+new String(ebs));
|
||||
log.info("原文:"+new String(ebs));
|
||||
//初始化加密引擎
|
||||
SM2Engine sm2EncEngine = new SM2Engine();
|
||||
sm2EncEngine.init(true, new ParametersWithRandom(localECPublicKeyParameters));
|
||||
//加密
|
||||
byte[] bs = sm2EncEngine.processBlock(ebs,0,ebs.length);
|
||||
String es = Base64.toBase64String(bs);
|
||||
System.out.println("密文:"+es);
|
||||
log.info("密文:"+es);
|
||||
|
||||
//获取私钥
|
||||
PKCS8EncodedKeySpec pkcs8EncodedKeySpec = new PKCS8EncodedKeySpec(readFile("custPrivateKey"));
|
||||
@@ -285,13 +287,13 @@ public class CaUtil {
|
||||
sm2DcEngine.init(false, localECPrivateKeyParameters);
|
||||
bs = Base64.decode(es.getBytes("Utf-8"));
|
||||
byte[] b = sm2DcEngine.processBlock(bs,0,bs.length);
|
||||
System.out.println("明文:"+new String(b));
|
||||
log.info("明文:"+new String(b));
|
||||
|
||||
System.out.println("=============测试国密SM2加解密=============");
|
||||
log.info("=============测试国密SM2加解密=============");
|
||||
}
|
||||
|
||||
public static void testSaveGMKeyStore() throws Exception {
|
||||
System.out.println("=============测试国密证书PKCS12 KeyStore存取=============");
|
||||
log.info("=============测试国密证书PKCS12 KeyStore存取=============");
|
||||
PKCS8EncodedKeySpec pkcs8EncodedKeySpec = new PKCS8EncodedKeySpec(readFile("custPrivateKey"));
|
||||
|
||||
KeyFactory keyFactory = KeyFactory.getInstance("EC");
|
||||
@@ -318,11 +320,11 @@ public class CaUtil {
|
||||
|
||||
PrivateKey privateKey1 = (PrivateKey) keyStore1.getKey("test", "32145698745632145698745632145698".toCharArray());
|
||||
|
||||
System.out.println("公钥证书存取前后对比:" + Arrays.equals(certificate1.getEncoded(), certificate.getEncoded()));
|
||||
log.info("公钥证书存取前后对比:" + Arrays.equals(certificate1.getEncoded(), certificate.getEncoded()));
|
||||
|
||||
System.out.println("私钥存取前后对比:" + Arrays.equals(privateKey.getEncoded(), privateKey1.getEncoded()));
|
||||
log.info("私钥存取前后对比:" + Arrays.equals(privateKey.getEncoded(), privateKey1.getEncoded()));
|
||||
|
||||
System.out.println("=============测试国密证书PKCS12 KeyStore存取=============");
|
||||
log.info("=============测试国密证书PKCS12 KeyStore存取=============");
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -87,7 +87,7 @@ public class SM2Util extends GMBaseUtil {
|
||||
}
|
||||
|
||||
// 3059301306072A8648CE3D020106082A811CCF5501822D03420004EB1F1EC734D710C016B171C4A0DC5418BD9AE89EEFE8DA7C36D7192B40F8CF9B80EFF7D62F98A9D84BF910B85AD8F2F19D8DC1EE61458A01B7FB21C1850C7290
|
||||
// System.out.println(pk);
|
||||
// log.info(pk);
|
||||
|
||||
|
||||
// EB1F1EC734D710C016B171C4A0DC5418BD9AE89EEFE8DA7C36D7192B40F8CF9B80EFF7D62F98A9D84BF910B85AD8F2F19D8DC1EE61458A01B7FB21C1850C7290
|
||||
@@ -97,8 +97,8 @@ public class SM2Util extends GMBaseUtil {
|
||||
String xHex = pkDer.substring(0, 64);
|
||||
String yHex = pkDer.substring(64);
|
||||
|
||||
// System.out.println("x=" + xHex);
|
||||
// System.out.println("y=" + yHex);
|
||||
// log.info("x=" + xHex);
|
||||
// log.info("y=" + yHex);
|
||||
ECPublicKeyParameters pubKey = BCECUtil.createECPublicKeyParameters(xHex, yHex, SM2Util.CURVE, SM2Util.DOMAIN_PARAMS);
|
||||
|
||||
|
||||
@@ -459,7 +459,7 @@ public class SM2Util extends GMBaseUtil {
|
||||
}
|
||||
signer.init(true, param);
|
||||
|
||||
System.out.println("Z=" + BytesUtil.bytes2HexString((byte[]) ReflectUtil.getFieldValue( signer, "z")));
|
||||
log.info("Z=" + BytesUtil.bytes2HexString((byte[]) ReflectUtil.getFieldValue( signer, "z")));
|
||||
|
||||
signer.update(srcData, 0, srcData.length);
|
||||
return signer.generateSignature();
|
||||
@@ -559,13 +559,13 @@ public class SM2Util extends GMBaseUtil {
|
||||
param = pubKeyParameters;
|
||||
}
|
||||
signer.init(false, param);
|
||||
System.out.println("Z=" + BytesUtil.bytes2HexString((byte[]) ReflectUtil.getFieldValue( signer, "z")));
|
||||
log.info("Z=" + BytesUtil.bytes2HexString((byte[]) ReflectUtil.getFieldValue( signer, "z")));
|
||||
|
||||
// Digest digest = (Digest) ReflectUtil.getFieldValue( signer, "digest" );
|
||||
// digest.update( srcData, 0, srcData.length );
|
||||
// byte[] result = new byte[digest.getDigestSize()];
|
||||
// digest.doFinal(result, 0);
|
||||
// System.out.println("hash=" + Util.bytes2HexString(result));
|
||||
// log.info("hash=" + Util.bytes2HexString(result));
|
||||
|
||||
signer.update(srcData, 0, srcData.length);
|
||||
return signer.verifySignature(sign);
|
||||
|
||||
@@ -69,7 +69,7 @@ public class SM3 {
|
||||
g = V[6];
|
||||
h = V[7];
|
||||
|
||||
/*System.out.println("IV: ");
|
||||
/*log.info("IV: ");
|
||||
System.out.print(Integer.toHexString(a)+" ");
|
||||
System.out.print(Integer.toHexString(b)+" ");
|
||||
System.out.print(Integer.toHexString(c)+" ");
|
||||
|
||||
@@ -2,7 +2,9 @@ package com.sunyard.ssp.utils.sm3;
|
||||
|
||||
|
||||
import com.sunyard.config.security.SM3PasswordEncoder;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
@Slf4j
|
||||
public class SM3Digest
|
||||
{
|
||||
/** SM3值的长度 */
|
||||
@@ -175,9 +177,9 @@ public class SM3Digest
|
||||
String s="";
|
||||
SM3PasswordEncoder passwordEncoder = new SM3PasswordEncoder();
|
||||
String encode = passwordEncoder.encode(s);
|
||||
System.out.println("加密后结果="+encode);
|
||||
log.info("加密后结果="+encode);
|
||||
|
||||
boolean matches = passwordEncoder.matches("123", encode);
|
||||
System.out.println("校验结果="+matches);
|
||||
log.info("校验结果="+matches);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user