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

阿里云服务器配置网站萍乡网站建设哪家好

阿里云服务器配置网站,萍乡网站建设哪家好,图书馆建设网站,做网站一般不选用的图片格式文章目录 1、用户认证流程AuthenticationSuccessHandler AuthenticationFailureHandlerSecurityFilterChain配置用户认证信息 2、会话并发处理2.1、实现处理器接口2.2、SecurityFilterChain配置 1、用户认证流程 AuthenticationSuccessHandler AuthenticationFailureHandler …

文章目录

    • 1、用户认证流程
      • AuthenticationSuccessHandler AuthenticationFailureHandler
      • SecurityFilterChain配置
      • 用户认证信息
    • 2、会话并发处理
      • 2.1、实现处理器接口
      • 2.2、SecurityFilterChain配置

1、用户认证流程

AuthenticationSuccessHandler AuthenticationFailureHandler

  • 登录成功后调用:AuthenticationSuccessHandler
  • 登录失败后调用:AuthenticationFailureHandler
    在这里插入图片描述

public class SecurityAuthenticationSuccessHandler implements AuthenticationSuccessHandler {@Overridepublic void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws IOException, ServletException {//获取用户身份信息Object principal = authentication.getPrincipal();//创建结果对象HashMap result = new HashMap();result.put("code", 0);result.put("message", "登录成功");result.put("data", principal);//转换成json字符串String json = JSON.toJSONString(result);//返回响应response.setContentType("application/json;charset=UTF-8");response.getWriter().println(json);}
}

SecurityFilterChain配置

form.successHandler(new SecurityAuthenticationSuccessHandler()) //认证成功时的处理

用户认证信息

@RestController
public class IndexController {@GetMapping("/")public Map index(){System.out.println("index controller");SecurityContext context = SecurityContextHolder.getContext();//存储认证对象的上下文Authentication authentication = context.getAuthentication();//认证对象String username = authentication.getName();//用户名Object principal =authentication.getPrincipal();//身份Object credentials = authentication.getCredentials();//凭证(脱敏)Collection<? extends GrantedAuthority> authorities = authentication.getAuthorities();//权限System.out.println(username);System.out.println(principal);System.out.println(credentials);System.out.println(authorities);//创建结果对象HashMap result = new HashMap();result.put("code", 0);result.put("data", username);return result;}
}

2、会话并发处理

后登录的账号会使先登录的账号失效

2.1、实现处理器接口

实现接口SessionInformationExpiredStrategy

package com.atguigu.securitydemo.config;public class MySessionInformationExpiredStrategy implements SessionInformationExpiredStrategy {@Overridepublic void onExpiredSessionDetected(SessionInformationExpiredEvent event) throws IOException, ServletException {//创建结果对象HashMap result = new HashMap();result.put("code", -1);result.put("message", "该账号已从其他设备登录");//转换成json字符串String json = JSON.toJSONString(result);HttpServletResponse response = event.getResponse();//返回响应response.setContentType("application/json;charset=UTF-8");response.getWriter().println(json);}
}

2.2、SecurityFilterChain配置

//会话管理
http.sessionManagement(session -> {session.maximumSessions(1).expiredSessionStrategy(new MySessionInformationExpiredStrategy());
});
http://www.yayakq.cn/news/150744/

相关文章:

  • 江西南昌电子商务网站建设公司快速建站php
  • 网站模板前台后台江苏建新建设集团有限公司网站
  • 如何登录中国建设银行网站江苏中益建设官方网站
  • 爱做的小说网站吗程序代码大全
  • cnzz网站建设教学网站建设合同制
  • 企业网站推广可以选择哪些方法天津做网站找津坤科技
  • 本省网站建设建议wordpress的主题上传了没有显示
  • 武威网站建设优化花钱也可以哪些网站可以做推广广告
  • iis 如何搭建网站加快信用网站建设
  • 云图书馆平台网站建设方案网站做成app
  • 类似织梦的建站cms分销平台app
  • 高清图片素材网站免费下载黎平网站开发
  • 优秀高端网站建设报价网站推广建站
  • 制作网站 美工游戏网官网
  • 网站建设过程的结构图网站字体颜色大小
  • 东营市建设局网站网页软件有哪些
  • 深圳制作网站培训学校移动端4060相当于桌面端什么显卡
  • 购物网站排名第一wordpress怎么解绑域名
  • ps网站建设教程怎么查看网页的html代码
  • 建设领域工人管理网站网站建设服务器对比
  • 做业精灵官方网站公司网站建设注意
  • 织梦网站更改网站的导航贴吧推广
  • 做php网站宁波网站建设rswl
  • 莱芜正规的网站建设如何做更改网站的图片
  • 昆明智能建站asp网站的配置
  • 家居企业网站建设机构山西网站设计
  • 廊坊企业网站建设创建论坛网站
  • 企业做网站公司排名口碑市场营销与网络营销
  • wordpress网站的CDN设置网站怎么制作 推广
  • 网站开发与设计论文重庆装修价格明细表