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

运动网站建设主题推广平台有哪些优势

运动网站建设主题,推广平台有哪些优势,免费小程序怎么赚钱,雅虎网站提交文章目录 前言简单介绍官方默认用户认证失败后处理器SimpleUrlAuthenticationSuccessHandlerForwardAuthenticationSuccessHandlerSavedRequestAwareAuthenticationSuccessHandler 自定义SecurityConfiguration 配置 前言 AuthenticationSuccessHandler 接口的作用是做用户认证… 文章目录 前言简单介绍官方默认用户认证失败后处理器SimpleUrlAuthenticationSuccessHandlerForwardAuthenticationSuccessHandlerSavedRequestAwareAuthenticationSuccessHandler 自定义SecurityConfiguration 配置 前言 AuthenticationSuccessHandler 接口的作用是做用户认证成功后执行的操作处理器官方目前是给了三个默认的处理器我们也可以自定义处理器接下来先简单介绍一下官方的然后再用一个小例子自定义一个自己的。 简单介绍官方默认用户认证失败后处理器 SimpleUrlAuthenticationSuccessHandler 认证成功后重定向到某个URL。 Override protected void configure(HttpSecurity http) throws Exception {CorsConfiguration configuration new CorsConfiguration();configuration.setAllowCredentials(true);http// 登录.formLogin()// 认证失败后处理器.successHandler(authenticationSuccessHandler()); }Bean public AuthenticationSuccessHandler authenticationSuccessHandler() {SimpleUrlAuthenticationSuccessHandlerhandler new SimpleUrlAuthenticationSuccessHandler();// 认证成功后重定向的URLhandler.setDefaultTargetUrl(/login-success);return handler; }ForwardAuthenticationSuccessHandler 认证成功后跳转到某个URL。 Override protected void configure(HttpSecurity http) throws Exception {CorsConfiguration configuration new CorsConfiguration();configuration.setAllowCredentials(true);http// 登录.formLogin()// 认证失败后处理器.successHandler(authenticationSuccessHandler()); }Bean public AuthenticationSuccessHandler authenticationSuccessHandler() {// 验证成功后跳转的URLreturn new ForwardAuthenticationSuccessHandler(/login-success); }SavedRequestAwareAuthenticationSuccessHandler 用户成功登录后执行操作它的特点是能够记住用户最初请求的URL并在登录成功后重定向用户回到这个URL。 比方说你在网上浏览找到了一个很有趣的视频链接点击进去后发现需要登录才能观看。你登录账号后网站自动跳转回你想看的那个视频而不是让你重新开始浏览。这里网站的登录系统就起到了 SavedRequestAwareAuthenticationSuccessHandler 的作用确保你在登录后可以直接观看之前选择的视频。 Override protected void configure(HttpSecurity http) throws Exception {CorsConfiguration configuration new CorsConfiguration();configuration.setAllowCredentials(true);http// 登录.formLogin()// 自定义登录页面.loginPage(/login)// 认证失败后处理器.successHandler(authenticationSuccessHandler()); }Bean public AuthenticationSuccessHandler authenticationSuccessHandler() {SavedRequestAwareAuthenticationSuccessHandler authSuccessHandler new SavedRequestAwareAuthenticationSuccessHandler();// 验证成功后默认跳转的URLauthSuccessHandler.setDefaultTargetUrl(/defaultPage);return authSuccessHandler; }自定义 package com.security.handler.auth;import com.alibaba.fastjson2.JSON; import com.security.controller.vo.ResponseResult; import lombok.extern.slf4j.Slf4j; import org.springframework.security.core.Authentication; import org.springframework.security.web.authentication.AuthenticationSuccessHandler; import org.springframework.stereotype.Component;import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.io.IOException;Component Slf4j public class AuthenticationSuccessHandlerImpl implements AuthenticationSuccessHandler {Overridepublic void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws IOException, ServletException {log.info(AuthenticationSuccessHandlerImpl 登录认证成功时调用 ...);/*** 设置响应状态值*/response.setStatus(200);response.setContentType(application/json);response.setCharacterEncoding(utf-8);// TODO 这里的 JSON 如果你有 Body 返回值的话可以不设置String json JSON.toJSONString(ResponseResult.builder().code(200).message(登录成功!).build());// JSON信息response.getWriter().println(json);} }SecurityConfiguration 配置 package com.security.config;import com.security.handler.auth.AuthenticationFailureHandlerImpl; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.security.authentication.AuthenticationManager; import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity; import org.springframework.security.config.annotation.web.builders.HttpSecurity; import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; import org.springframework.security.web.authentication.AuthenticationFailureHandler; import org.springframework.web.cors.CorsConfiguration;Configuration EnableWebSecurity // 开启限制访问资源所需权限 EnableGlobalMethodSecurity(prePostEnabled true) public class SecurityConfigurationTest extends WebSecurityConfigurerAdapter {Overrideprotected void configure(HttpSecurity http) throws Exception {CorsConfiguration configuration new CorsConfiguration();configuration.setAllowCredentials(true);http// 登录.formLogin()// 认证成功后处理器.successHandler(authenticationSuccessHandler());}Beanpublic AuthenticationSuccessHandler authenticationSuccessHandler() {// 自定义的成功后的处理器return new AuthenticationSuccessHandlerImpl();} }End
http://www.pierceye.com/news/894963/

相关文章:

  • html网页设计网站开发报告企业做的网站费入什么科目
  • 网站建设辶金手指排名十三郑州经济技术开发区教师招聘公告
  • 企业网站建设课程体会西安网站制作定制
  • 网站主题服务公司管理软件免费版
  • 网站建设主要职责六安网站建设
  • wordpress电影站主题一般做兼职在哪个网站
  • 可信网站友链怎么做网站建设行业标准
  • 济南营销网站制作公司哪家好口碑好的家装前十强
  • 公司网站开发费账务处理做图表的网站推荐
  • 网站如何做好用户体验wordpress 文章类
  • 做采集网站的方法世界四大广告公司
  • 做断桥铝窗户的网站宿州推广公司
  • 网站优化制作东莞房价一览表
  • 屏显的企业网站应该怎么做沈阳网站推广优化公司哪家好
  • 外包服务有哪些汕头seo网站建设
  • 新公司网站怎么做推广wordpress 中文 seo 插件
  • 网站建设客户分析国家企业信息公示网(广东)
  • php网站开发技术文档天津市装修公司排名榜
  • qq群优惠券里面网站怎么做的长春网站建设找源晟
  • 如何建一个公司的网站百度快速收录入口
  • 网络市场营销湘潭seo优化
  • 网站建设的模块传奇合成版2合1雷霆版手游
  • wordpress快站怎么样js网站开发视频
  • 滕州市 网站建设公司合肥网站建设方案案例
  • 外贸网站推广企业ida设计公司上海
  • 网站怎么做图片转链湄潭建设局官方网站
  • 泰州品牌网站建设二建报名时间2023年报名时间
  • 企业网站优化兴田德润怎么样wordpress标签不输出文章
  • 百度站长平台论坛永嘉网站制作
  • 月嫂公司网站建设构思免费的短视频素材库