|
@ -1,16 +1,20 @@
|
|
|
package com.yihu.jw.security.oauth2.provider.endpoint;
|
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
import com.yihu.jw.entity.base.login.BaseLoginLogDO;
|
|
|
import com.yihu.jw.restmodel.ResultStatus;
|
|
|
import com.yihu.jw.restmodel.web.ObjEnvelop;
|
|
|
import com.yihu.jw.security.core.userdetails.jdbc.WlyyUserDetailsService;
|
|
|
import com.yihu.jw.security.dao.OauthKeypairDao;
|
|
|
import com.yihu.jw.security.login.service.BaseLoginLogService;
|
|
|
import com.yihu.jw.security.model.*;
|
|
|
import com.yihu.jw.security.oauth2.core.redis.WlyyRedisVerifyCodeService;
|
|
|
import com.yihu.jw.security.oauth2.provider.WlyyTokenGranter;
|
|
|
import com.yihu.jw.security.oauth2.provider.error.WlyyOAuth2ExceptionTranslator;
|
|
|
import com.yihu.jw.security.utils.SerializeUtil;
|
|
|
import com.yihu.utils.security.RSAUtils;
|
|
|
import org.apache.commons.collections.map.HashedMap;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
@ -45,6 +49,7 @@ import javax.servlet.http.HttpServletResponse;
|
|
|
import javax.servlet.http.HttpSession;
|
|
|
import java.io.IOException;
|
|
|
import java.security.KeyPair;
|
|
|
import java.security.PrivateKey;
|
|
|
import java.security.interfaces.RSAPrivateKey;
|
|
|
import java.security.interfaces.RSAPublicKey;
|
|
|
import java.text.SimpleDateFormat;
|
|
@ -52,6 +57,7 @@ import java.util.Date;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.Map;
|
|
|
import java.util.UUID;
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
|
|
|
/**
|
|
|
* <p>
|
|
@ -90,6 +96,8 @@ public class WlyyLoginEndpoint extends AbstractEndpoint {
|
|
|
private StringRedisTemplate redisTemplate;
|
|
|
@Autowired
|
|
|
private BaseLoginLogService baseLoginLogService;
|
|
|
@Autowired
|
|
|
private OauthKeypairDao oauthKeypairDao;
|
|
|
|
|
|
@PostConstruct
|
|
|
private void init() {
|
|
@ -598,4 +606,49 @@ public class WlyyLoginEndpoint extends AbstractEndpoint {
|
|
|
return response;
|
|
|
}
|
|
|
|
|
|
@RequestMapping(value = "/oauth/getHwlyyPublicKey", method = RequestMethod.GET)
|
|
|
public ObjEnvelop getHwlyyPublicKey(){
|
|
|
// KeyPair keyPair = com.yihu.jw.security.utils.RSAUtils.getKey();
|
|
|
// byte[] bytekey = SerializeUtil.ObjTOSerialize(keyPair);
|
|
|
// KeyPair key = (KeyPair)SerializeUtil.unSerialize(bytekey);
|
|
|
// OauthKeypairDO keypairDO = new OauthKeypairDO();
|
|
|
// keypairDO.setCode("hwlyyKey");
|
|
|
// keypairDO.setKeyPair(bytekey);
|
|
|
// oauthKeypairDao.save(keypairDO);
|
|
|
OauthKeypairDO keypairDO = oauthKeypairDao.findByCode("hwlyyKey");
|
|
|
KeyPair key = (KeyPair)SerializeUtil.unSerialize(keypairDO.getKeyPair());
|
|
|
PublickeyVO pk = new PublickeyVO();
|
|
|
pk.setPublicKey(com.yihu.jw.security.utils.RSAUtils.generateBase64PublicKey(key));
|
|
|
return ObjEnvelop.getSuccess("success", pk);
|
|
|
}
|
|
|
|
|
|
@RequestMapping(value = "/oauth/getHwlyyDecrypt", method = RequestMethod.POST)
|
|
|
public ObjEnvelop getHwlyyDecrypt(String openid,String idcard,String wechatId){
|
|
|
Map<String,Object> rs = new HashedMap();
|
|
|
try{
|
|
|
OauthKeypairDO keypairDO = oauthKeypairDao.findByCode("hwlyyKey");
|
|
|
KeyPair keyPair = (KeyPair)SerializeUtil.unSerialize(keypairDO.getKeyPair());
|
|
|
//解密openid
|
|
|
if(org.apache.commons.lang3.StringUtils.isNotBlank(openid)){
|
|
|
rs.put("openid",com.yihu.jw.security.utils.RSAUtils.decryptBase64(openid, keyPair));
|
|
|
}else {
|
|
|
rs.put("openid",openid);
|
|
|
}
|
|
|
//解密idcard
|
|
|
if(org.apache.commons.lang3.StringUtils.isNotBlank(idcard)){
|
|
|
rs.put("idcard",com.yihu.jw.security.utils.RSAUtils.decryptBase64(idcard, keyPair));
|
|
|
}else {
|
|
|
rs.put("idcard",idcard);
|
|
|
}
|
|
|
//解密wechatId
|
|
|
if(org.apache.commons.lang3.StringUtils.isNotBlank(wechatId)){
|
|
|
rs.put("wechatId",com.yihu.jw.security.utils.RSAUtils.decryptBase64(wechatId, keyPair));
|
|
|
}else {
|
|
|
rs.put("wechatId",wechatId);
|
|
|
}
|
|
|
}catch (Exception e){
|
|
|
logger.error(e);
|
|
|
}
|
|
|
return ObjEnvelop.getSuccess("success", rs);
|
|
|
}
|
|
|
}
|