servlet域名通訊時(shí)與applet的安全問(wèn)題分析
web應(yīng)用中的一個(gè)jsp頁(yè)面的applet需要與服務(wù)器端的servlet通訊,直接ip,159.226.2.133,訪問(wèn)這一web應(yīng)用的jsp頁(yè)面,applet與servlet間的通信沒(méi)問(wèn)題。
但我通過(guò)域名,如http://www.abc.com來(lái)訪問(wèn)這一應(yīng)用,調(diào)用jsp頁(yè)面時(shí),applet會(huì)報(bào)如下錯(cuò)誤:
access denied (java.net.SocketPermission 159.226.2.133:80 connect,resolve)
java.security.AccessControlException: access denied (java.net.SocketPermission 159.226.2.133:80 connect,resolve)
at java.security.AccessControlContext.checkPermission(Unknown Source)
at java.security.AccessController.checkPermission(Unknown Source)
at java.lang.SecurityManager.checkPermission(Unknown Source)
at java.lang.SecurityManager.checkConnect(Unknown Source)
at sun.plugin2.applet.Applet2SecurityManager.checkConnect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at sun.net.NetworkClient.doConnect(Unknown Source)
at sun.net.www.http.HttpClient.openServer(Unknown Source)
at sun.net.www.http.HttpClient.openServer(Unknown Source)
at sun.net.www.http.HttpClient.<init>(Unknown Source)
at sun.net.www.http.HttpClient.New(Unknown Source)
at sun.net.www.http.HttpClient.New(Unknown Source)
也就是說(shuō)applet與后臺(tái)servlet連接時(shí)是通過(guò)ip連接的,而applet現(xiàn)在是出于域名環(huán)境下,這樣就造成了applet跨域訪問(wèn),破壞java安全性的情況。
從網(wǎng)上搜索,大家一般都是在客戶端jre中做些修改,或進(jìn)行數(shù)字簽名,來(lái)解決applet跨域訪問(wèn)問(wèn)題。
大家有什么辦法能避免造成applet跨域訪問(wèn)呢,因?yàn)閷?shí)際上applet和web應(yīng)用都是在一個(gè)環(huán)境下的,只是由于將這一應(yīng)用放在了域名下,造成這種問(wèn)題的
現(xiàn)在getHost()方法是能夠獲得域名的,但不知道為啥連接時(shí)applet總報(bào)上面提到的applet安全問(wèn)題