@Test public void testInsecureSource() { final String subnet = "255.255.255.0"; final String network = "192.168.1.0"; final InetSocketAddress remoteAddress = new InetSocketAddress("192.168.2.4", 2727); final NetworkChannel channel = Mockito.mock(NetworkChannel.class); final NetworkGuard guard = new RestrictedNetworkGuard(network, subnet); final boolean secure = guard.isSecure(channel, remoteAddress); Assert.assertFalse(secure); }
@Override public boolean isSecure(NetworkChannel channel, InetSocketAddress source) { byte[] networkBytes = IPAddressCompare.addressToByteArrayV4(this.network); byte[] subnetBytes = IPAddressCompare.addressToByteArrayV4(this.subnet); boolean secure = IPAddressCompare.isInRangeV4(networkBytes, subnetBytes, source.getAddress().getAddress()); if (log.isTraceEnabled()) { log.trace("Is packet secure? " + secure + " [network=" + this.network + ", subnet=" + this.subnet + ", remote address=" + source.getAddress().getHostAddress() + "]"); } return secure; }
RestrictedNetworkGuard implements NetworkGuard { @Override public boolean isSecure(NetworkChannel channel, InetSocketAddress source) { byte[] networkBytes = IPAddressCompare.addressToByteArrayV4(this.network); byte[] subnetBytes = IPAddressCompare.addressToByteArrayV4(this.subnet); boolean secure = IPAddressCompare.isInRangeV4(networkBytes, subnetBytes, source.getAddress().getAddress()); if (log.isTraceEnabled()) { log.trace("Is packet secure? " + secure + " [network=" + this.network + ", subnet=" + this.subnet + ", remote address=" + source.getAddress().getHostAddress() + "]"); } return secure; } }
RestrictedNetworkGuard implements NetworkGuard { @Override public boolean isSecure(NetworkChannel channel, InetSocketAddress source) { byte[] networkBytes = IPAddressCompare.addressToByteArrayV4(this.network); byte[] subnetBytes = IPAddressCompare.addressToByteArrayV4(this.subnet); boolean secure = IPAddressCompare.isInRangeV4(networkBytes, subnetBytes, source.getAddress().getAddress()); if (log.isTraceEnabled()) { log.trace("Is packet secure? " + secure + " [network=" + this.network + ", subnet=" + this.subnet + ", remote address=" + source.getAddress().getHostAddress() + "]"); } return secure; } RestrictedNetworkGuard(String network, String subnet); }
RestrictedNetworkGuard implements NetworkGuard { @Override public boolean isSecure(NetworkChannel channel, InetSocketAddress source) { byte[] networkBytes = IPAddressCompare.addressToByteArrayV4(this.network); byte[] subnetBytes = IPAddressCompare.addressToByteArrayV4(this.subnet); boolean secure = IPAddressCompare.isInRangeV4(networkBytes, subnetBytes, source.getAddress().getAddress()); if (log.isTraceEnabled()) { log.trace("Is packet secure? " + secure + " [network=" + this.network + ", subnet=" + this.subnet + ", remote address=" + source.getAddress().getHostAddress() + "]"); } return secure; } RestrictedNetworkGuard(String network, String subnet); @Override boolean isSecure(NetworkChannel channel, InetSocketAddress source); }
RestrictedNetworkGuard implements NetworkGuard { @Override public boolean isSecure(NetworkChannel channel, InetSocketAddress source) { byte[] networkBytes = IPAddressCompare.addressToByteArrayV4(this.network); byte[] subnetBytes = IPAddressCompare.addressToByteArrayV4(this.subnet); boolean secure = IPAddressCompare.isInRangeV4(networkBytes, subnetBytes, source.getAddress().getAddress()); if (log.isTraceEnabled()) { log.trace("Is packet secure? " + secure + " [network=" + this.network + ", subnet=" + this.subnet + ", remote address=" + source.getAddress().getHostAddress() + "]"); } return secure; } RestrictedNetworkGuard(String network, String subnet); @Override boolean isSecure(NetworkChannel channel, InetSocketAddress source);  }