Commit 381807bd authored by guozhipeng's avatar guozhipeng

authorization添加

parent 6d2de307
......@@ -3,8 +3,8 @@
"routes": [
{
"source": "^/index.html(#.*)?$",
"target": "/main/webapp/index.html$1",
"localDir": ".",
"target": "/index.html$1",
"localDir": "./main/webapp",
"cacheControl": "no-cache, no-store, must-revalidate"
},
{
......
......@@ -326,7 +326,7 @@ public class HttpClientUtil {
/**
* OData批量操作,可以使用超长OData拼接的URL
*/
public static String odataV4Batch(String url) throws Exception {
public static String odataV4Batch(String url, String authorization) throws Exception {
CloseableHttpClient httpclient = HttpClients.createDefault();
try {
url = HTTPUtil.urlEncode(url);
......@@ -393,6 +393,10 @@ public class HttpClientUtil {
String resStr = null;
HttpPost httppost = new HttpPost(serviceUrl + "$batch");
if (authorization != null && !"".equals(authorization)) {
//添加鉴权 authorization Basic c2FiaW5lOnBhc3Nfc2FiaW5l
httppost.setHeader("authorization", authorization);
}
// 请求参数配置
RequestConfig requestConfig = RequestConfig.custom()
......@@ -444,7 +448,7 @@ public class HttpClientUtil {
* 带参数的视图只能使用get请求
* 参数值中如果有#需要转义
*/
public static String odataV4BatchGet(String url) throws Exception {
public static String odataV4BatchGet(String url, String authorization) throws Exception {
try {
url = HTTPUtil.urlEncode(url);
if (true) {// odata v4 query处理
......@@ -512,6 +516,10 @@ public class HttpClientUtil {
HttpClient client = HttpClients.createDefault();
log.info("[odataV4BatchGet-url]" + url);
HttpGet httpGet = new HttpGet(url);// 创建Get请求
if (authorization != null && !"".equals(authorization)) {
//添加鉴权 authorization Basic c2FiaW5lOnBhc3Nfc2FiaW5l
httpGet.setHeader("authorization", authorization);
}
HttpResponse response = client.execute(httpGet);
int status = response.getStatusLine().getStatusCode();
HttpEntity resEntity = response.getEntity();
......@@ -548,8 +556,8 @@ public class HttpClientUtil {
* @return
* @throws Exception
*/
public static String odataV4BatchLocal(String url) throws Exception {
return odataV4Batch("http://localhost:" + getHttpPort + "/odata/v4/" + url);
public static String odataV4BatchLocal(String url, String authorization) throws Exception {
return odataV4Batch("http://localhost:" + getHttpPort + "/odata/v4/" + url, authorization);
}
/**
......@@ -559,8 +567,8 @@ public class HttpClientUtil {
* @return
* @throws Exception
*/
public static String odataV4BatchLocalGet(String url) throws Exception {
return odataV4BatchGet("http://localhost:" + getHttpPort + "/odata/v4/" + url);
public static String odataV4BatchLocalGet(String url, String authorization) throws Exception {
return odataV4BatchGet("http://localhost:" + getHttpPort + "/odata/v4/" + url, authorization);
}
/**
......
......@@ -216,7 +216,9 @@ public class CommonController {
*/
@PostMapping(value = "/getRuleCdsList")
public Result<?> getRuleCdsList(@RequestBody JSONObject jsonObject, HttpServletRequest req) {
String authorization = req.getHeader("authorization");//鉴权
String language = req.getHeader("language");//语言
jsonObject.put("authorization", authorization);
Result<?> re = commonService.getUserLogin(jsonObject, req);
if (re.isSuccess()) {
String userLoginPartyId = ((UserLogin) re.getResult()).getPartyId();
......@@ -292,6 +294,8 @@ public class CommonController {
@PostMapping(value = "/invokeByCdsView")
public Result<?> invokeByCdsView(@RequestBody JSONObject jsonObject, HttpServletRequest req) {
String language = req.getHeader("language");//语言
String authorization = req.getHeader("authorization");//鉴权
jsonObject.put("authorization", authorization);
//return Result.ok("该接口不对外开放,禁止调用!");
return commonService.invokeByCdsView(jsonObject, language);
}
......
......@@ -124,6 +124,8 @@ public class CommonServiceImpl implements CommonService {
*/
@Override
public Result<?> getRuleCdsList(JSONObject jsonObject, String language) {
String authorization = jsonObject.getString("authorization");// 鉴权
//log.info("[getRuleCdsList-language]" + language);
// 分页
int pageNo = 1;// pageNo: 1 当前页
......@@ -293,6 +295,8 @@ public class CommonServiceImpl implements CommonService {
if (urlRule2.contains(".")) {//服务查询 (视图查询封装在方法invokeByCdsView中)
try {
JSONObject paramRule2Json = JSONObject.parseObject(paramRule2);
//authorization
paramRule2Json.put("authorization", authorization);
JSONObject jsonObject2 = new JSONObject();
jsonObject2.put("classMethod", urlRule2);//类名.方法名
jsonObject2.put("param", paramRule2Json);//参数
......@@ -416,9 +420,9 @@ public class CommonServiceImpl implements CommonService {
try {
String resStr = null;
if (isOdataGet) {
resStr = HttpClientUtil.odataV4BatchLocalGet(url1);//GET请求 带参数的视图
resStr = HttpClientUtil.odataV4BatchLocalGet(url1, authorization);//GET请求 带参数的视图
} else {
resStr = HttpClientUtil.odataV4BatchLocal(url1);//POST请求
resStr = HttpClientUtil.odataV4BatchLocal(url1, authorization);//POST请求
}
resultJson1 = JSONObject.parseObject(resStr);
//失败!
......@@ -465,6 +469,8 @@ public class CommonServiceImpl implements CommonService {
colParamRuleJson = JSONObject.parseObject(colParamRule);
}
colParamRuleJson.put("list", list);//类型 List<Object>
//authorization
colParamRuleJson.put("authorization", authorization);
JSONObject colJson = new JSONObject();
colJson.put("classMethod", colUrlRule);//类名.方法名
colJson.put("param", colParamRuleJson);//参数
......@@ -591,6 +597,7 @@ public class CommonServiceImpl implements CommonService {
*/
@Override
public Result<?> getRequestParamRuleCdsList(JSONObject jsonObject, String language) {
String authorization = jsonObject.getString("authorization");//鉴权
String ruleMsg = "";
// 权限
......@@ -716,6 +723,8 @@ public class CommonServiceImpl implements CommonService {
if (urlRule2.contains(".")) {//服务查询 (视图查询封装在方法invokeByCdsView中)
try {
JSONObject paramRule2Json = JSONObject.parseObject(paramRule2);
//authorization
paramRule2Json.put("authorization", authorization);
JSONObject jsonObject2 = new JSONObject();
jsonObject2.put("classMethod", urlRule2);//类名.方法名
jsonObject2.put("param", paramRule2Json);//参数
......@@ -1058,13 +1067,14 @@ public class CommonServiceImpl implements CommonService {
*/
@Override
public Result<?> invokeByCdsView(JSONObject jsonObject, String language) {
String authorization = jsonObject.getString("authorization");//鉴权
try {
String urlRule = (String) jsonObject.get("url");
String paramRule = (String) jsonObject.get("param");
String url2 = urlRule + "?" + paramRule;
log.info("[odata-url2]" + url2);
JSONObject resultJson2 = null;
String resStr = HttpClientUtil.odataV4BatchLocal(url2);
String resStr = HttpClientUtil.odataV4BatchLocal(url2, authorization);
resultJson2 = JSONObject.parseObject(resStr);
log.info("[odata-value2]" + resultJson2.get("value"));
List<Object> list = (List<Object>) resultJson2.get("value");
......
......@@ -7,6 +7,6 @@ class HttpClientUtilTest {
@Test
void odataBatch() throws Exception {
// System.out.println(HttpClientUtil.odataV4Batch("http://localhost:8080/odata/v4/orderService/OrderHeaderItemView?$filter=docId eq 'S1711936526854'"));
System.out.println(HttpClientUtil.odataV4Batch("http://localhost:8080/odata/v4/orderService/OrderHeaderItemView?$filter=docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854'"));
System.out.println(HttpClientUtil.odataV4Batch("http://localhost:8080/odata/v4/orderService/OrderHeaderItemView?$filter=docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854' or docId eq 'S1711936526854'", null));
}
}
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