while (it.hasNext()) {
config = (ForwardingConfiguration) it.next();
if (config.getAddressToBind().equals(addressToBind) &&
(config.getPortToBind() == portToBind)) {
throw new ForwardingConfigurationException(
"The address and port are already in use!");
}
}
config = new ForwardingConfiguration(addressToBind, portToBind);
// Check the security mananger
SecurityManager manager = System.getSecurityManager();
if (manager != null) {
try {
manager.checkPermission(new SocketPermission(addressToBind +
":" + String.valueOf(portToBind), "accept,listen"));
} catch (SecurityException e) {
throw new ForwardingConfigurationException(
"The security manager has denied listen permision on " +
addressToBind + ":" + String.valueOf(portToBind));
}
}
try {
ForwardingListener listener = new ServerForwardingListener(connection,
addressToBind, portToBind);
remoteForwardings.add(listener);
listener.start();
} catch (IOException ex) {
throw new ForwardingConfigurationException(ex.getMessage());
}
}