Skip to content

Allow subclassing of SessionRepositoryMessageInterceptor #219

@csavory

Description

@csavory

This issue could be related to #98

We are currently configuring a WebSocketMessageBroker by extending WebSocketMessageBrokerConfigurationSupport. The reason we are doing this is so we can attach the current user to the Spring Security Context. We do that with these two beans:

    @Bean
    public AbstractSubscribableChannel clientInboundChannel() {
        Executor securityExecutor = new DelegatingSecurityContextExecutor( clientInboundChannelExecutor() );
        ExecutorSubscribableChannel result = new ExecutorSubscribableChannel( securityExecutor );
        result.addInterceptor( securityContextChannelInterceptorAdapter() );
        return result;
    }

    @Bean
    public ChannelInterceptorAdapter securityContextChannelInterceptorAdapter() {
        return new SessionRepositoryMessageInterceptor() {

            @Override
            public Message<?> preSend( Message<?> message, MessageChannel channel ) {
                Authentication auth = (Authentication) SimpMessageHeaderAccessor.getUser( message.getHeaders() );
                SecurityContextHolder.getContext().setAuthentication( auth );
                return super.preSend( message, channel );
            }
        };
    }

I'm trying to follow the examples here: http://docs.spring.io/spring-session/docs/current/reference/html5/guides/websocket.html to integrate Spring session into our application. In order to do that, I would like to change our class definition to:

public class WebSocketConfig extends AbstractSessionWebSocketMessageBrokerConfigurer<ExpiringSession>

and then override this method like this:

    @Override
    public void configureClientInboundChannel(ChannelRegistration registration) {
        registration.setInterceptors(new SessionRepositoryMessageInterceptor<ExpiringSession>(sessionRepository) {

            @Override
            public Message<?> preSend( Message<?> message, MessageChannel channel ) {
                Authentication auth = (Authentication) SimpMessageHeaderAccessor.getUser( message.getHeaders() );
                SecurityContextHolder.getContext().setAuthentication( auth );
                return super.preSend( message, channel );
            }
        });
    }

But I can't because SessionRepositoryMessageInterceptor is final and can't be subclassed. Any chance you can change that class definition?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions