mirror of
https://gitee.com/beecue/fastbee.git
synced 2025-12-17 08:25:53 +08:00
修改bug-添加认证失败处理类 导致启用自定义认证会导致oauth授权地址不能访问
This commit is contained in:
@@ -93,7 +93,7 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter
|
||||
// CSRF禁用,因为不使用session
|
||||
.csrf().disable()
|
||||
// 认证失败处理类 TODO 启用自定义认证会导致oauth授权地址不能访问
|
||||
//.exceptionHandling().authenticationEntryPoint(unauthorizedHandler).and()
|
||||
.exceptionHandling().authenticationEntryPoint(unauthorizedHandler).and()
|
||||
// 基于token,所以不需要session
|
||||
.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS).and()
|
||||
// 过滤请求
|
||||
|
||||
@@ -27,8 +27,18 @@ public class AuthenticationEntryPointImpl implements AuthenticationEntryPoint, S
|
||||
public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException e)
|
||||
throws IOException
|
||||
{
|
||||
int code = HttpStatus.UNAUTHORIZED;
|
||||
String msg = StringUtils.format("请求访问:{},认证失败,无法访问系统资源", request.getRequestURI());
|
||||
ServletUtils.renderString(response, JSON.toJSONString(AjaxResult.error(code, msg)));
|
||||
if (isAjaxRequest(request)){
|
||||
int code = HttpStatus.UNAUTHORIZED;
|
||||
String msg = StringUtils.format("请求访问:{},认证失败,无法访问系统资源", request.getRequestURI());
|
||||
ServletUtils.renderString(response, JSON.toJSONString(AjaxResult.error(code, msg)));
|
||||
}else {
|
||||
response.sendRedirect("/oauth/login");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static boolean isAjaxRequest(HttpServletRequest request) {
|
||||
String ajaxFlag = request.getHeader("X-Requested-With");
|
||||
return ajaxFlag != null && "XMLHttpRequest".equals(ajaxFlag);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user