Examples of EC2AuthorizeRevokeSecurityGroup


Examples of com.cloud.bridge.service.core.ec2.EC2AuthorizeRevokeSecurityGroup

 
  /**
   * Authorize and Revoke Security Group Ingress have the same parameters.
   */
  private EC2AuthorizeRevokeSecurityGroup toSecurityGroup( String groupName, IpPermissionType[] items ) {
        EC2AuthorizeRevokeSecurityGroup request = new  EC2AuthorizeRevokeSecurityGroup();

        request.setName( groupName );
       
        for (IpPermissionType ipPerm : items) {
         EC2IpPermission perm = new EC2IpPermission();        
         perm.setProtocol( ipPerm.getIpProtocol());
         perm.setFromPort( ipPerm.getFromPort());
         perm.setToPort( ipPerm.getToPort());
   
         UserIdGroupPairSetType groups = ipPerm.getGroups();
         if (null != groups && groups.getItem() != null) {
           UserIdGroupPairType[] groupItems = groups.getItem();
           for (UserIdGroupPairType groupPair : groupItems) {
            EC2SecurityGroup user = new EC2SecurityGroup();
            user.setName( groupPair.getGroupName());
            user.setAccount( groupPair.getUserId());
            perm.addUser( user );
           }       
         }      
  
         IpRangeSetType ranges = ipPerm.getIpRanges();
         if (ranges != null && ranges.getItem() != null) {
           IpRangeItemType[] rangeItems = ranges.getItem();
           for (IpRangeItemType ipRange: rangeItems)
            perm.addIpRange( ipRange.getCidrIp() );
        
  
         request.addIpPermission( perm );
        }
        return request;
    }
View Full Code Here

Examples of com.cloud.bridge.service.core.ec2.EC2AuthorizeRevokeSecurityGroup

     * 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 { response.sendError(530, "Missing GroupName parameter" ); return; }

    EC2IpPermission perm = new EC2IpPermission();        

        String[] protocol = request.getParameterValues( "IpProtocol" );
    if ( null != protocol && 0 < protocol.length )
         perm.setProtocol( protocol[0] );
    else { response.sendError(530, "Missing IpProtocol parameter" ); return; }

        String[] fromPort = request.getParameterValues( "FromPort" );
      if ( null != fromPort && 0 < fromPort.length )
         perm.setProtocol( fromPort[0] );
    else { response.sendError(530, "Missing FromPort parameter" ); return; }

        String[] toPort = request.getParameterValues( "ToPort" );
    if ( null != toPort && 0 < toPort.length )
       perm.setProtocol( toPort[0] );
    else { response.sendError(530, "Missing ToPort parameter" ); return; }
               
      String[] ranges = request.getParameterValues( "CidrIp" );
    if ( null != ranges && 0 < ranges.length)
        perm.addIpRange( ranges[0] );
    else { response.sendError(530, "Missing CidrIp parameter" ); return; }
   
      String[] user = request.getParameterValues( "SourceSecurityGroupOwnerId" );
    if ( null == user || 0 == user.length) {
         response.sendError(530, "Missing SourceSecurityGroupOwnerId parameter" );
         return;
    }
 
    String[] name = request.getParameterValues( "SourceSecurityGroupName" );
    if ( null == name || 0 == name.length) {
         response.sendError(530, "Missing SourceSecurityGroupName parameter" );
         return;    
    }

    EC2SecurityGroup group = new EC2SecurityGroup();
    group.setAccount( user[0] );
    group.setName( name[0] );
    perm.addUser( group );
      EC2request.addIpPermission( perm )
   
      // -> execute the request
        RevokeSecurityGroupIngressResponse EC2response = EC2SoapServiceImpl.toRevokeSecurityGroupIngressResponse(
            ServiceProvider.getInstance().getEC2Engine().revokeSecurityGroup( EC2request ));
        serializeResponse(response, EC2response);
View Full Code Here

Examples of com.cloud.bridge.service.core.ec2.EC2AuthorizeRevokeSecurityGroup

    public AuthorizeSecurityGroupIngressResponse authorizeSecurityGroupIngress(AuthorizeSecurityGroupIngress authorizeSecurityGroupIngress) {
        AuthorizeSecurityGroupIngressType sgit = authorizeSecurityGroupIngress.getAuthorizeSecurityGroupIngress();
        IpPermissionSetType ipPerms = sgit.getIpPermissions();

        EC2AuthorizeRevokeSecurityGroup request = toSecurityGroup(sgit.getAuthorizeSecurityGroupIngressTypeChoice_type0().getGroupName(), ipPerms.getItem());
        return toAuthorizeSecurityGroupIngressResponse(engine.authorizeSecurityGroup(request));
    }
View Full Code Here

Examples of com.cloud.bridge.service.core.ec2.EC2AuthorizeRevokeSecurityGroup

    public RevokeSecurityGroupIngressResponse revokeSecurityGroupIngress(RevokeSecurityGroupIngress revokeSecurityGroupIngress) {
        RevokeSecurityGroupIngressType sgit = revokeSecurityGroupIngress.getRevokeSecurityGroupIngress();
        IpPermissionSetType ipPerms = sgit.getIpPermissions();

        EC2AuthorizeRevokeSecurityGroup request = toSecurityGroup(sgit.getRevokeSecurityGroupIngressTypeChoice_type0().getGroupName(), ipPerms.getItem());
        return toRevokeSecurityGroupIngressResponse(engine.revokeSecurityGroup(request));
    }
View Full Code Here

Examples of com.cloud.bridge.service.core.ec2.EC2AuthorizeRevokeSecurityGroup

    /**
     * Authorize and Revoke Security Group Ingress have the same parameters.
     */
    private EC2AuthorizeRevokeSecurityGroup toSecurityGroup(String groupName, IpPermissionType[] items) {
        EC2AuthorizeRevokeSecurityGroup request = new EC2AuthorizeRevokeSecurityGroup();

        request.setName(groupName);

        for (IpPermissionType ipPerm : items) {
            EC2IpPermission perm = new EC2IpPermission();
            perm.setProtocol(ipPerm.getIpProtocol());
            if (ipPerm.getIpProtocol().equalsIgnoreCase("icmp")) {
                perm.setIcmpType(Integer.toString(ipPerm.getFromPort()));
                perm.setIcmpCode(Integer.toString(ipPerm.getToPort()));
            } else {
                perm.setFromPort(ipPerm.getFromPort());
                perm.setToPort(ipPerm.getToPort());
            }
            UserIdGroupPairSetType groups = ipPerm.getGroups();
            if (null != groups && groups.getItem() != null) {
                UserIdGroupPairType[] groupItems = groups.getItem();
                for (UserIdGroupPairType groupPair : groupItems) {
                    EC2SecurityGroup user = new EC2SecurityGroup();
                    user.setName(groupPair.getGroupName());
                    user.setAccount(groupPair.getUserId());
                    perm.addUser(user);
                }
            }

            IpRangeSetType ranges = ipPerm.getIpRanges();
            if (ranges != null && ranges.getItem() != null) {
                IpRangeItemType[] rangeItems = ranges.getItem();
                for (IpRangeItemType ipRange : rangeItems) {
                    perm.addIpRange(ipRange.getCidrIp());
                    perm.setCIDR(ipRange.getCidrIp());
                }
            }

            request.addIpPermission(perm);
        }
        return request;
    }
View Full Code Here

Examples of com.cloud.bridge.service.core.ec2.EC2AuthorizeRevokeSecurityGroup

     * 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 { response.sendError(530, "Missing GroupName parameter" ); return; }

    EC2IpPermission perm = new EC2IpPermission();        

        String[] protocol = request.getParameterValues( "IpProtocol" );
    if ( null != protocol && 0 < protocol.length )
         perm.setProtocol( protocol[0] );
    else { response.sendError(530, "Missing IpProtocol parameter" ); return; }

        String[] fromPort = request.getParameterValues( "FromPort" );
      if ( null != fromPort && 0 < fromPort.length )
         perm.setProtocol( fromPort[0] );
    else { response.sendError(530, "Missing FromPort parameter" ); return; }

        String[] toPort = request.getParameterValues( "ToPort" );
    if ( null != toPort && 0 < toPort.length )
       perm.setProtocol( toPort[0] );
    else { response.sendError(530, "Missing ToPort parameter" ); return; }
               
      String[] ranges = request.getParameterValues( "CidrIp" );
    if ( null != ranges && 0 < ranges.length)
        perm.addIpRange( ranges[0] );
    else { response.sendError(530, "Missing CidrIp parameter" ); return; }
   
      String[] user = request.getParameterValues( "SourceSecurityGroupOwnerId" );
    if ( null == user || 0 == user.length) {
         response.sendError(530, "Missing SourceSecurityGroupOwnerId parameter" );
         return;
    }
 
    String[] name = request.getParameterValues( "SourceSecurityGroupName" );
    if ( null == name || 0 == name.length) {
         response.sendError(530, "Missing SourceSecurityGroupName parameter" );
         return;    
    }

    EC2SecurityGroup group = new EC2SecurityGroup();
    group.setAccount( user[0] );
    group.setName( name[0] );
    perm.addUser( group );
      EC2request.addIpPermission( perm )
   
      // -> execute the request
        RevokeSecurityGroupIngressResponse EC2response = EC2SoapServiceImpl.toRevokeSecurityGroupIngressResponse(
            ServiceProvider.getInstance().getEC2Engine().revokeSecurityGroup( EC2request ));
        serializeResponse(response, EC2response);
View Full Code Here

Examples of com.cloud.bridge.service.core.ec2.EC2AuthorizeRevokeSecurityGroup

    }

     private void authorizeSecurityGroupIngress( HttpServletRequest request, HttpServletResponse response )
        throws ADBException, XMLStreamException, IOException {
      // -> parse the complicated paramters into our standard object
        EC2AuthorizeRevokeSecurityGroup EC2request = new EC2AuthorizeRevokeSecurityGroup();

        String[] groupName = request.getParameterValues( "GroupName" );
    if ( null != groupName && 0 < groupName.length )
       EC2request.setName( groupName[0] );
    else { response.sendError(530, "Missing GroupName parameter" ); return; }

    // -> not clear how many parameters there are until we fail to get IpPermissions.n.IpProtocol
    int nCount = 1;
    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) perm.setProtocol( fromPort[0] );

            String[] toPort = request.getParameterValues( "IpPermissions." + nCount + ".ToPort" );
        if (null != toPort && 0 < toPort.length) perm.setProtocol( toPort[0] );
               
            // -> list: IpPermissions.n.IpRanges.m.CidrIp
      int 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
          String[] user = request.getParameterValues( "IpPermissions." + nCount + ".Groups." + mCount + ".UserId" );
           if ( null == user || 0 == user.length) break;
 
           String[] name = request.getParameterValues( "IpPermissions." + nCount + ".Groups." + mCount + ".GroupName" );
         if ( null == name || 0 == name.length) break;

         EC2SecurityGroup group = new EC2SecurityGroup();
         group.setAccount( user[0] );
         group.setName( name[0] );
         perm.addUser( group );
           mCount++;
          
          } while( true );
         
          // -> multiple IP permissions can be specified per group name
        EC2request.addIpPermission( perm )
        nCount++;
       
    } while( true );
   
    if (1 == nCount) { response.sendError(530, "At least one IpPermissions required" ); return; }
View Full Code Here

Examples of com.cloud.bridge.service.core.ec2.EC2AuthorizeRevokeSecurityGroup

 
  public AuthorizeSecurityGroupIngressResponse authorizeSecurityGroupIngress(AuthorizeSecurityGroupIngress authorizeSecurityGroupIngress) {
        AuthorizeSecurityGroupIngressType sgit = authorizeSecurityGroupIngress.getAuthorizeSecurityGroupIngress();       
        IpPermissionSetType ipPerms = sgit.getIpPermissions();
       
        EC2AuthorizeRevokeSecurityGroup request = toSecurityGroup( sgit.getGroupName(), ipPerms.getItem());
    return toAuthorizeSecurityGroupIngressResponse( engine.authorizeSecurityGroup( request ));
  }
View Full Code Here

Examples of com.cloud.bridge.service.core.ec2.EC2AuthorizeRevokeSecurityGroup

  public RevokeSecurityGroupIngressResponse revokeSecurityGroupIngress( RevokeSecurityGroupIngress revokeSecurityGroupIngress )
  {
        RevokeSecurityGroupIngressType sgit = revokeSecurityGroupIngress.getRevokeSecurityGroupIngress();       
        IpPermissionSetType ipPerms = sgit.getIpPermissions();
       
        EC2AuthorizeRevokeSecurityGroup request = toSecurityGroup( sgit.getGroupName(), ipPerms.getItem());
    return toRevokeSecurityGroupIngressResponse( engine.revokeSecurityGroup( request ));
  }
