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

个人网站设计策划书wordpress获取微信用户

个人网站设计策划书,wordpress获取微信用户,网站建设属于移动互联网,桂林网站定制目录 本节大纲 一、简介 二、会话并发管理 1. 简介 2. 开启会话管理 3. 测试会话管理 三、会话失效处理 1. 传统 web 开发处理 2. 前后端分离开发处理 四、禁止再次登录 五、会话共享 六、实战 1. 引入依赖 2. 编写配置 3. 配置Security 4. 测试 本节大纲 简介会…

目录

本节大纲

一、简介

二、会话并发管理

1. 简介

2. 开启会话管理

3. 测试会话管理

三、会话失效处理

1. 传统 web 开发处理

2. 前后端分离开发处理

四、禁止再次登录

五、会话共享

六、实战

1. 引入依赖

2. 编写配置

3. 配置Security

4. 测试


本节大纲

  • 简介
  • 会话并发管理
  • 会话共享实战

一、简介

当浏览器调用登录接口登录成功后,服务端会和浏览器之间建立一个会话 (Session) 浏览器在每次发送请求时都会

携带一个 Sessionld,服务端则根据这个 Sessionld 来判断用户身份。

当浏览器关闭后,服务端的 Session 并不会自动销毁,需要开发者手动在服务端调用Session销毁方法,或者等

Session 过期时间到了自动销毁。

在Spring Security 中,与HttpSession相关的功能由SessionManagementFiter 和

SessionAutheaticationStrateey 接口来处理,SessionManagomentFilter 过滤器将 Session 相关操作委托

给 SessionAuthenticationStrateey 接口去完成。

二、会话并发管理

1. 简介

会话并发管理就是指在当前系统中,同一个用户可以同时创建多少个会话,如果一个设备对应一个会话,那么也

可以简单理解为同一个用户可以同时在多少台设备上进行登录。默认情况下,同一用户在多少台设备上登录并没

有限制,不过开发者可以在 Spring Security 中对此进行配置。

2. 开启会话管理

@Configuration
public class SecurityConfig extends WebSecurityConfigurerAdapter {//...@Overrideprotected void configure(HttpSecurity http) throws Exception {http.authorizeRequests().anyRequest().authenticated().and().formLogin().and().rememberMe().and().csrf().disable().sessionManagement()  //开启会话管理.maximumSessions(1);  //设置会话并发数为 1}@Beanpublic HttpSessionEventPublisher httpSessionEventPublisher() {return new HttpSessionEventPublisher();}
}
  1. sessionManagement() 用来开启会话管理、maximumSessions 指定会话的并发数为 1。
  2. HttpSessionEventPublisher 提供一一个Htp SessionEvenePubishor-实例。
    Spring Security中通过一个 Map 集合来集护当前的 Http Session 记录,进而实现会话的并发管理。
    当用户登录成功时,就向集合中添加一条Http Session 记录;当会话销毁时,就从集合中移除一条 Httpsession 记录。
    HtpSesionEvenPublisher 实现了 Fttp SessionListener 接口,可以监听到 HtpSession 的创建和销毀事件,并将 Fltp Session 的创建/销毁事件发布出去,这样,当有 HttpSession 销毀时,Spring Security 就可以感知到该事件了。

3. 测试会话管理

配置完成后,启动项目。这次测试我们需要两个浏览器,如果使用了 Chrome 浏览器,可以使用 Chrome 浏览器

中的多用户方式(相当于两个浏览器)先在第一个浏览器中输入 http://localhost:8080,此时会自动跳转到登录

页面,完成登录操作,就可以访问到数据了;

接下来在第二个浏览器中也输入 http://localhost:8080,也需要登录,完成登录操作;当第二个浏览器登录成功

后,再回到第一个浏览器,刷新页面。

结果出现下图:

三、会话失效处理

1. 传统 web 开发处理

protected void configure(HttpSecurity http) throws Exception {http.authorizeRequests().anyRequest().authenticated().and().....sessionManagement()  //开启会话管理.maximumSessions(1)  //允许同一个用户只允许创建一个会话.expiredUrl("/login");//会话过期处理
}

2. 前后端分离开发处理

@Override
protected void configure(HttpSecurity http) throws Exception {http.authorizeRequests().anyRequest().authenticated()......sessionManagement()  //开启会话管理.maximumSessions(1)  //允许同一个用户只允许创建一个会话//.expiredUrl("/login")//会话过期处理  传统 web 开发.expiredSessionStrategy(event -> {HttpServletResponse response = event.getResponse();response.setContentType("application/json;charset=UTF-8");Map<String, Object> result = new HashMap<>();result.put("status", 500);result.put("msg", "当前会话已经失效,请重新登录!");String s = new ObjectMapper().writeValueAsString(result);response.setContentType("application/json;charset=UTF-8");response.getWriter().println(s);response.flushBuffer();});//前后端分离开发处理
}

四、禁止再次登录

默认的效果是一种被 “挤下线”的效果,后面登录的用户会把前面登录的用户 “挤下线”。

还有一种是禁止后来者登录,即一旦当前用户登录成功,后来者无法再次使用相同的用户登录,直到当前用户主

动注销登录,配置如下:

@Override
protected void configure(HttpSecurity http) throws Exception {http.authorizeRequests().anyRequest().authenticated().and().....sessionManagement()  //开启会话管理.maximumSessions(1)  //允许同一个用户只允许创建一个会话//.expiredUrl("/login")//会话过期处理  传统 web 开发.expiredSessionStrategy(event -> {HttpServletResponse response = event.getResponse();response.setContentType("application/json;charset=UTF-8");Map<String, Object> result = new HashMap<>();result.put("status", 500);result.put("msg", "当前会话已经失效,请重新登录!");String s = new ObjectMapper().writeValueAsString(result);response.getWriter().println(s);response.flushBuffer();})//前后端分离开发处理.maxSessionsPreventsLogin(true);//登录之后禁止再次登录
}

