简体   繁体   English

如何防止在同一容器中部署的两个或多个不同应用程序之间传递HTML5本地存储数据?

[英]How to prevent passing HTML5 local storage data between two or more different applications which were deployed at the same container?

i have a big deal with user session monitoring. 我对用户会话监控非常重视。 I need to kill session after closing last application tab or after browser closing. 关闭最后一个应用程序选项卡或关闭浏览器后,我需要终止会话。

So, this work was performed. 因此,完成了这项工作。 I have developed small library for working with local storage and session storage and i developed mechanism for monitoring of opened browser tabs. 我已经开发了用于本地存储和会话存储的小型库,并且已经开发了用于监视打开的浏览器选项卡的机制。

Just simple object with tab counter. 只是带有Tab计数器的简单对象。

{
    "session_instance_count" : 0
}

And simple methods for writing this object to localstorage: 并将此对象写入本地存储的简单方法:

SessionMonitor.prototype.writeValueByKeyToLS = function (key, value){
   var own = this;
   own.getLocalStorageInstance().setItem(key, value);
};

SessionMonitor.prototype.getLocalStorageInstance = function () {
    return 'localStorage' in window && window['localStorage'];
};

But after deploying another application to Tomcat i have found serious troubles with local storage. 但是在将另一个应用程序部署到Tomcat之后,我发现本地存储存在严重问题。 All stored values from first application were available in second application. 来自第一个应用程序的所有存储的值在第二个应用程序中可用。

I stored some data on http://localhost:8080/app1 this data will be available on http://localhost:8080/app2 我在http:// localhost:8080 / app1上存储了一些数据,该数据将在http:// localhost:8080 / app2上可用

App1 sending request to open App2 with some parameters App1发送请求以打开带有某些参数的App2

Note: I do not have access to modify source code of second application. 注意:我无权修改第二个应用程序的源代码。

This is my question: 这是我的问题:

How to prevent passing HTML5 local storage data between two or more different applications which were deployed at the same container? 如何防止在同一容器中部署的两个或多个不同应用程序之间传递HTML5本地存储数据?

Solution with local storage was removed, because it's not provide possibilities for set data separately between applications inside one container with same domain pattern. 删除了具有本地存储的解决方案,因为它无法在具有相同域模式的一个容器内的应用程序之间单独设置数据。 I have checked solution with port configuring inside tomcat/conf/server.xml So we can set different ports to all deployed application. 我已经检查了在tomcat / conf / server.xml中配置端口的解决方案,因此我们可以为所有已部署的应用程序设置不同的端口。 Or we can register one more port for applications 或者我们可以为应用程序再注册一个端口

    <Connector port="8080" protocol="HTTP/1.1"
           connectionTimeout="20000"
           redirectPort="8443" />
    <Connector port="8086" protocol="HTTP/1.1"
       connectionTimeout="20000"
       redirectPort="8444" />

http://localhost:8080/app2 with http://localhost:8086/app1 http:// localhost:8080 / app2http:// localhost:8086 / app1

Local storages will be unique. 本地存储将是唯一的。 But i can't use this solution, because customer don't want this. 但是我不能使用此解决方案,因为客户不希望这样。

I found one more solution: relation between server side and client side. 我发现了另一个解决方案:服务器端和客户端之间的关系。

Just generating unique window.name and storing it inside server session. 只需生成唯一的window.name并将其存储在服务器会话中即可。 I hope, that it will be helpfull for somebody. 我希望这会对某人有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM