From d6b851a6165fd339410361e352b9a79cafde3e97 Mon Sep 17 00:00:00 2001 From: thinkgem Date: Sat, 29 Feb 2020 18:53:43 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=20web.jsonp.enabled=20?= =?UTF-8?q?=E5=8F=82=E6=95=B0=EF=BC=8C=E9=BB=98=E8=AE=A4=E4=B8=8D=E5=BC=80?= =?UTF-8?q?=E5=90=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../jeesite/common/web/http/ServletUtils.java | 22 ++++++++++--------- .../main/resources/config/jeesite-core.yml | 12 ++++++---- web/src/main/resources/config/application.yml | 10 ++++++--- 3 files changed, 27 insertions(+), 17 deletions(-) diff --git a/common/src/main/java/com/jeesite/common/web/http/ServletUtils.java b/common/src/main/java/com/jeesite/common/web/http/ServletUtils.java index 74dc8dfa..be5d2820 100644 --- a/common/src/main/java/com/jeesite/common/web/http/ServletUtils.java +++ b/common/src/main/java/com/jeesite/common/web/http/ServletUtils.java @@ -215,12 +215,13 @@ public class ServletUtils { if (response != null){ response.setContentType(MediaType.APPLICATION_JSON_UTF8_VALUE); } - String functionName = request.getParameter("__callback"); - if (StringUtils.isNotBlank(functionName)){ - return JsonMapper.toJsonp(functionName, resultMap); - }else{ - return JsonMapper.toJson(resultMap); + if (ObjectUtils.toBoolean(PropertiesUtils.getInstance().getProperty("web.jsonp.enabled"))) { + String functionName = request.getParameter("__callback"); + if (StringUtils.isNotBlank(functionName)){ + return JsonMapper.toJsonp(functionName, resultMap); + } } + return JsonMapper.toJson(resultMap); } }else{ if (response != null){ @@ -267,12 +268,13 @@ public class ServletUtils { .equalsIgnoreCase(request.getParameter("__ajax"), "xml")){ return renderString(response, XmlMapper.toXml(object)); }else{ - String functionName = request.getParameter("__callback"); - if (StringUtils.isNotBlank(functionName)){ - return renderString(response, JsonMapper.toJsonp(functionName, object)); - }else{ - return renderString(response, JsonMapper.toJson(object)); + if (ObjectUtils.toBoolean(PropertiesUtils.getInstance().getProperty("web.jsonp.enabled"))) { + String functionName = request.getParameter("__callback"); + if (StringUtils.isNotBlank(functionName)){ + return renderString(response, JsonMapper.toJsonp(functionName, object)); + } } + return renderString(response, JsonMapper.toJson(object)); } } diff --git a/modules/core/src/main/resources/config/jeesite-core.yml b/modules/core/src/main/resources/config/jeesite-core.yml index 4b0e5e9e..44e16c92 100644 --- a/modules/core/src/main/resources/config/jeesite-core.yml +++ b/modules/core/src/main/resources/config/jeesite-core.yml @@ -350,18 +350,18 @@ shiro: # 是否允许嵌入到外部网站iframe中(true:不限制,false:不允许) isAllowExternalSiteIframe: true - # 是否允许跨域访问,如果允许,设置允许的域名,全部域名设置*号,如果不允许,此设置应该为空 + # 是否允许跨域访问 CORS,如果允许,设置允许的域名,全部域名设置*号,如果不允许,此设置应该为空 # accessControlAllowOrigin: http://demo.jeesite.com # accessControlAllowOrigin: '*' - # 允许跨域访问时,可以使用的方法和响应头 + # 允许跨域访问时 CORS,可以使用的方法和响应头 # accessControlAllowMethods: GET, POST, OPTIONS # accessControlAllowHeaders: Origin, No-Cache, X-Requested-With, If-Modified-Since, Pragma, Last-Modified, Cache-Control, Expires, Content-Type, X-E4M-With - # 是否允许接收跨域的Cookie凭证数据 + # 是否允许接收跨域的Cookie凭证数据 CORS # accessControlAllowCredentials: true - # 允许的网站来源地址,不设置为全部地址(避免一些跨站点请求伪造CSRF) + # 允许的网站来源地址,不设置为全部地址(避免一些跨站点请求伪造 CSRF) # allowReferers: http://127.0.0.1,http://localhost # allowReferers: ~ @@ -506,6 +506,10 @@ web: id: '[a-zA-Z0-9_\-/#\u4e00-\u9fa5]{0,64}' user.loginCode: '[a-zA-Z0-9_\u4e00-\u9fa5]{4,20}' + # 默认不启用(为兼用旧版保留,建议使用 CORS) + jsonp: + enabled: false + # 核心模块的Web功能(仅作为微服务时设为false) core: enabled: true diff --git a/web/src/main/resources/config/application.yml b/web/src/main/resources/config/application.yml index 3ac602b6..00b46443 100644 --- a/web/src/main/resources/config/application.yml +++ b/web/src/main/resources/config/application.yml @@ -389,14 +389,18 @@ shiro: # # 是否允许嵌入到外部网站iframe中(true:不限制,false:不允许) # isAllowExternalSiteIframe: true # -# # 是否允许跨域访问,如果允许,设置允许的域名,全部域名设置*号,如果不允许,此设置应该为空 +# # 是否允许跨域访问 CORS,如果允许,设置允许的域名,全部域名设置*号,如果不允许,此设置应该为空 ## accessControlAllowOrigin: http://demo.jeesite.com ## accessControlAllowOrigin: '*' # -# # 是否允许接收跨域的Cookie凭证数据 +# # 允许跨域访问时 CORS,可以使用的方法和响应头 +# accessControlAllowMethods: GET, POST, OPTIONS +# accessControlAllowHeaders: Origin, No-Cache, X-Requested-With, If-Modified-Since, Pragma, Last-Modified, Cache-Control, Expires, Content-Type, X-E4M-With +# +# # 是否允许接收跨域的Cookie凭证数据 CORS ## accessControlAllowCredentials: true # -# # 允许的网站来源地址,不设置为全部地址(避免一些跨站点请求伪造CSRF) +# # 允许的网站来源地址,不设置为全部地址(避免一些跨站点请求伪造 CSRF) # allowReferers: http://127.0.0.1,http://localhost # allowReferers: ~ #