Weblogic跨域session沖突解決辦法


一、現象:

在WebLogic中,有兩個不同域A(端口:9000)和B(端口:8000),應用CA在域A中,應用CB在域B中,進行如下操作:

1、先登錄應用CA,再登錄應用CB,然后,切換回應用CA,發現應用CA的Session丟失;

2、應用CA中有指向應用CB的鏈接,登錄應用CA,點擊指向應用CB的鏈接,應用CA的Session丟失;

二、原因:

因Cookie沖突導致Session丟失。

Cookie的覆蓋機制:

如果一個新的cookie與一個已存在的cookie的NAME、Domain和Path屬性值均相同,則舊的cookie會被丟棄。(參考:http://code.google.com/p/browsersec/wiki/Part2#Same-origin_policy_for_cookies

WebLogic的Cookie相關配置:

屬性名

默認值
cookie-name JSESSIONID 如未設置,默認為“JSESSIONID”
cookie-path NULL 如未設置,默認為“/”
cookie-domain NULL 如未設置,默認為發放cookie的服務器的域

  由於沒有在Weblogic.xml配置文件中對cookie的相關屬性值進行配置,因此應用CA和應用CB的cookie的Name、 Domain和Path屬性值均為默認值,即Name為JSESSIONID,Path為“/”,Domain為服務器的IP地址,三個屬性值均相同,這 就造成了應用CA的cookie與應用CB的cookie會互相覆蓋,從而導致相應應用的session丟失。

三、解決辦法:

在Weblogic.xml配置文件中增加Cookie的相應屬性值的配置:

方法1:設置各應用的cookie的Name屬性為不同值

方法2:設置各應用的cookie的Path屬性為不同值(cookie的Path屬性值需與context-root值保持一 致,context-root若未在Weblogic.xml中指定則默認為部署的WAR包名或文件夾名,若同一Weblogic服務器不同域中的兩應用 context-root相同,則此方法不可行)

附注:雖然問題是在WebLogic下的不同域部署應用進行互訪的情況下發現的,但是,從問題產生的原因來看,在同一個域中的不同應用的互訪,如果未做cookie相關屬性值的配置,也會出現cookie沖突的問題。

 

四、WebLogic修改JSESSION方法(如修改為JSESSIONID1):

 

<?xml version="1.0" encoding="utf-8" ?>
<!--
<weblogic-web-app xmlns="http://www.bea.com/ns/weblogic/90" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
-->
<!--
<!DOCTYPE weblogic-web-app PUBLIC "-//BEA Systems, Inc.//DTD Web Application 8.1//EN" "http://www.bea.com/servers/wls810/dtd/weblogic810-web-jar.dtd">
-->
<wls:weblogic-web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:wls="http://www.bea.com/ns/weblogic/weblogic-web-app" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd http://www.bea.com/ns/weblogic/weblogic-web-app http://www.bea.com/ns/weblogic/weblogic-web-app/1.0/weblogic-web-app.xsd">
<!--
<weblogic-web-app>
-->
<wls:description>pis</wls:description>
    <wls:session-descriptor>
       <wls:timeout-secs>7200</wls:timeout-secs>
    <wls:cookie-name>JSESSIONID1</wls:cookie-name>
    <wls:encode-session-id-in-query-params>true</wls:encode-session-id-in-query-params>
 </wls:session-descriptor>
  <wls:context-root>pis</wls:context-root>
    <wls:container-descriptor>
    <wls:filter-dispatched-requests-enabled>true</wls:filter-dispatched-requests-enabled>
    <wls:index-directory-enabled>true</wls:index-directory-enabled>
 <wls:prefer-web-inf-classes>true</wls:prefer-web-inf-classes>  
  </wls:container-descriptor>
</wls:weblogic-web-app>

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM