Search code examples
springkotlinrsocketspring-rsocket

How to make the path public in RSocketSecurity(Spring)


I have config class for RSocketSecurity Something like that

@Configuration
@EnableRSocketSecurity
@EnableReactiveMethodSecurity
class RSocketAuthConfiguration {

and authorization for it (allows only authenticated users to subscribe )

     security.addPayloadInterceptor(interceptor).authorizePayload {
        it.setup().authenticated().anyRequest().permitAll()
    }

I want to set some routes with public access, but most of them should be with authorization. What is the best way to achieve that?


Solution

  • Spring Security Rsocket configures the setup and route respectively.

    The following is an example of the configuration part.

    @Bean
    public PayloadSocketAcceptorInterceptor rsocketInterceptor(RSocketSecurity rsocket) {
            return rsocket
                    .authorizePayload(
                            authorize -> {
                                authorize
                                        // must have ROLE_SETUP to make connection
                                        .setup().hasRole("SETUP")
                                        // must have ROLE_ADMIN for routes starting with "greet."
                                        .route("greet*").hasRole("ADMIN")
                                        // any other request must be authenticated for
                                        .anyRequest().authenticated();
                            }
                    )
                    .basicAuthentication(Customizer.withDefaults())
                    .build();
        }
    

    Get the complete example from my Github.