1
@ConnectMapping("setup")
public void setup(@AuthenticationPrincipal Principal principal) {
}
@MessageMapping("hello")
public void hello(@AuthenticationPrincipal Principal principal) {
}

The two mappings are on the server side.

When the RSocket client setup a connection with 'message/x.rsocket.authentication.v0' metadata,

and then send request to hello mapping.

The first principal is null.

The second principal is the expected authentication data.

How to resolve the principal in @ConnectMapping?

Gan
  • 188
  • 2
  • 7

2 Answers2

0

Work properly with spring-security-rsocket version 5.3.4.RELEASE

Gan
  • 188
  • 2
  • 7
0

You need to add message handler with custom resolver which will include AuthenticationPrincipalArgumentResolver from package org.springframework.security.messaging.handler.invocation.reactive

may need to add dependency

org.springframework.security:spring-security-messaging

to your maven/gradle

my example for kotlin:

@Bean
fun messageHandler(strategies: RSocketStrategies?): RSocketMessageHandler? {
    val handler = RSocketMessageHandler()
    handler.argumentResolverConfigurer.addCustomResolver(AuthenticationPrincipalArgumentResolver())
    handler.rSocketStrategies = strategies
    return handler
}
John Doe
  • 61
  • 5