Skip to content

Spring Security Support #26

@InventorSingh

Description

@InventorSingh

Hello, Thank you for the great work. Could you please add spring security support with this example. I have tried using spring-security-rsocket and configuring PayloadSocketAcceptorInterceptor but is does not work.

Here is my security config:

@Configuration
@EnableRSocketSecurity
public class RsocketSecurityConfig {

    @Bean
    PayloadSocketAcceptorInterceptor rsocketInterceptor(RSocketSecurity rsocket) {
        return rsocket
                .authorizePayload(authorize ->
                        authorize
                                .route("*").authenticated()
                                .anyRequest().authenticated()
                                .anyExchange().authenticated()
                ).jwt(jwtSpec -> {
                    try {
                        jwtSpec.authenticationManager(jwtReactiveAuthenticationManager(reactiveJwtDecoder()));
                    } catch (Exception e) {
                        throw new RuntimeException(e);
                    }
                }).build();
    }

    @Bean
    ReactiveJwtDecoder reactiveJwtDecoder() {
        return ReactiveJwtDecoders
                .fromIssuerLocation("http://localhost:7475/auth/realms/devnation");
    }

    @Bean
    public JwtReactiveAuthenticationManager jwtReactiveAuthenticationManager(ReactiveJwtDecoder reactiveJwtDecoder) {
        JwtReactiveAuthenticationManager jwtReactiveAuthenticationManager = new JwtReactiveAuthenticationManager(reactiveJwtDecoder);

        JwtAuthenticationConverter authenticationConverter = new JwtAuthenticationConverter();
        JwtGrantedAuthoritiesConverter jwtGrantedAuthoritiesConverter = new JwtGrantedAuthoritiesConverter();
        jwtGrantedAuthoritiesConverter.setAuthorityPrefix("ROLE_");
        authenticationConverter.setJwtGrantedAuthoritiesConverter(jwtGrantedAuthoritiesConverter);
        jwtReactiveAuthenticationManager.setJwtAuthenticationConverter( new ReactiveJwtAuthenticationConverterAdapter(authenticationConverter));
        return jwtReactiveAuthenticationManager;
    }
}

I am still able to call hello-service methods from hello-client without any token. There is no error thrown.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions