org.springframework.messaging.support.ChannelInterceptorAdapter Java Examples

The following examples show how to use org.springframework.messaging.support.ChannelInterceptorAdapter. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: WebSocketStompConfig.java    From Project with Apache License 2.0 5 votes vote down vote up
@Override
public void configureClientInboundChannel(ChannelRegistration registration) {
	registration.setInterceptors(new ChannelInterceptorAdapter() {

		@Override
		public Message<?> preSend(Message<?> message, MessageChannel channel) {
			System.out.println("configureClientInboundChannel");
			StompHeaderAccessor accessor = StompHeaderAccessor.wrap(message);
			User user = (User) accessor.getSessionAttributes().get("user");
			return super.preSend(message, channel);
		}
		
	});
}
 
Example #2
Source File: BusAutoConfigurationTests.java    From spring-cloud-bus with Apache License 2.0 5 votes vote down vote up
private ChannelInterceptor interceptor() {
	return new ChannelInterceptorAdapter() {
		@Override
		public void postSend(Message<?> message, MessageChannel channel,
				boolean sent) {
			OutboundMessageHandlerConfiguration.this.message = message;
			OutboundMessageHandlerConfiguration.this.latch.countDown();
		}
	};
}
 
Example #3
Source File: WebSocketConfig.java    From bearchoke with Apache License 2.0 5 votes vote down vote up
@Bean
public ChannelInterceptorAdapter sessionContextChannelInterceptorAdapter() {
    return new ChannelInterceptorAdapter() {
        @Override
        public Message<?> preSend(Message<?> message, MessageChannel channel) {
            StompHeaderAccessor accessor = StompHeaderAccessor.wrap(message);
            StompCommand command = accessor.getCommand();

            if (log.isDebugEnabled() && command != null) {
                log.debug("StompCommand: " + command.toString());
            }

            String authToken = accessor.getFirstNativeHeader(ServerConstants.X_AUTH_TOKEN);

            if (log.isDebugEnabled() && StringUtils.isNotEmpty(authToken)) {
                log.debug("Header auth token: " + authToken);
            }

            if (StringUtils.isNotBlank(authToken)) {

                // set cached authenticated user back in the spring security context
                Authentication authentication = preAuthAuthenticationManager.authenticate(new PreAuthenticatedAuthenticationToken(authToken, "N/A"));

                if (log.isDebugEnabled()) {
                    log.debug("Adding Authentication to SecurityContext for WebSocket call: " + authentication);
                }
                SpringSecurityHelper.setAuthentication(authentication);

            }
            return super.preSend(message, channel);
        }
    };
}