RuoYi 5 anni fa
parent
commit
5c51cbc07c

+ 0 - 184
ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/utils/web/WebUtils.java

@@ -1,184 +0,0 @@
1
-package com.ruoyi.common.core.utils.web;
2
-
3
-import com.alibaba.fastjson.JSON;
4
-import com.ruoyi.common.core.exception.CheckedException;
5
-import org.bouncycastle.util.encoders.Base64;
6
-import org.slf4j.Logger;
7
-import org.slf4j.LoggerFactory;
8
-import org.springframework.http.HttpHeaders;
9
-import org.springframework.http.MediaType;
10
-import org.springframework.http.server.reactive.ServerHttpRequest;
11
-import org.springframework.util.Assert;
12
-import org.springframework.web.bind.annotation.ResponseBody;
13
-import org.springframework.web.context.request.RequestContextHolder;
14
-import org.springframework.web.context.request.ServletRequestAttributes;
15
-import org.springframework.web.method.HandlerMethod;
16
-
17
-import javax.servlet.http.Cookie;
18
-import javax.servlet.http.HttpServletRequest;
19
-import javax.servlet.http.HttpServletResponse;
20
-import java.io.IOException;
21
-import java.io.PrintWriter;
22
-import java.io.UnsupportedEncodingException;
23
-import java.nio.charset.StandardCharsets;
24
-
25
-public class WebUtils extends org.springframework.web.util.WebUtils
26
-{
27
-    private final Logger logger = LoggerFactory.getLogger(WebUtils.class);
28
-
29
-    private static final String BASIC_ = "Basic ";
30
-
31
-//    /**
32
-//     * 判断是否ajax请求 spring ajax 返回含有 ResponseBody 或者 RestController注解
33
-//     *
34
-//     * @param handlerMethod HandlerMethod
35
-//     * @return 是否ajax请求
36
-//     */
37
-//    public boolean isBody(HandlerMethod handlerMethod)
38
-//    {
39
-//        ResponseBody responseBody = ClassUtils.getAnnotation(handlerMethod, ResponseBody.class);
40
-//        return responseBody != null;
41
-//    }
42
-
43
-    /**
44
-     * 读取cookie
45
-     *
46
-     * @param name cookie name
47
-     * @return cookie value
48
-     */
49
-    public String getCookieVal(String name)
50
-    {
51
-        HttpServletRequest request = WebUtils.getRequest();
52
-        Assert.notNull(request, "request from RequestContextHolder is null");
53
-        return getCookieVal(request, name);
54
-    }
55
-
56
-    /**
57
-     * 读取cookie
58
-     *
59
-     * @param request HttpServletRequest
60
-     * @param name cookie name
61
-     * @return cookie value
62
-     */
63
-    public String getCookieVal(HttpServletRequest request, String name)
64
-    {
65
-        Cookie cookie = getCookie(request, name);
66
-        return cookie != null ? cookie.getValue() : null;
67
-    }
68
-
69
-    /**
70
-     * 清除 某个指定的cookie
71
-     *
72
-     * @param response HttpServletResponse
73
-     * @param key cookie key
74
-     */
75
-    public void removeCookie(HttpServletResponse response, String key)
76
-    {
77
-        setCookie(response, key, null, 0);
78
-    }
79
-
80
-    /**
81
-     * 设置cookie
82
-     *
83
-     * @param response HttpServletResponse
84
-     * @param name cookie name
85
-     * @param value cookie value
86
-     * @param maxAgeInSeconds maxage
87
-     */
88
-    public void setCookie(HttpServletResponse response, String name, String value, int maxAgeInSeconds)
89
-    {
90
-        Cookie cookie = new Cookie(name, value);
91
-        cookie.setPath("/");
92
-        cookie.setMaxAge(maxAgeInSeconds);
93
-        cookie.setHttpOnly(true);
94
-        response.addCookie(cookie);
95
-    }
96
-
97
-    /**
98
-     * 获取 HttpServletRequest
99
-     *
100
-     * @return {HttpServletRequest}
101
-     */
102
-    public static HttpServletRequest getRequest()
103
-    {
104
-        return ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
105
-    }
106
-
107
-    /**
108
-     * 获取 HttpServletResponse
109
-     *
110
-     * @return {HttpServletResponse}
111
-     */
112
-    public HttpServletResponse getResponse()
113
-    {
114
-        return ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getResponse();
115
-    }
116
-
117
-    /**
118
-     * 返回json
119
-     *
120
-     * @param response HttpServletResponse
121
-     * @param result 结果对象
122
-     */
123
-    public void renderJson(HttpServletResponse response, Object result)
124
-    {
125
-        renderJson(response, result, MediaType.APPLICATION_JSON_VALUE);
126
-    }
127
-
128
-    /**
129
-     * 返回json
130
-     *
131
-     * @param response HttpServletResponse
132
-     * @param result 结果对象
133
-     * @param contentType contentType
134
-     */
135
-    public void renderJson(HttpServletResponse response, Object result, String contentType)
136
-    {
137
-        response.setCharacterEncoding("UTF-8");
138
-        response.setContentType(contentType);
139
-        try (PrintWriter out = response.getWriter())
140
-        {
141
-            out.append(JSON.toJSONString(result));
142
-        }
143
-        catch (IOException e)
144
-        {
145
-            logger.error(e.getMessage(), e);
146
-        }
147
-    }
148
-
149
-    /**
150
-     * 从request 获取CLIENT_ID
151
-     *
152
-     * @return
153
-     * @throws UnsupportedEncodingException
154
-     */
155
-    public static String[] getClientId(ServerHttpRequest request) throws UnsupportedEncodingException
156
-    {
157
-        String header = request.getHeaders().getFirst(HttpHeaders.AUTHORIZATION);
158
-
159
-        if (header == null || !header.startsWith(BASIC_))
160
-        {
161
-            throw new CheckedException("请求头中client信息为空");
162
-        }
163
-        byte[] base64Token = header.substring(6).getBytes("UTF-8");
164
-        byte[] decoded;
165
-        try
166
-        {
167
-            decoded = Base64.decode(base64Token);
168
-        }
169
-        catch (IllegalArgumentException e)
170
-        {
171
-            throw new CheckedException("Failed to decode basic authentication token");
172
-        }
173
-
174
-        String token = new String(decoded, StandardCharsets.UTF_8);
175
-
176
-        int delim = token.indexOf(":");
177
-
178
-        if (delim == -1)
179
-        {
180
-            throw new CheckedException("Invalid basic authentication token");
181
-        }
182
-        return new String[] { token.substring(0, delim), token.substring(delim + 1) };
183
-    }
184
-}

+ 1 - 0
ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/web/controller/BaseController.java

@@ -70,6 +70,7 @@ public class BaseController
70 70
         TableDataInfo rspData = new TableDataInfo();
71 71
         rspData.setCode(HttpStatus.SUCCESS);
72 72
         rspData.setRows(list);
73
+        rspData.setMsg("查询成功");
73 74
         rspData.setTotal(new PageInfo(list).getTotal());
74 75
         return rspData;
75 76
     }

+ 0 - 12
ruoyi-gateway/src/main/java/com/ruoyi/gateway/filter/ValidateCodeFilter.java

@@ -1,7 +1,5 @@
1 1
 package com.ruoyi.gateway.filter;
2 2
 
3
-import com.ruoyi.common.core.utils.web.WebUtils;
4
-import com.ruoyi.gateway.config.properties.IgnoreClientProperties;
5 3
 import org.springframework.beans.factory.annotation.Autowired;
6 4
 import org.springframework.cloud.gateway.filter.GatewayFilter;
7 5
 import org.springframework.cloud.gateway.filter.factory.AbstractGatewayFilterFactory;
@@ -27,9 +25,6 @@ public class ValidateCodeFilter extends AbstractGatewayFilterFactory<Object>
27 25
     @Autowired
28 26
     private ValidateCodeService validateCodeService;
29 27
 
30
-    @Autowired
31
-    private IgnoreClientProperties ignoreClient;
32
-
33 28
     @Override
34 29
     public GatewayFilter apply(Object config)
35 30
     {
@@ -43,13 +38,6 @@ public class ValidateCodeFilter extends AbstractGatewayFilterFactory<Object>
43 38
             }
44 39
             try
45 40
             {
46
-                // swagger的oauth2.0验证码放行操作
47
-                String[] clientInfos = WebUtils.getClientId(request);
48
-                if (ignoreClient.getClients().contains(clientInfos[0]))
49
-                {
50
-                    return chain.filter(exchange);
51
-                }
52
-
53 41
                 validateCodeService.checkCapcha(request.getQueryParams().getFirst("code"),
54 42
                         request.getQueryParams().getFirst("uuid"));
55 43
             }

+ 1 - 1
ruoyi-modules/ruoyi-system/src/main/resources/mapper/system/SysDictDataMapper.xml

@@ -107,7 +107,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
107 107
  			<if test="createBy != null and createBy != ''">create_by,</if>
108 108
  			create_time
109 109
  		)values(
110
- 		    <if test="dictSort != null and dictSort != ''">#{dictSort},</if>
110
+ 		    <if test="dictSort != null">#{dictSort},</if>
111 111
  		    <if test="dictLabel != null and dictLabel != ''">#{dictLabel},</if>
112 112
  			<if test="dictValue != null and dictValue != ''">#{dictValue},</if>
113 113
  			<if test="dictType != null and dictType != ''">#{dictType},</if>