use of org.eclipse.kura.net.firewall.FirewallOpenPortConfigIP in project kura by eclipse.
the class GwtNetworkServiceImpl method updateDeviceFirewallOpenPorts.
@Override
public void updateDeviceFirewallOpenPorts(GwtXSRFToken xsrfToken, List<GwtFirewallOpenPortEntry> entries) throws GwtKuraException {
checkXSRFToken(xsrfToken);
NetworkAdminService nas = ServiceLocator.getInstance().getService(NetworkAdminService.class);
List<FirewallOpenPortConfigIP<? extends IPAddress>> firewallOpenPortConfigIPs = new ArrayList<FirewallOpenPortConfigIP<? extends IPAddress>>();
s_logger.debug("updating open ports");
try {
for (GwtFirewallOpenPortEntry entry : entries) {
String network = null;
String prefix = null;
if (entry.getPermittedNetwork() != null) {
String[] parts = entry.getPermittedNetwork().split("/");
network = parts[0];
prefix = parts[1];
}
FirewallOpenPortConfigIP<IP4Address> firewallOpenPortConfigIP = new FirewallOpenPortConfigIP4();
if (entry.getPortRange() != null) {
if (entry.getPortRange().indexOf(':') > 0) {
firewallOpenPortConfigIP.setPortRange(entry.getPortRange());
} else {
firewallOpenPortConfigIP.setPort(Integer.parseInt(entry.getPortRange()));
}
}
firewallOpenPortConfigIP.setProtocol(NetProtocol.valueOf(GwtSafeHtmlUtils.htmlEscape(entry.getProtocol())));
if (network != null && prefix != null) {
firewallOpenPortConfigIP.setPermittedNetwork(new NetworkPair<IP4Address>((IP4Address) IPAddress.parseHostAddress(network), Short.parseShort(prefix)));
}
firewallOpenPortConfigIP.setPermittedInterfaceName(GwtSafeHtmlUtils.htmlEscape(entry.getPermittedInterfaceName()));
firewallOpenPortConfigIP.setUnpermittedInterfaceName(GwtSafeHtmlUtils.htmlEscape(entry.getUnpermittedInterfaceName()));
firewallOpenPortConfigIP.setPermittedMac(GwtSafeHtmlUtils.htmlEscape(entry.getPermittedMAC()));
firewallOpenPortConfigIP.setSourcePortRange(GwtSafeHtmlUtils.htmlEscape(entry.getSourcePortRange()));
s_logger.debug("adding open port entry for {}", entry.getPortRange());
firewallOpenPortConfigIPs.add(firewallOpenPortConfigIP);
}
nas.setFirewallOpenPortConfiguration(firewallOpenPortConfigIPs);
} catch (KuraException e) {
s_logger.warn("Exception while updating firewall open ports", e);
throw new GwtKuraException(GwtKuraErrorCode.INTERNAL_ERROR, e);
} catch (NumberFormatException e) {
s_logger.warn("Exception while updating firewall open ports", e);
throw new GwtKuraException(GwtKuraErrorCode.INTERNAL_ERROR, e);
} catch (UnknownHostException e) {
s_logger.warn("Exception while updating firewall open ports", e);
throw new GwtKuraException(GwtKuraErrorCode.INTERNAL_ERROR, e);
}
}
Aggregations