java – HTTPS上的Websockets 403 Forbidden

我目前正在尝试在 spring boot 1.2应用程序中设置HTTPS.此应用程序使用大量websockets在两个服务器之间进行通信.当它在简单的HTTP上运行时一切正常,但是当我将其切换到HTTPS时,我在Firefox和Chrome上都遇到403 Forbidden错误(尚未在IE上测试过.)我有一个SimpleCORSFilter设置,接受所有连接,所以我不要以为那是问题.通过HTTPS对同一服务器的所有RESTful请求都工作,它只是似乎被阻止的websockets.
这是我的WebSocket Spring配置
@Configuration
@EnableWebSocketMessagebroker
public class WebSocketConfig extends        
    AbstractWebSocketMessagebrokerConfigurer {
    @Override
    public void configureMessagebroker(MessagebrokerRegistry config) {
        config.enableSimplebroker("/topic");
        config.setApplicationDestinationPrefixes("/app");
    }
    @Override
    public void registerStompEndpoints(StompEndpointRegistry registry) {
        registry.addEndpoint("/simulation").withSockJS();
    }
}

这是我的前端websocket连接

socket = new SockJS(https://my.url + '/simulation');
   stompClient = Stomp.over(socket);
   stompClient.debug = false;
   stompClient.connect({},function(frame) {
        stompClient.subscribe('/topic/',function(status){
                  // Do something with result
        });
   });

编辑:这是Chrome控制台中的错误

GET https://localhost:8090/simulation/info 403 (Forbidden)
stomp.js:8 Whoops! Lost connection to undefined

编辑2:此错误似乎是最近从spring boot 1.1升级到spring boot 1.2的副作用.当我确定哪个依赖项导致错误时,我将更新.

解决方法

试试这个:
@Override
public void registerStompEndpoints(StompEndpointRegistry registry) {
    registry.addEndpoint("/simulation").setAllowedOrigins("*").withSockJS();
}

请注意,允许所有来源的来源可能会施加跨站请求伪造.有关防御方法,请参阅https://www.owasp.org/index.php/Cross-Site_Request_Forgery_(CSRF).

相关文章

最近看了一下学习资料,感觉进制转换其实还是挺有意思的,尤...
/*HashSet 基本操作 * --set:元素是无序的,存入和取出顺序不...
/*list 基本操作 * * List a=new List(); * 增 * a.add(inde...
/* * 内部类 * */ 1 class OutClass{ 2 //定义外部类的成员变...
集合的操作Iterator、Collection、Set和HashSet关系Iterator...
接口中常量的修饰关键字:public,static,final(常量)函数...