Created
February 9, 2018 09:27
-
-
Save kwart/cd1da8b7dcbd0a287f6e906a439c28d2 to your computer and use it in GitHub Desktop.
Validating remote address in Hazelcast. We don't have information if the other side is member or client yet.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
// Usage: | |
Config config = new Config(); | |
SocketInterceptorConfig socketInterceptorConfig = new SocketInterceptorConfig(); | |
VerifyRemoteAddressInterceptor interceptor = new | |
VerifyRemoteAddressInterceptor(); | |
socketInterceptorConfig.setImplementation(interceptor).setEnabled(true); | |
config.getNetworkConfig().setSocketInterceptorConfig(socketInterceptorConfig); | |
Hazelcast.newHazelcastInstance(config); | |
*/ | |
public class VerifyRemoteAddressInterceptor implements MemberSocketInterceptor { | |
@Override | |
public void init(Properties properties) {} | |
@Override | |
public void onAccept(Socket acceptedSocket) throws IOException { | |
if (! customAddressVerificationService.isAllowed(acceptedSocket.getInetAddress())) { | |
throw new IOException("Connection not allowed"); | |
} | |
} | |
@Override | |
public void onConnect(Socket connectedSocket) throws IOException {} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment