黄色网址大全免费-黄色网址你懂得-黄色网址你懂的-黄色网址有那些-免费超爽视频-免费大片黄国产在线观看

Spring Session教程
Spring Session常見的應用場景
Spring Session的執行流程
Session會話管理

Spring Session單點登錄

不同根域名下的項目實現Session共享,

比如阿里巴巴這樣的公司,有多個業務線,多個網站,用戶在一個網站登錄,那么其他網站也會是登錄了的狀態,比如:登錄了淘寶網,則天貓網也是登錄的;

www.taobao.com

www.tmall.com

比如:www.web.com www.p2p.com www.dai.com

對于不同根域名的場景,要實現一處登錄,處處登錄,Spring Session不支持;

單點登錄(Single Sign On),簡稱為 SSO,是目前比較流行的企業業務整合的解決方案之一。SSO的定義是在多個應用系統中,用戶只需要登錄一次就可以訪問所有相互信任的應用系統。目前市面上有很多實現單點登錄的方案,例如CAS,Token頒發校驗,Cookie+域名+路徑配置,在這里主要是想介紹一下第三種方案的實現方式。

概述
1. SpringSession提供了
• 一套管理ServletHttpSession的解決方案;
• 一臺Cluster Session的解決方案,默認使用外置的Redis存儲Session的方式解決Session共享的問題;

2. 相關網站:
• 官方網站:https://projects.spring.io/spring-session
• 文檔地址:https://docs.spring.io/spring-session/docs/current/reference/html5
• 源碼地址:https://github.com/spring-projects/spring-session

集成步驟

1. 導入maven(注意Spring的版本需要大于等于4.0.3,否在后面的過濾器會報異常):

<dependency>
    <groupId>org.springframework.session</groupId>
    <artifactId>spring-session-data-redis</artifactId>
    <version>1.2.0.RELEASE</version>
</dependency>

2. 添加過濾器SessionExpireFilter

<filter>
    <filter-name>sessionExpireFilter</filter-name>
    <filter-class>com.mmall.controller.common.SessionExpireFilter</filter-class>
</filter>
<filter-mapping>
    <filter-name>sessionExpireFilter</filter-name>
    <url-pattern>*.do</url-pattern>
</filter-mapping>

3. 在Spring的配置文件中添加配置:

<bean id="redisHttpSessionConfiguration" class="org.springframework.session.data.redis.config.annotation.web.http.RedisHttpSessionConfiguration">
    <property name="maxInactiveIntervalInSeconds" value="1800" />
</bean>
<bean id="jedisPoolConfig" class="redis.clients.jedis.JedisPoolConfig">
    <property name="maxTotal" value="20"/>
    <property name="maxIdle" value="10"/>
    <property name="minIdle" value="2"/>
    <property name="testOnBorrow" value="true"/>
    <property name="testOnReturn" value="false"/>
</bean>
<bean id="jedisConnectionFactory" class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory">
    <property name="hostName" value="127.0.0.1" />
    <property name="port" value="6379" />
    <property name="database" value="0"/>
    <property name="poolConfig" ref="jedisPoolConfig" />
</bean>

4. 添加單點登錄Session的各種配置:

<bean id="defaultCookieSerializer" class="org.springframework.session.web.http.DefaultCookieSerializer">
    <property name="cookieName" value="USER_KEY"/>
    <property name="domainName" value=".shreker.org"/>
    <property name="useHttpOnlyCookie" value="true"/> <!-- Only In Servlet3 -->
    <property name="cookiePath" value="/"/>
    <property name="cookieMaxAge" value="1800"/>
</bean>

5. 正常編寫session代碼(注意:這里的response.getData()返回的對象必須實現接口java.io.Serializable),如:

session.setAttribute(Consts.USER_IN_SESSION,response.getData());
session.getAttribute(Const.USER_IN_SESSION);
session.removeAttribute(Const.USER_IN_SESSION);

6. 完成配置,需要注意:

• Spring-Session通過代理攔截我們設置的session信息,并使用Jedis存儲到Redis上;

• Spring-Session在Redis上存儲的不止用戶的信息,還有兩個關聯的key;

• 當過期時間到時,Spring-Session會先去刪除關聯的key信息,最后過一段時間刪除真正存儲的用戶信息;

• Redis中,當關聯的key被刪除之后,真正的信息刪除之前的這一段時間里,我們也是無法獲取真正存儲在Redis中的信息的;

7. 使用到的相關的類:

• org.springframework.data.redis.connection.jedis.JedisConnectionFactory

• org.springframework.web.filter.DelegatingFilterProxy

•org.springframework.session.data.redis.config.annotation.web.http.RedisHttpSessionConfiguration

• org.springframework.session.web.http.DefaultCookieSerializer

• redis.clients.jedis.JedisPoolConfig

• org.springframework.session.web.http.SessionRepositoryFilter

• org.springframework.session.data.redis.RedisOperationsSessionRepository

• org.springframework.session.web.context.AbstractHttpSessionApplicationInitializer

• org.springframework.session.web.http.SessionRepositoryFilter.SessionRepositoryRequestWrapper

• org.springframework.session.web.http.SessionRepositoryFilter.SessionRepositoryResponseWrapper

• org.springframework.session.web.http.CookieHttpSessionStrategy

全部教程
主站蜘蛛池模板: 午夜羞羞 | 在线免费观看亚洲视频 | 99视频在线精品免费 | 黄色一级大片免费看 | 亚洲精品123区 | 欧美国产综合视频 | 久久毛片免费看一区二区三区 | 91成人高清在线播放 | 好男人www社区资源在线观看 | 免费看一级特黄a大片 | 有色视频在线观看 | 久久国产亚洲观看 | 国产日韩欧美一区二区 | 色视网| 97视频在线观看免费 | 欧美激情在线观看一区二区三区 | 免费羞羞网站 | 一级理论片免费观看在线 | 91在线 在线播放 | 亚洲一区中文字幕 | 91精品国产91热久久p | 国产欧美91 | 手机在线看片不卡中文字幕 | 国产精品麻豆一区二区 | 成人永久免费福利视频网站 | 精品亚洲成a人在线播放 | 91人前露出精品国产 | 欧美videosex娇小hd | 5g影院天天爽爽 | 久热精品男人的天堂在线视频 | caoporm国产精品视频免费 | 免费一看一级毛片人 | 曰韩精品 | 亚洲无限码 | 狠狠色噜噜综合社区 | 免费看的黄色录像 | 毛片又大又粗又长又硬 | 5g影院天天爽爽 | 毛片免费看看 | 日本一区二区免费在线观看 | 卡一卡二卡三免费专区2 |