五、会话共享

前面所讲的会话管理都是单机上的会话管理,如果当前是集群环境,前面所讲的会话管理方案就会失效。

此时可以利用 spring-session 结合 redis 实现 session 共享。

六、实战

1. 引入依赖

<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
<dependency><groupId>org.springframework.session</groupId><artifactId>spring-session-data-redis</artifactId>
</dependency>

2. 编写配置

spring.redis.host=localhost
spring.redis.port=6379

3. 配置Security

package com.blr.config;import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.provisioning.InMemoryUserDetailsManager;
import org.springframework.session.FindByIndexNameSessionRepository;
import org.springframework.session.security.SpringSessionBackedSessionRegistry;import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.Map;@Configuration
public class SecurityConfig extends WebSecurityConfigurerAdapter {private final FindByIndexNameSessionRepository sessionRepository;@Autowiredpublic SecurityConfig(FindByIndexNameSessionRepository sessionRepository) {this.sessionRepository = sessionRepository;}@Beanpublic UserDetailsService userDetailsService() {....}@Overrideprotected void configure(AuthenticationManagerBuilder auth) throws Exception {auth.userDetailsService(userDetailsService());}@Overrideprotected void configure(HttpSecurity http) throws Exception {http.authorizeRequests().anyRequest().authenticated().and().formLogin().and().rememberMe().and().csrf().disable().sessionManagement()  //开启会话管理.maximumSessions(1)  //允许同一个用户只允许创建一个会话*/.expiredUrl("/login")//会话过期处理  传统 web 开发.expiredSessionStrategy(event -> {HttpServletResponse response = event.getResponse();response.setContentType("application/json;charset=UTF-8");Map<String, Object> result = new HashMap<>();result.put("status", 500);result.put("msg", "当前会话已经失效,请重新登录!");String s = new ObjectMapper().writeValueAsString(result);response.getWriter().println(s);response.flushBuffer();}).sessionRegistry(sessionRegistry());//前后端分离开发处理//.maxSessionsPreventsLogin(true);//登录之后禁止再次登录*/}@Beanpublic SpringSessionBackedSessionRegistry sessionRegistry() {return new SpringSessionBackedSessionRegistry(sessionRepository);}}

4. 测试


文章转载自:

http://gJLIM987.qnzpg.cn
http://S1bL0dNr.qnzpg.cn
http://sDqVnon5.qnzpg.cn
http://0mqqyYGC.qnzpg.cn
http://xNv5Pgtn.qnzpg.cn
http://UIV7LwjU.qnzpg.cn
http://VxNcECgT.qnzpg.cn
http://c9j7bbXB.qnzpg.cn
http://qBuV8iER.qnzpg.cn
http://tpqgK2u4.qnzpg.cn
http://48kJQjv4.qnzpg.cn
http://SC1b3mUy.qnzpg.cn
http://zwOUq9pK.qnzpg.cn
http://ecUBDvYS.qnzpg.cn
http://EqjjBXpT.qnzpg.cn
http://QvRQHLmE.qnzpg.cn
http://kJx0w8JH.qnzpg.cn
http://e6J2r5U2.qnzpg.cn
http://Kkh0obJS.qnzpg.cn
http://odaKFoOp.qnzpg.cn
http://zhLotaiC.qnzpg.cn
http://pCaNVBCg.qnzpg.cn
http://ubQ9ELYN.qnzpg.cn
http://i8mvnNqx.qnzpg.cn
http://XsvA8Wtd.qnzpg.cn
http://ocJrPt4h.qnzpg.cn
http://Abzp6MlM.qnzpg.cn
http://hoM5pppo.qnzpg.cn
http://ZM7O9crb.qnzpg.cn
http://Uz0PV2ZU.qnzpg.cn
http://www.dtcms.com/wzjs/686894.html

相关文章:

  • h5手机网站建设哪家好wordpress微信推送
  • 宿迁网站制作公司wordpress 置顶 插件
  • 电商平台网站多少钱工商营业执照查询网
  • 太原网站优化常识网站开发文本模版
  • 网站推广百度优化西山区建设局网站
  • 网站增加权重吗网站制作费用大概多少
  • 怎么建网站视频签名在线生成器
  • 番禺网站开发多少钱个人餐饮网站模板
  • 怎么用模板建网站wordpress全站静态化
  • 360网站制作潍坊wordpress文章显示摘要
  • 支付公司网站建设费账务处理许昌市建设路小学网站
  • 房产设计公司网站想做网站
  • 服务器如何架设网站汉化WORDPRESS聊天软件
  • 第一百四十七章 做视频网站怎样做百度口碑推广自己的网站
  • 宁夏微信网站建设wordpress表单提交 阿里云邮箱
  • 内黄县建设局网站郑州专业的网站建设公司哪家好
  • 专业网站快速江苏省建设厅 标准化网站
  • wordpress html5中文主题青岛谁优化网站做的好处
  • 自适应网站 响应式网站模板建设网站费用预算
  • 网站怎样注册备案东莞阳光网投诉电话
  • wordpress 网站赏析wordpress做在线编辑图片大小
  • 合肥网站推广公司排名wordpress 设置用户权限
  • 毕业设计做网站做内部网站cms
  • 清溪网站建设wordpress怎么ftp建站
  • 做网站都需要学什么网站规划模板
  • 怎么能查到网站是哪个公司做的wordpress edu2.0
  • 保定网站建设方案推广东莞网站平台费用
  • 如何建设网站盈利比价网站模板
  • 莱芜网站建设与管理企业vi设计是什么意思
  • 网站建立费用网页传奇开服表