【fix sonar】CASServiceUtil文件

This commit is contained in:
梁琦涛
2023-03-08 16:11:36 +08:00
parent 4b31e2083c
commit 1175ba0d57
@@ -1,14 +1,6 @@
package com.jero.modules.cas.util; package com.jero.modules.cas.util;
import java.io.BufferedReader; import lombok.extern.slf4j.Slf4j;
import java.io.IOException;
import java.io.InputStreamReader;
import java.security.cert.X509Certificate;
import javax.net.ssl.SSLContext;
import javax.net.ssl.TrustManager;
import javax.net.ssl.X509TrustManager;
import org.apache.http.HttpResponse; import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpGet; import org.apache.http.client.methods.HttpGet;
import org.apache.http.conn.socket.LayeredConnectionSocketFactory; import org.apache.http.conn.socket.LayeredConnectionSocketFactory;
@@ -16,15 +8,28 @@ import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
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 javax.net.ssl.SSLContext;
import javax.net.ssl.TrustManager;
import javax.net.ssl.X509TrustManager;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.security.cert.X509Certificate;
@Slf4j
public class CASServiceUtil { public class CASServiceUtil {
private CASServiceUtil(){
}
public static void main(String[] args) { public static void main(String[] args) {
String serviceUrl = "https://cas.8f8.com.cn:8443/cas/p3/serviceValidate"; String serviceUrl = "https://cas.8f8.com.cn:8443/cas/p3/serviceValidate";
String service = "http://localhost:3003/user/login"; String service = "http://localhost:3003/user/login";
String ticket = "ST-5-1g-9cNES6KXNRwq-GuRET103sm0-DESKTOP-VKLS8B3"; String ticket = "ST-5-1g-9cNES6KXNRwq-GuRET103sm0-DESKTOP-VKLS8B3";
String res = getSTValidate(serviceUrl,ticket, service); String res = getSTValidate(serviceUrl,ticket, service);
System.out.println("---------res-----"+res); log.info("---------res-----"+res);
} }
@@ -38,7 +43,7 @@ public class CASServiceUtil {
HttpGet httpget = new HttpGet(url); HttpGet httpget = new HttpGet(url);
HttpResponse response = httpclient.execute(httpget); HttpResponse response = httpclient.execute(httpget);
String res = readResponse(response); String res = readResponse(response);
return res == null ? null : ("".equals(res) ? null : res); return "".equals(res) ? null : res;
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
@@ -77,17 +82,19 @@ public class CASServiceUtil {
new X509TrustManager() { new X509TrustManager() {
@Override @Override
public X509Certificate[] getAcceptedIssuers() { public X509Certificate[] getAcceptedIssuers() {
return null; return new X509Certificate[0];
} }
@Override @Override
public void checkClientTrusted(X509Certificate[] certs, String authType) { public void checkClientTrusted(X509Certificate[] certs, String authType) {
// don't check // don't check
log.info("client");
} }
@Override @Override
public void checkServerTrusted(X509Certificate[] certs, String authType) { public void checkServerTrusted(X509Certificate[] certs, String authType) {
// don't check // don't check
log.info("server");
} }
} }
}; };