Commit b72cb1d5 authored by 赵啸非's avatar 赵啸非

提交配置校验

parent b9bd798e
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
<profiles.nacos.group>DEFAULT_GROUP</profiles.nacos.group> <profiles.nacos.group>DEFAULT_GROUP</profiles.nacos.group>
<profiles.nacos.namespace>smart-gov</profiles.nacos.namespace> <profiles.nacos.namespace>smart-gov</profiles.nacos.namespace>
<profiles.req.json.check>false</profiles.req.json.check> <profiles.req.json.check>false</profiles.req.json.check>
<profiles.trustedReferer></profiles.trustedReferer>
<package.environment>build</package.environment> <package.environment>build</package.environment>
<skipUi>true</skipUi> <skipUi>true</skipUi>
</properties> </properties>
...@@ -49,6 +50,7 @@ ...@@ -49,6 +50,7 @@
<profiles.server.debug>-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5513</profiles.server.debug> <profiles.server.debug>-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5513</profiles.server.debug>
<profiles.nacos.server-addr>192.168.0.252:8848</profiles.nacos.server-addr> <profiles.nacos.server-addr>192.168.0.252:8848</profiles.nacos.server-addr>
<profiles.req.json.check>true</profiles.req.json.check> <profiles.req.json.check>true</profiles.req.json.check>
<profiles.trustedReferer>192.168.0.98,localhost</profiles.trustedReferer>
</properties> </properties>
</profile> </profile>
......
package com.mortals.xhx.base.framework.interceptor; package com.mortals.xhx.base.framework.interceptor;
import cn.hutool.core.util.StrUtil; import cn.hutool.core.util.StrUtil;
import cn.hutool.core.util.URLUtil;
import cn.hutool.http.HttpStatus; import cn.hutool.http.HttpStatus;
import cn.hutool.http.HttpUtil;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.mortals.framework.annotation.UnAuth; import com.mortals.framework.annotation.UnAuth;
import com.mortals.framework.common.Rest; import com.mortals.framework.common.Rest;
...@@ -22,6 +24,9 @@ import org.springframework.web.servlet.resource.ResourceHttpRequestHandler; ...@@ -22,6 +24,9 @@ import org.springframework.web.servlet.resource.ResourceHttpRequestHandler;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URL;
import java.util.List; import java.util.List;
import static com.mortals.xhx.common.key.ErrorCode.*; import static com.mortals.xhx.common.key.ErrorCode.*;
...@@ -52,10 +57,12 @@ public class AuthUserInterceptor extends BaseInterceptor { ...@@ -52,10 +57,12 @@ public class AuthUserInterceptor extends BaseInterceptor {
throws Exception { throws Exception {
//response.setContentType("application/json"); //response.setContentType("application/json");
String referer = request.getHeader("Referer"); String referer = request.getHeader("Referer");
if (!ObjectUtils.isEmpty(referer)) { if (!ObjectUtils.isEmpty(referer)) {
referer = StrUtil.removeSuffix(referer, "/"); //校验host即可
URI host = URLUtil.getHost(new URL(referer));
referer = host.getHost();
//referer = StrUtil.removeSuffix(referer, "/");
List<String> trustReferers = StrUtil.split(trustedReferer, ","); List<String> trustReferers = StrUtil.split(trustedReferer, ",");
if (!ObjectUtils.isEmpty(trustReferers)) { if (!ObjectUtils.isEmpty(trustReferers)) {
if (!trustReferers.contains(referer)) { if (!trustReferers.contains(referer)) {
...@@ -128,4 +135,10 @@ public class AuthUserInterceptor extends BaseInterceptor { ...@@ -128,4 +135,10 @@ public class AuthUserInterceptor extends BaseInterceptor {
} }
public static void main(String[] args) throws MalformedURLException {
String url="http://192.168.0.1:9989";
URI host = URLUtil.getHost(new URL(url));
System.out.println(host.getHost());
}
} }
...@@ -49,4 +49,4 @@ application: ...@@ -49,4 +49,4 @@ application:
dm: dm:
enable: true enable: true
jsonCheck: @profiles.req.json.check@ jsonCheck: @profiles.req.json.check@
trustedReferer : http://192.168.0.98:11072,http://localhost:8080 trustedReferer : @profiles.trustedReferer@
\ No newline at end of file \ No newline at end of file
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