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

做海报的网站什么编辑平台建设上线网站

做海报的网站什么编辑,平台建设上线网站,免费虚拟主机的好处,world做网站在SpringSecurity中,如果我们在认证或者授权的过程中出现了异常会被ExceptionTranslationFilter捕 获到。在ExceptionTranslationFilter中会去判断是认证失败还是授权失败出现的异常。 一、自定义验证异常类 创建exception包,在exception包下创建自定义…

在SpringSecurity中,如果我们在认证或者授权的过程中出现了异常会被ExceptionTranslationFilter捕 获到。在ExceptionTranslationFilter中会去判断是认证失败还是授权失败出现的异常。

一、自定义验证异常类

创建exception包,在exception包下创建自定义CustomerAuthenticationException类,继承 AuthenticationException类

/*** 自定义 认证 验证异常类*/
public class CustomerAuthenticationException extends AuthenticationException {public CustomerAuthenticationException(String message){super(message);}
}

二、登录用户访问无权限资源处理器

创建CustomerAccessDeniedHandler认证用户访问无权限资源时处理器类。

抓捕到AccessDeniedException异常后,进入此处理器

/*** 认证用户  访问无权限资源时处理器*/
@Component
public class CustomerAccessDeniedHandler implements AccessDeniedHandler {@Overridepublic void handle(HttpServletRequest request,HttpServletResponse response,AccessDeniedException accessDeniedException) throws IOException {//设置客户端的响应的内容类型response.setContentType("application/json;charset=UTF-8");//获取输出流ServletOutputStream outputStream = response.getOutputStream();//消除循环引用String result = JSON.toJSONString(R.error().code(700).message("无权限访问, 请联系管理员!"),SerializerFeature.DisableCircularReferenceDetect);outputStream.write(result.getBytes(StandardCharsets.UTF_8));outputStream.flush();outputStream.close();}
}

三、匿名用户访问资源处理器

/*** 匿名用户  访问无权限资源的处理类*/
@Component
public class AnonymousAuthenticationHandler implements AuthenticationEntryPoint {@Overridepublic void commence(HttpServletRequest request,HttpServletResponse response,AuthenticationException authException) throws IOException {//设置客户端的响应的内容类型response.setContentType("application/json;charset=UTF-8");String result = null;//获取输出流ServletOutputStream outputStream = response.getOutputStream();// System.out.println("异常消息:"+authException.getMessage()+",对象:"+authException);if (authException instanceof BadCredentialsException) {// 用户名未找到,可以在这里添加自定义处理逻辑result = JSON.toJSONString(R.error().code(HttpServletResponse.SC_UNAUTHORIZED).message(authException.getMessage()),SerializerFeature.DisableCircularReferenceDetect);} else if (authException instanceof InternalAuthenticationServiceException) {result = JSON.toJSONString(R.error().code(HttpServletResponse.SC_UNAUTHORIZED).message("用户名为空!"),SerializerFeature.DisableCircularReferenceDetect);} else {// 其他身份验证异常处理result = JSON.toJSONString(R.error().code(600).message("匿名用户无权限访问!"),SerializerFeature.DisableCircularReferenceDetect);  //消除循环引用}outputStream.write(result.getBytes(StandardCharsets.UTF_8));outputStream.flush();outputStream.close();}
}

四、改造认证校验过滤器 && 认证失败处理器

/*** 认证校验失败处理类*/
@Component
public class LoginFailureHandler implements AuthenticationFailureHandler {@Overridepublic void onAuthenticationFailure(HttpServletRequest request,HttpServletResponse response,AuthenticationException exception) throws IOException, ServletException {//设置客户端响应编码格式response.setContentType("application/json;charset=UTF-8");//获取输出流ServletOutputStream outputStream= response.getOutputStream();String message = null;//提示信息int code = 500;//错误编码//判断异常类型if(exception instanceof AccountExpiredException){message = "账户过期,登录失败!";}else if(exception instanceof BadCredentialsException){message = "用户名或密码错误,登录失败!";}else if(exception instanceof CredentialsExpiredException){message = "密码过期,登录失败!";}else if(exception instanceof DisabledException){message = "账户被禁用,登录失败!";}else if(exception instanceof LockedException){message = "账户被锁,登录失败!";}else if(exception instanceof InternalAuthenticationServiceException){message = "账户不存在,登录失败!";}else if(exception instanceof CustomerAuthenticationException){message = exception.getMessage();code = 600;}else{message = "登录失败!";}//将错误信息转换成JSONString result = JSON.toJSONString(R.error().code(code).message(message));outputStream.write(result.getBytes(StandardCharsets.UTF_8));outputStream.flush();outputStream.close();}
}

五、配置自定义处理器

http://www.yayakq.cn/news/891975/

相关文章:

  • 清远企业网站建设公司wordpress 边栏修改
  • 广州做网站 汉狮网络淮北官方网站
  • 三亚做网站推广东莞招聘网官方网站
  • 网站建设展板企业宣传视频制作免费版
  • 做一个小型网站多少钱WordPress留言板插件使用
  • 什么网站动物和人做的吗wordpress语言包插件
  • 东莞营销型网站建设国内做网站费用
  • 阳江市建设局网站软件服务外包
  • asp网站建设类论文wordpress易企秀
  • 网站建设步骤实践报告网站建设开场白怎么说
  • 男女朋友在一起做那个的网站柳州做网站那家好
  • 中英文网站开发会议网站
  • 网站开发工程师是什么内容安丘网站建设多少钱
  • 制作网站培训网站设计主页
  • 手机怎么创网站免费博山网站建设
  • 注册公司网站模板下载wordpress页面找不到该网页
  • 建设 春风 摩托车官方网站网站建设的具体过程
  • 宿迁房产网官方网站海尔网站建设
  • 网站后缀pw网络运维工程师薪酬
  • php做的商城网站设计论文wordpress tag 模板
  • 做网站说什么5.0啥意思网络技术培训机构
  • 温州建设网站公司重庆建设工程施工安全管理平台
  • 360安全网站怎么做号码认证dw做的网站要多大
  • 制作制作网站开发网站建设公制度
  • 企业网站开发服务器科技设计网站有哪些内容
  • 地方性资讯门户网站一般公司常用的邮箱
  • 同城同镇网站建设网站免费建站
  • 成都商城网站建设牧风的在wordpress
  • 山东手机网站建设电话网站作品欣赏
  • 国内外知名建设设计网站怎么做网站跟域名