简体   繁体   English

Java WebSocket API:将服务限制到某些域

[英]Java WebSocket API: Restrict service to certain domains

As mentioned eg in the HTML5Rocks WebSockets tutorial , HTML5Rocks WebSockets教程中所述

The server decides whether to make its service available to all clients or only those that reside on a set of well defined domains. 服务器决定是使其服务对所有客户端还是仅对驻留在一组定义良好的域上的客户端可用。

Ok, how to do that with the Java API for WebSocket 1.0 (JSR 356) (running on Tomcat )? 好的,如何使用Java API for WebSocket 1.0(JSR 356) (在Tomcat上运行)呢?

See ServerEndpointConfig.Configurator#checkOrigin 请参阅ServerEndpointConfig.Configurator#checkOrigin

Once registered, checkOrigin method will be called with "Origin" http header value as a parameter and then you can return true if its ok, or false, which should result in HTTP 403 - Origin not verified. 注册后,将使用“ Origin” http标头值作为参数调用checkOrigin方法,然后如果确定正确,则可以返回true,否则返回false,这将导致HTTP 403-Origin not authenticated。

(please ignore any references to project Tyrus in javadoc, API (javax.websocket.*) is the same for all implementations). (请忽略在Javadoc中对项目Tyrus的任何引用,API(javax.websocket。*)对于所有实现都是相同的)。

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

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