Skip to content

Instantly share code, notes, and snippets.

@yschimke
Created January 22, 2021 08:08
Show Gist options
  • Save yschimke/16a06e60e65b42f63d11db37d8f79d0c to your computer and use it in GitHub Desktop.
Save yschimke/16a06e60e65b42f63d11db37d8f79d0c to your computer and use it in GitHub Desktop.
@Configuration
@EnableRSocketSecurity
@EnableReactiveMethodSecurity
// https://spring.io/blog/2020/06/17/getting-started-with-rsocket-spring-security
class SecurityConfig {
@Bean
fun messageHandler(strategies: RSocketStrategies?): RSocketMessageHandler {
val mh = RSocketMessageHandler()
mh.argumentResolverConfigurer.addCustomResolver(AuthenticationPrincipalArgumentResolver())
mh.rSocketStrategies = strategies!!
return mh
}
@Bean fun userDetailsService(jwtDecoder: ReactiveJwtDecoder): ReactiveUserDetailsService {
// return JwtUserDetailsService(jwtDecoder)
return ReactiveUserDetailsService {
just(User.withUsername("yuri").roles("USER").build())
}
}
@Bean
fun authorizationToken(rsocket: RSocketSecurity): PayloadSocketAcceptorInterceptor {
return rsocket
.authorizePayload { authorize: AuthorizePayloadsSpec ->
authorize
// .route("runCommand").authenticated()
.anyExchange().permitAll()
}
.jwt { jwtSpec: RSocketSecurity.JwtSpec ->
jwtSpec.authenticationManager {
// TODO security disabled
it.isAuthenticated = true
just(it)
}
}
.build()
}
@Bean fun jwtDecoder(): ReactiveJwtDecoder {
return ReactiveJwtDecoder {
just(Jwt.withTokenValue(it).build())
}
// return ReactiveJwtDecoders
// .fromIssuerLocation("https://uaa.run.pivotal.io/oauth/token")
}
@Bean fun reactiveAuthenticationManager(): ReactiveAuthenticationManager {
return ReactiveAuthenticationManager {
just(it)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment