Skip to content

Instantly share code, notes, and snippets.

@kwart
Created February 9, 2018 09:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kwart/cd1da8b7dcbd0a287f6e906a439c28d2 to your computer and use it in GitHub Desktop.
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.
/*
// 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