HashMap<String, Object> paramsMap = new HashMap<>();
72
            paramsMap.put("root_module","0000");
73
            paramsMap.put("userCode",user.getUserCode());
74
75
            Map<String, String> headerMap=new HashMap<>();
76
            // 取得cookie
77
            Cookie[] cookies = request.getCookies();
78
            if (cookies != null) {
79
                for (Cookie cookie : cookies) {
80
                    if (cookie.getName().equals("session_id")) {
81
                        headerMap.put("session_id", cookie.getValue());
82
                    }
83
                    if (cookie.getName().equals("sign")) {
84
                        headerMap.put("sign", cookie.getValue());
85
                    }
86
                    if (cookie.getName().equals("sign_key")) {
87
                        headerMap.put("sign_key", cookie.getValue());
88
                    }
89
                }
90
            }
91
            Map<String, String> headerMap1=new HashMap<>();
92
            //将设置拼接cookie
93
            headerMap1.put("Cookie","session_id="+headerMap.get("session_id")+";"+"sign="+headerMap.get("sign")+";"+"sign_key="+headerMap.get("sign_key"));
94
            // (1)设置字符集
95
            Charset charset = Charset.forName("utf-8");
96
97
            String result = HttpServiceUtil.sendPost(menuUrl, paramsMap, charset,headerMap1 );
98
            //将返回结果转为map
99
            resultMap = JSON.parseObject(result, Map.class);
100
101
            String result1 = (String)resultMap.get("RESULT");
102
            if(null!=result1&&!"".equals(result1)){
103
                //如果result有值返回正确,将返回结果转为List
104
                List<Map<String,List<Map>>> list = JSON.parseObject(result1, List.class);
105
                resultMap.put("RESULT",list);
106
            }
107
        } catch (Exception e) {
108
            logger.error("调用uspa获取菜单接口失败: " + e.getMessage());
109
110
            return resultMap;
111
        }
112
        return resultMap;
113
    }
114
115
}

+ 22 - 0
security-protection-service/src/main/java/com/ai/bss/security/protection/service/interfaces/LoginService.java

@ -0,0 +1,22 @@
1
package com.ai.bss.security.protection.service.interfaces;
2
3
4
5
import com.ai.bss.security.protection.model.User;
6
7
import javax.servlet.http.HttpServletRequest;
8
import java.util.Map;
9
10
/**
11
 * @Auther: 王超
12
 * @Date: 2020/12/24 15:12
13
 * @Description:
14
 */
15
public interface LoginService {
16
17
18
    Map<String, Object> findMenus(User user, HttpServletRequest request);
19
20
21
    Map<String, Object> login(User user);
22
}

+ 295 - 0
security-protection-service/src/main/java/com/ai/bss/security/protection/utils/HttpServiceUtil.java

@ -0,0 +1,295 @@
1
package com.ai.bss.security.protection.utils;
2
3
import com.alibaba.fastjson.JSONObject;
4
import org.apache.http.HttpEntity;
5
import org.apache.http.HttpStatus;
6
import org.apache.http.client.ClientProtocolException;
7
import org.apache.http.client.HttpClient;
8
import org.apache.http.client.config.RequestConfig;
9
import org.apache.http.client.methods.CloseableHttpResponse;
10
import org.apache.http.client.methods.HttpGet;
11
import org.apache.http.client.methods.HttpPost;
12
import org.apache.http.client.methods.HttpPut;
13
import org.apache.http.entity.StringEntity;
14
import org.apache.http.entity.mime.MultipartEntityBuilder;
15
import org.apache.http.impl.client.CloseableHttpClient;
16
import org.apache.http.impl.client.HttpClients;
17
import org.apache.http.protocol.HTTP;
18
import org.apache.http.util.EntityUtils;
19
import org.slf4j.Logger;
20
import org.slf4j.LoggerFactory;
21
import org.springframework.util.CollectionUtils;
22
23
import java.io.*;
24
import java.net.HttpURLConnection;
25
import java.net.URL;
26
import java.net.URLEncoder;
27
import java.nio.charset.Charset;
28
import java.util.Iterator;
29
import java.util.Map;
30
import java.util.Set;
31
32
/**
33
 * http服务请求工具类
34
 *
35
 * @author chencai
36
 */