View Full Code Here

Examples of com.cloud.bridge.service.core.ec2.EC2AuthorizeRevokeSecurityGroup

 
  /**
   * Authorize and Revoke Security Group Ingress have the same parameters.
   */
  private EC2AuthorizeRevokeSecurityGroup toSecurityGroup( String groupName, IpPermissionType[] items ) {
        EC2AuthorizeRevokeSecurityGroup request = new  EC2AuthorizeRevokeSecurityGroup();

        request.setName( groupName );
       
        for (IpPermissionType ipPerm : items) {
         EC2IpPermission perm = new EC2IpPermission();        
         perm.setProtocol( ipPerm.getIpProtocol());
           if (ipPerm.getIpProtocol().equalsIgnoreCase("icmp")) {
               perm.setIcmpType( Integer.toString(ipPerm.getFromPort()));
               perm.setIcmpCode( Integer.toString(ipPerm.getToPort()));
           } else {
               perm.setFromPort( ipPerm.getFromPort());
               perm.setToPort( ipPerm.getToPort());
           }
         UserIdGroupPairSetType groups = ipPerm.getGroups();
         if (null != groups && groups.getItem() != null) {
           UserIdGroupPairType[] groupItems = groups.getItem();
           for (UserIdGroupPairType groupPair : groupItems) {
            EC2SecurityGroup user = new EC2SecurityGroup();
            user.setName( groupPair.getGroupName());
            user.setAccount( groupPair.getUserId());
            perm.addUser( user );
           }       
         }      
  
         IpRangeSetType ranges = ipPerm.getIpRanges();
         if (ranges != null && ranges.getItem() != null) {
           IpRangeItemType[] rangeItems = ranges.getItem();
                for (IpRangeItemType ipRange: rangeItems) {
                    perm.addIpRange( ipRange.getCidrIp() );
                    perm.setCIDR(ipRange.getCidrIp());
                }
         } 
  
         request.addIpPermission( perm );
        }
        return request;
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.