如何防止rsocket在spring引导中允许跨原点?

iyfjxgzm  于 2021-08-20  发布在  Java
关注(0)|答案(0)|浏览(136)

我的问题
我有一个使用rsockets的spring引导应用程序。
我的spring boot应用程序在端口8080上运行,我的前端(react.js)在端口3000上运行。
问题是我的前端没有被cors策略阻止。
这有点令人担忧,因为我希望在稍后部署应用程序时,cors策略会阻止其他来源。
我猜我在某种程度上允许rsocket配置中的所有源代码(见下文)。
我的rsocket配置

package com.example.server.api.rsocket.config;
import org.springframework.boot.autoconfigure.rsocket.RSocketProperties;
import org.springframework.boot.web.server.LocalServerPort;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.messaging.rsocket.RSocketRequester;
import org.springframework.messaging.rsocket.RSocketStrategies;
import reactor.core.publisher.Mono;

import java.net.URI;

@Configuration
public class RSocketConfiguration {
    @LocalServerPort
    private int port;

    @Bean
    public Mono<RSocketRequester> rSocketRequester(RSocketStrategies rSocketStrategies, RSocketProperties rSocketProps){
        RSocketRequester rSocketRequester = RSocketRequester.builder()
                .rsocketStrategies(rSocketStrategies)
                .websocket(getURI(rSocketProps));
        return Mono.just(rSocketRequester);
    }

    private URI getURI(RSocketProperties rSocketProps) {
        return URI.create(String.format("ws://localhost:%d%s",
                port, rSocketProps.getServer().getMappingPath()));
    }

}

我的问题
如何防止其他来源访问我的资源?
值得一提的是,我使用的是spring boot starter webflux,而不是spring boot starter web。

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题