37
public class HttpServiceUtil {
38
	static Logger log = LoggerFactory.getLogger(HttpServiceUtil.class);
39
40
	private static final String HTTP_CONTENT_TYPE_JSON = "application/json; charset=utf-8";
41
42
	public static String buildUrl(Map<String, String> paramMap, String serviceUrl) {
43
		String url = null;
44
		StringBuffer urlString = new StringBuffer();
45
		urlString.append(serviceUrl);
46
47
		if (!paramMap.isEmpty()) {
48
			// 参数列表不为空,地址尾部增加'?'
49
			urlString.append('?');
50
			// 拼接参数
51
			Set<Map.Entry<String, String>> entrySet = paramMap.entrySet();
52
			for (Map.Entry<String, String> entry : entrySet) {
53
				try {
54
					urlString.append(entry.getKey()).append('=').append(URLEncoder.encode(entry.getValue(), "UTF-8"))
55
							.append('&');
56
				} catch (UnsupportedEncodingException e) {
57
					log.error(" Exception: " + e);
58
				}
59
			}
60
			// 去掉最后一个字符“&”
61
			url = urlString.substring(0, urlString.length() - 1);
62
		}
63
		return url;
64
	}
65
66
	public static String sendRequest(String url) {
67
		InputStream inputStream = null;
68
		BufferedReader bufferedReader = null;
69
		HttpURLConnection httpURLConnection = null;
70
		try {
71
			log.error("It's not error. request url: " + url);
72
			URL requestURL = new URL(url);
73
			// 获取连接
74
			httpURLConnection = (HttpURLConnection) requestURL.openConnection();
75
			httpURLConnection.setConnectTimeout(10000); // 建立连接的超时时间,毫秒
76
			httpURLConnection.setReadTimeout(25000); // 获得返回的超时时间,毫秒
77
			httpURLConnection.setRequestMethod("GET");
78
			httpURLConnection.setRequestProperty("Content-type", "text/html;charset=UTF-8");
79
			httpURLConnection.setRequestProperty("Accept",
80
					"text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8");
81
			// 通过输入流获取请求的内容
82
			inputStream = httpURLConnection.getInputStream();
83
			bufferedReader = new BufferedReader(new InputStreamReader(inputStream, "UTF-8"));
84
			String temp = null;
85
			StringBuffer stringBuffer = new StringBuffer();
86
			// 循环读取返回的结果
87
			while ((temp = bufferedReader.readLine()) != null) {
88
				stringBuffer.append(temp);
89
			}
90
91
			return stringBuffer.toString();
92
		} catch (Exception e) {
93
			log.error("sendRequest Exception: " + e);
94
		} finally {
95
			// 断开连接
96
			if (httpURLConnection != null) {
97
				httpURLConnection.disconnect();
98
			}
99
			// 关闭流
100
			if (bufferedReader != null) {
101
				try {
102
					bufferedReader.close();
103
				} catch (IOException e) {
104
					log.error("bufferedReader Exception: " + e);
105
				}
106
			}
107
			if (inputStream != null) {
108
				try {
109
					inputStream.close();
110
				} catch (IOException e) {
111
					log.error("inputStream Exception: " + e);
112
				}
113
			}
114
		}
115
		return null;
116
	}
117
118
	public static String sendPostRequest(String url, Map<String, String> map, String encoding) {
119
		String retStr = "";
120
		try {
121
			retStr = sendPostRequest(url, map, encoding, 0, 0);
122
		} catch (Exception ex) {
123
			log.error("sendPostRequest error: " + ex);
124
		}
125
126
		return retStr;
127
	}
128
129
	public static String sendPostRequest(String url, Map<String, String> map, String encoding, int ebossConnectTimeout,
130
			int ebossServiceTimeout) {
131
		CloseableHttpClient httpClient = HttpClients.createDefault();
132
		HttpPost httpPost = new HttpPost(url);
133
		String body = "";
134
135
		try {
136
			MultipartEntityBuilder multipartEntityBuilder = MultipartEntityBuilder.create();
137
			if (map != null) {
138
				for (Map.Entry<String, String> entry : map.entrySet()) {
139
					multipartEntityBuilder.addTextBody(entry.getKey(), entry.getValue());
140
				}
141
			}
142
143
			log.debug("ebossConnectTimeout:" + ebossConnectTimeout);
144
			log.debug("ebossServiceTimeout:" + ebossServiceTimeout);
145
146
			httpPost.setEntity(multipartEntityBuilder.build());
147
			if (ebossConnectTimeout != 0 && ebossServiceTimeout != 0) {
148
				RequestConfig requestConfig = RequestConfig.custom().setSocketTimeout(ebossServiceTimeout)
149
						.setConnectTimeout(ebossConnectTimeout).build();// 设置请求和传输超时时间
150
				httpPost.setConfig(requestConfig);
151
			}
152
153
			CloseableHttpResponse response = httpClient.execute(httpPost);
154
155
			if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
156
				HttpEntity entity = response.getEntity();
157
				if (entity != null) {
158
					// 按指定编码转换结果实体为String类型
159
					body = EntityUtils.toString(entity, encoding);
160
				}
161
				EntityUtils.consume(entity);
162
			}
163
		} catch (ClientProtocolException e) {
164
			log.error("ClientProtocolException Exception: " + e);
165
		} catch (UnsupportedEncodingException e) {
166
			log.error("UnsupportedEncodingException Exception: " + e);
167
		} catch (IOException e) {
168
			log.error("IOException Exception: " + e);
169
			// throw new BaseException("10", "调用Eboss超时");
170
		} finally {
171
			// 关闭连接,释放资源
172
			try {
173
				httpClient.close();
174
			} catch (IOException e) {
175
				log.error("httpClient Exception: " + e);
176
			}
177
		}
178
179
		return body;
180
	}
181
182
	public static String sendGet(String url, Charset encoding, Map<String, String> headerMap) {
183
		HttpClient httpClient = HttpClients.createDefault();
184
		HttpGet httpGet = new HttpGet(url);
185
		httpGet.addHeader(HTTP.CONTENT_TYPE, HTTP_CONTENT_TYPE_JSON);
186
		CloseableHttpResponse response = null;
187
		try {
188
			log.debug("执行GET请求:url= " + url);
189
			response = (CloseableHttpResponse) httpClient.execute(httpGet);
190
		} catch (Exception e) {
191
			log.error("sendGet Exception: " + e.getMessage());
192
			return "{}";
193
		}
194
		return responseEx(httpClient, response, encoding);
195
	}
196
197
	public static String sendPost(String url, Map<String, Object> paramsMap, Charset encoding) {
198
		HttpClient httpClient = HttpClients.createDefault();
199
		HttpPost httpPost = new HttpPost(url);
200
		httpPost.addHeader(HTTP.CONTENT_TYPE, HTTP_CONTENT_TYPE_JSON);
201
		if (!CollectionUtils.isEmpty(paramsMap)) {
202
			StringEntity se = new StringEntity(JSONObject.toJSONString(paramsMap), encoding);
203
			httpPost.setEntity(se);
204
		}
205
		CloseableHttpResponse response = null;
206
		try {
207
			log.debug("执行POST无参请求:url= " + url);
208
			response = (CloseableHttpResponse) httpClient.execute(httpPost);
209
		} catch (Exception e) {
210
			log.error("sendPost Exception: " + e.getMessage());
211
			return "{}";
212
		}
213
		return responseEx(httpClient, response, encoding);
214
	}
215
216
	public static String sendPost(String url, Map<String, Object> paramsMap, Charset encoding,
217
			Map<String, String> headerMap) {
218
		HttpClient httpClient = HttpClients.createDefault();
219
		HttpPost httpPost = new HttpPost(url);
220
221
		Iterator<String> iter = headerMap.keySet().iterator();
222
		String key = "";
223
		String value = "";
224
		while (iter.hasNext()) {
225
			key = iter.next();
226
			value = headerMap.get(key);
227
			httpPost.setHeader(key, value);
228
		}
229
230
		httpPost.addHeader(HTTP.CONTENT_TYPE, HTTP_CONTENT_TYPE_JSON);
231
		if (!CollectionUtils.isEmpty(paramsMap)) {
232
			log.debug("执行POST请求:url= " + url + ",参数= " + JSONObject.toJSONString(paramsMap));
233
			StringEntity se = new StringEntity(JSONObject.toJSONString(paramsMap), encoding);
234
			httpPost.setEntity(se);
235
		}
236
		CloseableHttpResponse response = null;
237
		try {
238
			response = (CloseableHttpResponse) httpClient.execute(httpPost);
239
		} catch (Exception e) {
240
			log.error("sendPost Exception: " + e.getMessage());
241
			return "{}";
242
		}
243
		return responseEx(httpClient, response, encoding);
244
	}
245
246
	public static String sendPut(String url, Map<String, Object> paramsMap, Charset encoding) {
247
		HttpClient httpClient = HttpClients.createDefault();
248
		String resp = "";
249
		HttpPut httpPut = new HttpPut(url);
250
		httpPut.addHeader(HTTP.CONTENT_TYPE, HTTP_CONTENT_TYPE_JSON);
251
		if (!CollectionUtils.isEmpty(paramsMap)) {
252
			StringEntity se = new StringEntity(JSONObject.toJSONString(paramsMap), encoding);
253
			httpPut.setEntity(se);
254
		}
255
		CloseableHttpResponse response = null;
256
		try {
257
			log.debug("执行PUT请求:url= " + url + ",参数= " + JSONObject.toJSONString(paramsMap));
258
			response = (CloseableHttpResponse) httpClient.execute(httpPut);
259
		} catch (Exception e) {
260
			log.error("sendPut Exception: " + e.getMessage());
261
			return "{}";
262
		}
263
264
		return responseEx(httpClient, response, encoding);
265
	}
266
267
	private static String responseEx(HttpClient httpClient, CloseableHttpResponse response, Charset encoding) {
268
		String resp = "";
269
		try {
270
			if (response == null) {
271
				resp = "{}";
272
				log.error("请求执行失败,无返回信息");
273
			} else if (200 != response.getStatusLine().getStatusCode()) {
274
				resp = "{}";
275
				log.error("请求执行失败,状态码=" + response.getStatusLine().getStatusCode() + ",返回信息="
276
						+ EntityUtils.toString(response.getEntity(), encoding));
277
			} else {
278
				log.debug("请求执行成功");
279
				resp = EntityUtils.toString(response.getEntity(), encoding);
280
			}
281
		} catch (Exception e) {
282
			log.error("responseEx Exception: " + e.getMessage());
283
		} finally {
284
			if (response != null) {
285
				try {
286
					response.close();
287
				} catch (Exception e) {
288
					log.error("responseEx Exception: " + e.getMessage());
289
				}
290
			}
291
		}
292
		return resp;
293
	}
294
295
}

+ 5 - 0
security-protection-service/src/main/resources/application.properties

@ -89,3 +89,8 @@ spring.servlet.multipart.resolve-lazily=false
89 89
# LOGGING
90 90
logging.level.com.ai=debug
91 91
logging.level.org.springframework.data=debug
92
93
uspa.login.url=http://10.19.90.34:20000/usermng/login
94
uspa.login.vercode=Hiz#8uAqkjhoPmXu8%aaa
95
96
uspa.login.menuUrl=http://10.19.90.34:20000/usermng/process/com.wframe.usermanager.services.impl.QueryMenuByUser

@laijj@dev分支调整 · a7b6707875 - Nuosi Git Service
Browse Source

@laijj@dev分支调整

赖骏劼 2 years ago
parent
commit
a7b6707875
2 changed files with 6 additions and 2 deletions
  1. 2 1
      .gitignore
  2. 4 1
      show-client/settings.gradle

+ 2 - 1
.gitignore

6
.idea/
6
.idea/
7
.gradle/
7
.gradle/
8
target/
8
target/
9
logs/
9
logs/
10
local.properties

+ 4 - 1
show-client/settings.gradle

3
include ':app'
3
include ':app'
4
rootProject.name='show-client'
4
rootProject.name='show-client'
5
5
6
include ':ipu-watermark'
6
//include ':ipu-plugin-basic'
7
//project(':ipu-plugin-basic').projectDir = new File(rootProject.projectDir,'../../android-plugin/ipu-plugin-basic')
8
//include 'ipu-watermark'
9
//project(':ipu-watermark').projectDir = new File(rootProject.projectDir,'../../android-plugin/ipu-watermark')