* The SOAP equivalent of this function appears to allow multiple permissions per request, yet
* in the REST API documentation only one permission is allowed.
*/
private void revokeSecurityGroupIngress( HttpServletRequest request, HttpServletResponse response )
throws ADBException, XMLStreamException, IOException {
EC2AuthorizeRevokeSecurityGroup EC2request = new EC2AuthorizeRevokeSecurityGroup();
String[] groupName = request.getParameterValues( "GroupName" );
if ( null != groupName && 0 < groupName.length )
EC2request.setName( groupName[0] );
else {
throw new EC2ServiceException( ClientError.MissingParamter, "Missing required parameter - GroupName");
}
// -> not clear how many parameters there are until we fail to get IpPermissions.n.IpProtocol
int nCount = 1, mCount;
do {
EC2IpPermission perm = new EC2IpPermission();
String[] protocol = request.getParameterValues( "IpPermissions." + nCount + ".IpProtocol" );
if ( null != protocol && 0 < protocol.length )
perm.setProtocol( protocol[0]);
else break;
String[] fromPort = request.getParameterValues( "IpPermissions." + nCount + ".FromPort" );
if ( null != fromPort && 0 < fromPort.length ) {
if ( protocol[0].equalsIgnoreCase("icmp") )
perm.setIcmpType( fromPort[0] ) ;
else
perm.setFromPort( Integer.parseInt( fromPort[0]) );
}
String[] toPort = request.getParameterValues( "IpPermissions." + nCount + ".ToPort" );
if ( null != toPort && 0 < toPort.length ) {
if ( protocol[0].equalsIgnoreCase("icmp") )
perm.setIcmpCode( toPort[0] );
else
perm.setToPort( Integer.parseInt( toPort[0]) );
}
// -> list: IpPermissions.n.IpRanges.m.CidrIp
mCount = 1;
do {
String[] ranges = request.getParameterValues( "IpPermissions." + nCount + ".IpRanges." + mCount + ".CidrIp" );
if ( null != ranges && 0 < ranges.length)
perm.addIpRange( ranges[0]);
else break;
mCount++;
} while( true );
// -> list: IpPermissions.n.Groups.m.UserId and IpPermissions.n.Groups.m.GroupName
mCount = 1;
do {
EC2SecurityGroup group = new EC2SecurityGroup();
String[] user = request.getParameterValues( "IpPermissions." + nCount + ".Groups." + mCount + ".UserId" );
if ( null != user && 0 < user.length)
group.setAccount( user[0]);
else break;
String[] name = request.getParameterValues( "IpPermissions." + nCount + ".Groups." + mCount + ".GroupName" );
if ( null != name && 0 < name.length)
group.setName( name[0]);
else break;
perm.addUser( group);
mCount++;
} while( true );
// -> multiple IP permissions can be specified per group name
EC2request.addIpPermission( perm);
nCount++;
} while( true );
if (1 == nCount) {
throw new EC2ServiceException( ClientError.MissingParamter, "Missing required parameter - IpPermissions");