spring-projects / spring-projects/spring-session

Allow subclassing of SessionRepositoryMessageInterceptor

Open
#219 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

status: waiting-for-triage
Dominant language
Java
Stars
1.9k
Forks
1.2k
Avg merge
4h 27m
Merged PRs (30d)
55

Description

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?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with SessionRepositoryMessageInterceptor and its class declaration, then inspect the configureClientInboundChannel example in the issue and the existing preSend override behavior. Done means the interceptor can be extended by WebSocketConfig while preserving the inherited message interception behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
authentication, backend
Issue type
Feature
Difficulty
1/5
Estimated time
Under an hour
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
50/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.