Commit ca103731c721aae3f5f622e58c679ed5c09fd9e9
1 parent
512b0cc8
fix response `content-type` is not set if access without access token
Showing
1 changed file
with
4 additions
and
0 deletions
src/main/java/com/genersoft/iot/vmp/conf/security/AnonymousAuthenticationEntryPoint.java
| ... | ... | @@ -3,6 +3,7 @@ package com.genersoft.iot.vmp.conf.security; |
| 3 | 3 | import com.alibaba.fastjson2.JSONObject; |
| 4 | 4 | import com.genersoft.iot.vmp.conf.security.dto.JwtUser; |
| 5 | 5 | import com.genersoft.iot.vmp.vmanager.bean.ErrorCode; |
| 6 | +import org.springframework.http.MediaType; | |
| 6 | 7 | import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; |
| 7 | 8 | import org.springframework.security.core.AuthenticationException; |
| 8 | 9 | import org.springframework.security.core.context.SecurityContextHolder; |
| ... | ... | @@ -12,6 +13,7 @@ import org.springframework.stereotype.Component; |
| 12 | 13 | import javax.servlet.http.HttpServletRequest; |
| 13 | 14 | import javax.servlet.http.HttpServletResponse; |
| 14 | 15 | import java.io.IOException; |
| 16 | +import java.nio.charset.StandardCharsets; | |
| 15 | 17 | |
| 16 | 18 | /** |
| 17 | 19 | * 处理匿名用户访问逻辑 |
| ... | ... | @@ -35,6 +37,8 @@ public class AnonymousAuthenticationEntryPoint implements AuthenticationEntry |
| 35 | 37 | jsonObject.put("msg", e.getMessage()); |
| 36 | 38 | } |
| 37 | 39 | response.setStatus(HttpServletResponse.SC_UNAUTHORIZED); |
| 40 | + response.setContentType(MediaType.APPLICATION_JSON_VALUE); | |
| 41 | + response.setCharacterEncoding(StandardCharsets.UTF_8.name()); | |
| 38 | 42 | try { |
| 39 | 43 | response.getWriter().print(jsonObject.toJSONString()); |
| 40 | 44 | } catch (IOException ioException) { | ... | ... |