(HttpServletRequest request, HttpServletResponse response, AuthenticationException authException)
| 184 | public AuthenticationEntryPoint authenticationEntryPoint() { |
| 185 | return new AuthenticationEntryPoint() { |
| 186 | @Override |
| 187 | public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException authException) throws IOException, ServletException { |
| 188 | if (!response.isCommitted()) {// 如果响应未已经提交;提交的响应未写入状态码和报头 |
| 189 | String message = authException.getMessage(); |
| 190 | if("Full authentication is required to access this resource".equals(authException.getMessage())){ |
| 191 | message = "需要登录用户才能访问此资源"; |
| 192 | } |
| 193 | if(Strings.CS.startsWith(authException.getMessage(), "Invalid access token")){//判断开始部分是否与二参数相同 |
| 194 | message = "无效的访问令牌"+Strings.CS.removeStart(authException.getMessage(), "Invalid access token"); |
| 195 | } |
| 196 | |
| 197 | //向Header头写入信息 |
| 198 | response.setHeader("message", UriUtils.encode(message,"UTF-8"));//不支持中文参数 用UriUtils.encode代替URLEncoder.encode,解决空格转换成+号的问题 |
| 199 | |
| 200 | response.sendError(401,//返回401错误 HttpServletResponse.SC_UNAUTHORIZED |
| 201 | authException.getMessage());//错误信息 |
| 202 | |
| 203 | } |
| 204 | } |
| 205 | |
| 206 | }; |
| 207 | } |
nothing calls this directly
no test coverage detected