提交 | 用户 | 时间
|
e57a89
|
1 |
package com.jcdm.framework.security.handle; |
懒 |
2 |
|
|
3 |
import java.io.IOException; |
|
4 |
import java.io.Serializable; |
|
5 |
import javax.servlet.http.HttpServletRequest; |
|
6 |
import javax.servlet.http.HttpServletResponse; |
|
7 |
import org.springframework.security.core.AuthenticationException; |
|
8 |
import org.springframework.security.web.AuthenticationEntryPoint; |
|
9 |
import org.springframework.stereotype.Component; |
|
10 |
import com.alibaba.fastjson2.JSON; |
|
11 |
import com.jcdm.common.constant.HttpStatus; |
|
12 |
import com.jcdm.common.core.domain.AjaxResult; |
|
13 |
import com.jcdm.common.utils.ServletUtils; |
|
14 |
import com.jcdm.common.utils.StringUtils; |
|
15 |
|
|
16 |
/** |
|
17 |
* 认证失败处理类 返回未授权 |
|
18 |
* |
|
19 |
* @author jc |
|
20 |
*/ |
|
21 |
@Component |
|
22 |
public class AuthenticationEntryPointImpl implements AuthenticationEntryPoint, Serializable |
|
23 |
{ |
|
24 |
private static final long serialVersionUID = -8970718410437077606L; |
|
25 |
|
|
26 |
@Override |
|
27 |
public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException e) |
|
28 |
throws IOException |
|
29 |
{ |
|
30 |
int code = HttpStatus.UNAUTHORIZED; |
|
31 |
String msg = StringUtils.format("请求访问:{},认证失败,无法访问系统资源", request.getRequestURI()); |
|
32 |
ServletUtils.renderString(response, JSON.toJSONString(AjaxResult.error(code, msg))); |
|
33 |
} |
|
34 |
} |