当用户不在任何不等于连接的命令中时,我想使用拦截器终止客户端连接,这是我的代码:
@Component
公共类WebSocketInterceptor扩展ChannelInterceptorAdapter {
@Override
public Message<?> preSend(Message<?> message, MessageChannel channel) throws AuthenticationException {
StompHeaderAccessor accessor = MessageHeaderAccessor.getAccessor(message, StompHeaderAccessor.class);
if (StompCommand.CONNECT == accessor.getCommand()) {
//user = authenticate and get user
accessor.setUser(user);
} else if (accessor.getUser() == null) {
//disconnect from web socket completely
}
return message;
}
}
我已经尝试抛出异常,但是它仍然允许客户端发送消息