自定义AccessDeniedHandler
/**
* @Author: jialing xu
* @Description: xvjialing@outlook.com
* @Date: 17:24 2018/8/7
*/
@Service
public class CustomAccessDeniedHandler implements AccessDeniedHandler { @Autowired
private ObjectMapper objectMapper; @Override
public void handle(HttpServletRequest request, HttpServletResponse response, AccessDeniedException accessDeniedException) throws IOException, ServletException {
response.setContentType("application/json;charset=UTF-8");
Map map = new HashMap();
map.put("code", "403");
map.put("msg", accessDeniedException.getMessage());
map.put("data","");
response.setContentType("application/json");
response.setStatus(HttpServletResponse.SC_OK);
response.getWriter().write(objectMapper.writeValueAsString(map));
}
}
将CustomAccessDeniedHandler加到configure中

@Autowired
CustomAccessDeniedHandler accessDeniedHandler; @Override
protected void configure(HttpSecurity http) throws Exception {
http.csrf().disable()
.requestMatchers().anyRequest()
.and()
.authorizeRequests()
.antMatchers("/oauth/**").permitAll()
.antMatchers("/actuator","/actuator/**").permitAll()
.and()
.exceptionHandling().accessDeniedHandler(accessDeniedHandler);
} }

最新文章

  1. Ioc和Ao使用扩展
  2. Android 框架学习之 第一天 okhttp & Retrofit
  3. 清北学堂模拟赛day7 数字碰撞
  4. OSG透明代码
  5. IBatis.Net学习笔记五--常用的查询方式
  6. Vue.js学习 Item1 --快速入门
  7. [MEAN Stack] First API -- 7. Using Route Files to Structure Server Side API
  8. Amazon Alexa 语音识别2 : 设置
  9. jquery.validate 以alert方式显示错误方法
  10. linux下写脚本时-gt是什么意思
  11. Linux 下安装配置 JDK1.7
  12. 从一个微型例子看“C/C++的内存分配机制”和“数组变量名与指针变量名”(转)
  13. 一 .isinstance(obj,cls)和issubclass(sub,super)
  14. vue :基本语法格式
  15. day10.函数进阶
  16. Qt-Designer打不开
  17. autoconf配置的项目,编译debug版本
  18. ORA-00600: internal error code, arguments: [4193]问题解决
  19. Linux 安装 iptables防火墙
  20. vue 学习笔记1

热门文章

  1. javascript基础修炼(12)——手把手教你造一个简易的require.js
  2. 什么是StatefulSet
  3. ASP.NET MVC教程八:_ViewStart.cshtml
  4. WPF TreeView 虚拟化-设置滚动到选中项
  5. 【SDUT】【链表】2120 - 数据结构实验之链表五:单链表的拆分
  6. Locust压测结果准确性验证
  7. Node JS爬虫: 阮老师网站背景图
  8. thinkphp 5.x No input file specified 解决
  9. USB免驱RFID读写器编程解析之一:智能卡篇
  10. 039.[转] 基于 Kubernetes 和 Spring Cloud 的微服务化实践