spring-projects / spring-projects/spring-session
Allow subclassing of SessionRepositoryMessageInterceptor
Nobody has claimed this yet.
- 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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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