|
@ -16,7 +16,6 @@ import com.epmet.commons.tools.exception.ExceptionUtils; |
|
|
import com.epmet.commons.tools.exception.RenException; |
|
|
import com.epmet.commons.tools.exception.RenException; |
|
|
import com.epmet.commons.tools.security.dto.GovTokenDto; |
|
|
import com.epmet.commons.tools.security.dto.GovTokenDto; |
|
|
import com.epmet.commons.tools.security.dto.TokenDto; |
|
|
import com.epmet.commons.tools.security.dto.TokenDto; |
|
|
import com.epmet.commons.tools.security.password.PasswordUtils; |
|
|
|
|
|
import com.epmet.commons.tools.utils.*; |
|
|
import com.epmet.commons.tools.utils.*; |
|
|
import com.epmet.constant.SsoConstant; |
|
|
import com.epmet.constant.SsoConstant; |
|
|
import com.epmet.dto.*; |
|
|
import com.epmet.dto.*; |
|
@ -33,18 +32,16 @@ import com.epmet.redis.SsoRedis; |
|
|
import com.epmet.service.SsoService; |
|
|
import com.epmet.service.SsoService; |
|
|
import com.epmet.service.ThirdLoginService; |
|
|
import com.epmet.service.ThirdLoginService; |
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
import org.apache.commons.codec.digest.DigestUtils; |
|
|
|
|
|
import org.apache.commons.lang3.StringUtils; |
|
|
import org.apache.commons.lang3.StringUtils; |
|
|
import org.apache.http.HttpEntity; |
|
|
import org.apache.http.HttpEntity; |
|
|
import org.apache.http.client.methods.CloseableHttpResponse; |
|
|
import org.apache.http.client.methods.CloseableHttpResponse; |
|
|
import org.apache.http.client.methods.HttpPost; |
|
|
import org.apache.http.client.methods.HttpPost; |
|
|
import org.apache.http.entity.StringEntity; |
|
|
import org.apache.http.entity.mime.MultipartEntityBuilder; |
|
|
import org.apache.http.impl.client.CloseableHttpClient; |
|
|
import org.apache.http.impl.client.CloseableHttpClient; |
|
|
import org.apache.http.impl.client.HttpClients; |
|
|
import org.apache.http.impl.client.HttpClients; |
|
|
import org.apache.http.util.EntityUtils; |
|
|
import org.apache.http.util.EntityUtils; |
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
import org.springframework.beans.factory.annotation.Value; |
|
|
import org.springframework.beans.factory.annotation.Value; |
|
|
import org.springframework.http.MediaType; |
|
|
|
|
|
import org.springframework.stereotype.Service; |
|
|
import org.springframework.stereotype.Service; |
|
|
import org.springframework.util.CollectionUtils; |
|
|
import org.springframework.util.CollectionUtils; |
|
|
|
|
|
|
|
@ -205,46 +202,32 @@ public class SsoServiceImpl implements SsoService { |
|
|
CloseableHttpClient httpclient = null; |
|
|
CloseableHttpClient httpclient = null; |
|
|
CloseableHttpResponse response = null; |
|
|
CloseableHttpResponse response = null; |
|
|
UserTokenResultDTO userTokenResultDTO = null; |
|
|
UserTokenResultDTO userTokenResultDTO = null; |
|
|
try { |
|
|
|
|
|
httpclient = HttpClients.createDefault(); |
|
|
httpclient = HttpClients.createDefault(); |
|
|
HttpPost httpPost = new HttpPost(SsoConstant.TICKET_TOKEN_URL); |
|
|
HttpPost httpPost = new HttpPost(SsoConstant.TICKET_TOKEN_URL); |
|
|
JSONObject infoJson = new JSONObject(); |
|
|
MultipartEntityBuilder builder = MultipartEntityBuilder.create(); |
|
|
infoJson.put("ticket", form.getTicket()); |
|
|
builder.setCharset(StandardCharsets.UTF_8); |
|
|
StringEntity stringEntity = new StringEntity(infoJson.toString(), "UTF-8"); |
|
|
builder.addTextBody("ticket", form.getTicket()); |
|
|
stringEntity.setContentEncoding("UTF-8"); |
|
|
HttpEntity entity = builder.build(); |
|
|
stringEntity.setContentType(MediaType.APPLICATION_JSON_VALUE); |
|
|
httpPost.setEntity(entity); |
|
|
httpPost.setEntity(stringEntity); |
|
|
|
|
|
response = httpclient.execute(httpPost); |
|
|
response = httpclient.execute(httpPost); |
|
|
HttpEntity entity = response.getEntity(); |
|
|
JSONObject result = JSONObject.parseObject(EntityUtils.toString(response.getEntity())); |
|
|
if (entity != null) { |
|
|
|
|
|
EntityUtils.toString(entity, "UTF-8"); |
|
|
|
|
|
} |
|
|
|
|
|
JSONObject result = JSONObject.parseObject(EntityUtils.toString(entity)); |
|
|
|
|
|
if (result.getString("code").equals("200")) { |
|
|
if (result.getString("code").equals("200")) { |
|
|
String ticket = result.getString("data"); |
|
|
String ticket = result.getString("data"); |
|
|
String timestamp = String.valueOf(System.currentTimeMillis()); |
|
|
String timestamp = String.valueOf(System.currentTimeMillis()); |
|
|
String nonce = RandomUtil.randomString(18); |
|
|
String nonce = RandomUtil.randomString(18); |
|
|
httpPost = new HttpPost(SsoConstant.USER_INFO_URL); |
|
|
httpPost = new HttpPost(SsoConstant.USER_INFO_URL); |
|
|
infoJson = new JSONObject(); |
|
|
builder = MultipartEntityBuilder.create(); |
|
|
infoJson.put("loginId", ticket); |
|
|
builder.setCharset(StandardCharsets.UTF_8); |
|
|
infoJson.put("timestamp", timestamp); |
|
|
builder.addTextBody("loginId", ticket); |
|
|
infoJson.put("nonce", nonce); |
|
|
builder.addTextBody("timestamp", timestamp); |
|
|
infoJson.put("sign", Md5Params(ticket, timestamp, nonce)); |
|
|
builder.addTextBody("nonce", nonce); |
|
|
String params = DigestUtils.md5Hex(infoJson.toString().getBytes(StandardCharsets.UTF_8)); |
|
|
builder.addTextBody("sign", Md5Params(ticket, timestamp, nonce)); |
|
|
stringEntity = new StringEntity(params, "UTF-8"); |
|
|
httpPost.setEntity(builder.build()); |
|
|
stringEntity.setContentEncoding("UTF-8"); |
|
|
|
|
|
stringEntity.setContentType(MediaType.APPLICATION_JSON_VALUE); |
|
|
|
|
|
httpPost.setEntity(stringEntity); |
|
|
|
|
|
response = httpclient.execute(httpPost); |
|
|
response = httpclient.execute(httpPost); |
|
|
entity = response.getEntity(); |
|
|
result = JSONObject.parseObject(EntityUtils.toString(response.getEntity())); |
|
|
if (entity != null) { |
|
|
|
|
|
EntityUtils.toString(entity, "UTF-8"); |
|
|
|
|
|
} |
|
|
|
|
|
result = JSONObject.parseObject(EntityUtils.toString(entity)); |
|
|
|
|
|
if (result.getString("code").equals("200")) { |
|
|
if (result.getString("code").equals("200")) { |
|
|
JSONObject data = JSONObject.parseObject(result.getString("data")); |
|
|
JSONObject data = JSONObject.parseObject(result.getString("data")); |
|
|
String mobile = data.getString("phone"); |
|
|
String mobile = data.getString("phone"); |
|
|
String password = data.getString("password"); |
|
|
|
|
|
//1、根据手机号查询政府端工作人员基本信息,校验用户是否存在
|
|
|
//1、根据手机号查询政府端工作人员基本信息,校验用户是否存在
|
|
|
Result<List<CustomerStaffDTO>> staffData = epmetUserFeignClient.checkCustomerStaff(mobile); |
|
|
Result<List<CustomerStaffDTO>> staffData = epmetUserFeignClient.checkCustomerStaff(mobile); |
|
|
String customerId = ""; |
|
|
String customerId = ""; |
|
@ -268,12 +251,6 @@ public class SsoServiceImpl implements SsoService { |
|
|
String.format("当前账号已被禁用staffId:%s", resData.getUserId()), |
|
|
String.format("当前账号已被禁用staffId:%s", resData.getUserId()), |
|
|
EpmetErrorCode.GOV_STAFF_DISABLED.getMsg()); |
|
|
EpmetErrorCode.GOV_STAFF_DISABLED.getMsg()); |
|
|
} |
|
|
} |
|
|
GovWebOperLoginResultDTO resultDTO = resData; |
|
|
|
|
|
//4.密码是否正确
|
|
|
|
|
|
if (!PasswordUtils.matches(password, resultDTO.getPassWord())) { |
|
|
|
|
|
log.warn("登陆密码错误"); |
|
|
|
|
|
throw new EpmetException(EpmetErrorCode.ERR10004.getCode(), "登陆密码错误!"); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
} |
|
|
//5.生成token存到redis并返回
|
|
|
//5.生成token存到redis并返回
|
|
|
userTokenResultDTO = new UserTokenResultDTO(); |
|
|
userTokenResultDTO = new UserTokenResultDTO(); |
|
@ -296,14 +273,10 @@ public class SsoServiceImpl implements SsoService { |
|
|
log.error("校验失败,没有查询到Ticket为:'" + form.getTicket() + "'的人员信息", result.getString("msg")); |
|
|
log.error("校验失败,没有查询到Ticket为:'" + form.getTicket() + "'的人员信息", result.getString("msg")); |
|
|
throw new EpmetException(EpmetErrorCode.ERR10008.getCode(), "校验失败,没有查询到Ticket为:'" + form.getTicket() + "'的人员信息"); |
|
|
throw new EpmetException(EpmetErrorCode.ERR10008.getCode(), "校验失败,没有查询到Ticket为:'" + form.getTicket() + "'的人员信息"); |
|
|
} |
|
|
} |
|
|
} catch (Exception e) { |
|
|
|
|
|
e.printStackTrace(); |
|
|
|
|
|
} finally { |
|
|
|
|
|
if (null != httpclient) { |
|
|
if (null != httpclient) { |
|
|
httpclient.close(); |
|
|
httpclient.close(); |
|
|
response.close(); |
|
|
response.close(); |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
return userTokenResultDTO; |
|
|
return userTokenResultDTO; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -314,17 +287,15 @@ public class SsoServiceImpl implements SsoService { |
|
|
* @return |
|
|
* @return |
|
|
*/ |
|
|
*/ |
|
|
private String Md5Params(String loginId, String timestamp, String nonce) { |
|
|
private String Md5Params(String loginId, String timestamp, String nonce) { |
|
|
String prefix = "=${"; |
|
|
String suffix = "&"; |
|
|
String suffix = "}&"; |
|
|
|
|
|
StringBuilder builder = new StringBuilder(); |
|
|
StringBuilder builder = new StringBuilder(); |
|
|
builder.append("loginId").append(prefix).append(loginId).append(suffix); |
|
|
builder.append("loginId=").append(loginId).append(suffix); |
|
|
builder.append("nonce").append(prefix).append(nonce).append(suffix); |
|
|
builder.append("nonce=").append(nonce).append(suffix); |
|
|
builder.append("timestamp").append(prefix).append(timestamp).append(suffix); |
|
|
builder.append("timestamp=").append(timestamp).append(suffix); |
|
|
builder.append("key").append("={").append(SsoConstant.SECRET_KEY).append("}"); |
|
|
builder.append("key=").append(SsoConstant.SECRET_KEY); |
|
|
return SecureUtil.md5(builder.toString()); |
|
|
return SecureUtil.md5(builder.toString()); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* @Description token放缓存 |
|
|
* @Description token放缓存 |
|
|
* @Param formDTO |
|
|
* @Param formDTO |
|
|