mirror of
https://gitee.com/beecue/fastbee.git
synced 2025-12-18 00:45:55 +08:00
@@ -93,7 +93,7 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter
|
|||||||
// CSRF禁用,因为不使用session
|
// CSRF禁用,因为不使用session
|
||||||
.csrf().disable()
|
.csrf().disable()
|
||||||
// 认证失败处理类 TODO 启用自定义认证会导致oauth授权地址不能访问
|
// 认证失败处理类 TODO 启用自定义认证会导致oauth授权地址不能访问
|
||||||
//.exceptionHandling().authenticationEntryPoint(unauthorizedHandler).and()
|
.exceptionHandling().authenticationEntryPoint(unauthorizedHandler).and()
|
||||||
// 基于token,所以不需要session
|
// 基于token,所以不需要session
|
||||||
.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS).and()
|
.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS).and()
|
||||||
// 过滤请求
|
// 过滤请求
|
||||||
|
|||||||
@@ -27,8 +27,18 @@ public class AuthenticationEntryPointImpl implements AuthenticationEntryPoint, S
|
|||||||
public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException e)
|
public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException e)
|
||||||
throws IOException
|
throws IOException
|
||||||
{
|
{
|
||||||
|
if (isAjaxRequest(request)){
|
||||||
int code = HttpStatus.UNAUTHORIZED;
|
int code = HttpStatus.UNAUTHORIZED;
|
||||||
String msg = StringUtils.format("请求访问:{},认证失败,无法访问系统资源", request.getRequestURI());
|
String msg = StringUtils.format("请求访问:{},认证失败,无法访问系统资源", request.getRequestURI());
|
||||||
ServletUtils.renderString(response, JSON.toJSONString(AjaxResult.error(code, msg)));
|
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