当前位置: 首页 > news >正文

网站开发合同技术目标/今天刚刚发生的重大新闻

网站开发合同技术目标,今天刚刚发生的重大新闻,dede旅游网站源码,常州模板网站建设价格解释 AuthenticationEntryPoint简介 AuthenticationEntryPoint是Spring Security Web一个概念模型接口,顾名思义,他所建模的概念是:“认证入口点”。 它在用户请求处理过程中遇到认证异常时,被ExceptionTranslationFilter用于开启特定认证方…

解释

AuthenticationEntryPoint简介

AuthenticationEntryPointSpring Security Web一个概念模型接口,顾名思义,他所建模的概念是:“认证入口点”。
它在用户请求处理过程中遇到认证异常时,被ExceptionTranslationFilter用于开启特定认证方案(authentication schema)的认证流程。

AccessDeniedHandler

AccessDeniedHandler仅适用于已通过身份验证的用户。未经身份验证的用户的默认行为是重定向到登录页面(或适用于正在使用的身份验证机制的任何内容)。

 

1、匿名用户访问某个接口时

/*** @author yuguang* @date 2020/10/14 13:08* @desc 403 forbidden处理* 用来解决匿名用户访问无权限资源时的异常*/
@Component
public class MyAuthenticationEntryPoint implements AuthenticationEntryPoint {@Overridepublic void commence(HttpServletRequest request, HttpServletResponse response,AuthenticationException authException) throws IOException, ServletException {response.setStatus(HttpServletResponse.SC_FORBIDDEN);response.setCharacterEncoding("UTF-8");response.setContentType("application/json; charset=utf-8");PrintWriter out = response.getWriter();ObjectMapper objectMapper = new ObjectMapper();String errorMsg = objectMapper.writeValueAsString(BaseResult.error("没有权限"));out.write(errorMsg);out.flush();out.close();}
}

2、已经授权但是没有访问权限

/*** @author yuguang* @date 2020/10/14 12:04* @desc 403自定义返回json* 用来解决认证过的用户访问无权限资源时的异常*/
@Component
public class MyAccessDeniedHandler implements AccessDeniedHandler {@Overridepublic void handle(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, AccessDeniedException e) throws IOException {httpServletResponse.setStatus(HttpServletResponse.SC_FORBIDDEN);httpServletResponse.setHeader("Content-Type", "application/json;charset=utf-8");PrintWriter out = httpServletResponse.getWriter();ObjectMapper objectMapper = new ObjectMapper();String errorMsg = objectMapper.writeValueAsString(BaseResult.error("没有权限"));out.write(errorMsg);
//        out.write("{\"status\": \"error\", \"msg\":\"权限不足请联系管理员!!\"}");out.flush();out.close();}
}

3、配置

   @ResourceMyAccessDeniedHandler myAccessDeniedHandler;@Resourceprivate MyAuthenticationEntryPoint myAuthenticationEntryPoint;@Overridepublic void configure(HttpSecurity http) throws Exception {if (jwtProperties.getCsrfDisabled()) {http = http.csrf().disable();}http.cors()//.and().addFilterBefore(jwtAuthenticationTokenFilter, UsernamePasswordAuthenticationFilter.class)//todo 无权限时的处理.exceptionHandling().authenticationEntryPoint(myAuthenticationEntryPoint).accessDeniedHandler(myAccessDeniedHandler)....

4、测试

{

    "httpCode": 403,

    "reasonPhrase": null,

    "data": null,

    "extraData": null,

    "message": "没有权限"

}

http://www.jmfq.cn/news/5103847.html

相关文章:

  • 江苏屹峰建设网站/郑州seo关键词排名优化
  • 微信网站建设报价单/站长统计app下载免费
  • 济南网站建设公司电子商务网站/在线seo
  • 12306网站是阿里做的/排名优化怎么做
  • 贵阳网站设计阳光创信好吗/找培训机构的平台
  • 如何在大网站做外链/八百客crm系统登录入口
  • 查互做蛋白的网站/1688黄页大全进口
  • 同性性做视频网站/广州网站优化排名
  • 建设银行官方网站个人/公司的网站
  • 做一个推广网站多少钱/武汉网优化seo公司
  • 智慧团建登录入口官网电脑版/西安百度网站快速优化
  • 网站优化排名优化/网络营销推广活动
  • 360提交网站备案/什么平台引流最快
  • 百度的广告怎么免费发布/上海seo外包公司
  • 设计logo网站免/线下营销推广方式都有哪些
  • 全能网站建设/ip软件点击百度竞价推广
  • 政府网站字体/优化大师客服电话
  • 织梦下载网站模板/nba最新交易消息
  • 创网站需要什么/企业网站推广方案设计
  • 做网站需要服务器和什么软件/百度推广搜索排名
  • 怎样制作网站二维码/今日新闻国内大事件
  • 网站建设工资待遇/网上教育培训机构排名
  • 做视频的软件模板下载网站/seo搜索引擎优化步骤
  • 高价词网站源码/二级域名免费分发
  • 可以做puzzle的网站/网站seo招聘
  • 做电影种子下载网站违法吗/最新热搜榜
  • jsp做网站用到什么技术/兰州seo整站优化服务商
  • b2c平台是什么意思/苏州seo关键词优化推广
  • 设计师查询网站/google chrome浏览器
  • 在域名做网站/百度新闻