Commit e7e27056 authored by litengwei's avatar litengwei

Merge remote-tracking branch 'origin/develop_dl_bugfix' into develop_dl_bugfix

parents 38090e4b 9ad7de16
package com.yeejoin.amos.fas.business.controller;
import com.yeejoin.amos.fas.business.util.JSONUtil;
import com.yeejoin.amos.fas.business.util.SSLClient;
import com.yeejoin.amos.fas.core.util.CommonResponseUtil2;
import com.yeejoin.amos.fas.core.util.ResponseModel;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.util.HashMap;
import java.util.Map;
@RestController
@RequestMapping("/api/sso")
@Api(tags = "获取isdp的tokenAPI")
public class SsoTokenController {
@Value("${sso.client.id}")
private String clientId;
@Value("${sso.client.secret}")
private String clientSecret;
@Value("${sso.login.client}")
private String loginClient;
@Value("${sso.client.url}")
private String clientUrl;
@Value("${sso.login.type}")
private String loginType;
@Autowired
private SSLClient sslClient;
/**
* 获取tokenAPI
*/
@ApiOperation(value = "获取token", notes = "获取token")
@GetMapping(value = "/getSsoToken", produces = "application/json;charset=UTF-8")
public ResponseModel getSsoToken(@RequestParam(value = "username") String username) {
Map<String, Object> params = new HashMap<>();
params.put("client_id", clientId);
params.put("client_secret", clientSecret);
params.put("loginClient", loginClient);
params.put("login_type", loginType);
params.put("username", username);
String message = JSONUtil.toJson(params);
String result = sslClient.doPost(clientUrl, message, "utf-8");
return CommonResponseUtil2.success(result);
}
}
......@@ -19,26 +19,4 @@ public class RandomUtil {
}
return newDate + result;
}
/**
* @param resourceType 资源类型
* @param companyCode 单位编号
* @Description Random存在性能问题可能造成线程阻塞问题,使
* 用性能更加卓越的threadLocalRandom(线程安全的单例模式)生成随机数
* 四位随机数无法保证不可重复性,如果对不可重复要求高,请使用其他工具
* @Author songLei
* @Return String
* @Date 2020/12/18 11:49
*/
public static String buildNo(String resourceType, String companyCode) {
threadLocalRandom = ThreadLocalRandom.current();
int num = threadLocalRandom.nextInt(1000, 9999);
return resourceType + companyCode + num;
}
public static String buildNo() {
threadLocalRandom = ThreadLocalRandom.current();
int num = threadLocalRandom.nextInt(1000, 9999);
return String.valueOf(num);
}
}
package com.yeejoin.amos.fas.business.util;
import lombok.extern.slf4j.Slf4j;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.conn.ClientConnectionManager;
import org.apache.http.conn.scheme.Scheme;
import org.apache.http.conn.scheme.SchemeRegistry;
import org.apache.http.conn.ssl.SSLSocketFactory;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.util.EntityUtils;
import org.springframework.stereotype.Component;
import javax.net.ssl.SSLContext;
import javax.net.ssl.TrustManager;
import javax.net.ssl.X509TrustManager;
import java.security.cert.CertificateException;
import java.security.cert.X509Certificate;
@Slf4j
@Component
public class SSLClient extends DefaultHttpClient {
public SSLClient() throws Exception {
super();
//传输协议需要根据自己的判断
SSLContext ctx = SSLContext.getInstance("TLS");
X509TrustManager tm = new X509TrustManager() {
@Override
public void checkClientTrusted(X509Certificate[] chain,
String authType) throws CertificateException {
}
@Override
public void checkServerTrusted(X509Certificate[] chain,
String authType) throws CertificateException {
}
@Override
public X509Certificate[] getAcceptedIssuers() {
return null;
}
};
ctx.init(null, new TrustManager[]{tm}, null);
SSLSocketFactory ssf = new SSLSocketFactory(ctx, SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
ClientConnectionManager ccm = this.getConnectionManager();
SchemeRegistry sr = ccm.getSchemeRegistry();
sr.register(new Scheme("https", 443, ssf));
}
public String doPost(String url, String map, String charset) {
org.apache.http.client.HttpClient httpClient = null;
HttpPost httpPost = null;
String result = null;
try {
httpClient = new SSLClient();
httpPost = new HttpPost(url);
//设置参数
httpPost.addHeader("Accept", "application/json");
httpPost.addHeader("Content-Type", "application/json;charset=UTF-8");
StringEntity stringEntity = new StringEntity(map);
stringEntity.setContentEncoding("UTF-8");
stringEntity.setContentType("application/json");
httpPost.setEntity(stringEntity);
HttpResponse response = httpClient.execute(httpPost);
if (response != null) {
HttpEntity resEntity = response.getEntity();
if (resEntity != null) {
result = EntityUtils.toString(resEntity, charset);
}
}
} catch (Exception ex) {
ex.printStackTrace();
}
return result;
}
}
#DB properties:
spring.datasource.url = jdbc:mysql://172.16.11.201:3306/dl_business_v3.0.1.3_pyh_0510?allowMultiQueries=true&serverTimezone=GMT%2B8&characterEncoding=utf8
spring.datasource.url = jdbc:mysql://172.16.11.201:3306/dl_business?allowMultiQueries=true&serverTimezone=GMT%2B8&characterEncoding=utf8
spring.datasource.username=root
spring.datasource.password=ENC(ymcOoS7xaghkc/E5jSK3Yi9Zz42LWTls9jVGpYgsRTqLxPpXfqkIXAtXHwCSPOcw)
spring.datasource.driver-class-name = com.mysql.cj.jdbc.Driver
......@@ -21,8 +21,8 @@ amos.system.user.product=STUDIO_APP_WEB
eureka.client.serviceUrl.defaultZone: http://${spring.security.user.name}:${spring.security.user.password}@172.16.11.201:10001/eureka/
eureka.instance.prefer-ip-address=true
management.security.enabled=true
management.endpoint.health.show-details=always
management.endpoints.web.exposure.include=*
eureka.instance.health-check-url-path=/actuator/health
eureka.instance.metadata-map.management.context-path=${server.servlet.context-path}/actuator
eureka.instance.status-page-url-path=/actuator/info
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment