1

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?

2 Answers 2

0

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.

Sign up to request clarification or add additional context in comments.

Comments

0

Something along the following lines should work:

@Configuration
@EnableRSocketSecurity
@EnableReactiveMethodSecurity
class RSocketSecurityConfiguration(val authenticationService: AuthenticationService) {

    @Bean
    fun authorization(security: RSocketSecurity): PayloadSocketAcceptorInterceptor {
        return security
                .authorizePayload {
                    it.route("route-A").hasRole("role-A")
                        .route("route-B").permitAll()
                }
                .simpleAuthentication(Customizer.withDefaults())
                .authenticationManager(authenticationService)
                .build()
    }
}

route-A is authenticated and requires role-A while route-B is publicly available.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.