Closed
Description
Discussed in #4012
Originally posted by ppussar February 8, 2023
Hi,
I am trying to implement a TCP Server, which does client certificate authentication on its connections. I added a TcpSocketSupport Bean as described in the documentation.
However I get a ClassCastException during the serverSocket cast, as it is still a ServerSocket and not a SSLServerSocket.
So I tryed (without success) to overwrite the TcpSocketFactorySupport Bean:
@Bean
public TcpSocketSupport tcpSocketSupport(serverProperties serverProperties) {
if (serverProperties.getSsl().isEnabled()) {
return new DefaultTcpSocketSupport() {
@Override
public void postProcessServerSocket(ServerSocket serverSocket) {
((SSLServerSocket) serverSocket).setNeedClientAuth(true);
}
};
} else {
return new DefaultTcpSocketSupport();
}
}
@Bean
public TcpSocketFactorySupport tcpSocketFactorySupport(
ServerProperties serverProperties,
TcpSSLContextSupport tcpSSLContextSupport) {
if (serverProperties.getSsl().isEnabled()) {
return new DefaultTcpNetSSLSocketFactorySupport(tcpSSLContextSupport);
} else {
return new DefaultTcpNetSocketFactorySupport();
}
}
But it has no effect. I guess it is not working as I am using the DSL syntax, which does not support SSL?:
IntegrationFlow.from(Tcp.inboundGateway(
Tcp.netServer(serverPort)
.tcpSocketSupport(tcpSocketSupport)
.deserializer(mySerde)
.serializer(mySerde)
.soTimeout(Integer.MAX_VALUE)
.singleUseConnections(false)
.mapper(tcpMessageMapper))
.id(TCP_GATEWAY_ID)
.errorChannel(ERROR_CHANNEL_NAME)
.replyChannel(REPLY_CHANNEL_NAME))
Is there a way to set the tcpSocketFactorySupport to DefaultTcpNetSSLSocketFactorySupport via DSL?