EC2IpPermission[] perms = group.getIpPermissionSet();
for (EC2IpPermission perm : perms) {
// TODO: Fix kludges like this...
if (perm == null)
continue;
IpPermissionType param5 = new IpPermissionType();
param5.setIpProtocol(perm.getProtocol());
if (perm.getProtocol().equalsIgnoreCase("icmp")) {
param5.setFromPort(Integer.parseInt(perm.getIcmpType()));
param5.setToPort(Integer.parseInt(perm.getIcmpCode()));
} else {
param5.setFromPort(perm.getFromPort());
param5.setToPort(perm.getToPort());
}
// -> user groups
EC2SecurityGroup[] userSet = perm.getUserSet();
if (null == userSet || 0 == userSet.length) {
UserIdGroupPairSetType param8 = new UserIdGroupPairSetType();
param5.setGroups(param8);
} else {
for (EC2SecurityGroup secGroup : userSet) {
UserIdGroupPairSetType param8 = new UserIdGroupPairSetType();
UserIdGroupPairType param9 = new UserIdGroupPairType();
param9.setUserId(secGroup.getAccount());
param9.setGroupName(secGroup.getName());
param8.addItem(param9);
param5.setGroups(param8);
}
}
// -> or CIDR list
String[] rangeSet = perm.getIpRangeSet();
if (null == rangeSet || 0 == rangeSet.length) {
IpRangeSetType param6 = new IpRangeSetType();
param5.setIpRanges(param6);
} else {
for (String range : rangeSet) {
// TODO: This needs further attention...
IpRangeSetType param6 = new IpRangeSetType();
if (range != null) {
IpRangeItemType param7 = new IpRangeItemType();
param7.setCidrIp(range);
param6.addItem(param7);
}
param5.setIpRanges(param6);
}
}
param4.addItem(param5);
}
param3.setIpPermissions(param4);