大战熟女丰满人妻av-荡女精品导航-岛国aaaa级午夜福利片-岛国av动作片在线观看-岛国av无码免费无禁网站-岛国大片激情做爰视频

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

全部教程
主站蜘蛛池模板: 免费看曰批女人爽的视频网址 | 老司机毛片 | 九九视频网站 | 久久久国产麻豆 | 色桃花网 | 亚洲福利精品一区二区三区 | www.av天天| 欧美成人h精品网站 | 久久精品视频5 | 麻豆国产高清精品国在线 | 99er久久| 麻豆一区二区三区在线观看 | 欧美一级免费观看 | 免费一级毛片无毒不卡 | 日韩一级黄色影片 | 欧美一级午夜免费视频你懂的 | 国产毛片女人18水多 | 精品视频国产 | 91视频这里只有精品 | 国产第一区二区三区在线观看 | 亚洲另类视频在线观看 | 日韩 欧美 亚洲 国产 | 又黄又爽又成人免费视频 | 8050午夜一级全黄毛片 | 亚洲精品午夜久久久伊人 | 久久综合九色综合亚洲小说 | 四虎影视884a精品国产古代 | 九九热在线视频观看这里只有精品 | 免费福利视频在线观看 | 久久dvd| 五月天亚洲婷婷 | 国产精品久久久久久久久久久久 | 亚洲综合九九 | 中文字幕中文字幕中中文 | 久久夜夜操 | 青草草在线观看免费视频 | 中文字幕天天躁夜夜狠狠综合 | 久久这里只有精品18 | 一级bbbbbbbbb毛片| 精品欧美日韩一区二区三区 | 99久久精品免费看国产四区 |