@Override @DB @SuppressWarnings("rawtypes") @ActionEvent(eventType = EventTypes.EVENT_SECURITY_GROUP_AUTHORIZE_INGRESS, eventDescription = "Adding Ingress Rule ", async = true) public List<SecurityGroupRuleVO> authorizeSecurityGroupIngress(AuthorizeSecurityGroupIngressCmd cmd) { Long securityGroupId = cmd.getSecurityGroupId(); String protocol = cmd.getProtocol(); Integer startPort = cmd.getStartPort(); Integer endPort = cmd.getEndPort(); Integer icmpType = cmd.getIcmpType(); Integer icmpCode = cmd.getIcmpCode(); List<String> cidrList = cmd.getCidrList(); Map groupList = cmd.getUserSecurityGroupList(); return authorizeSecurityGroupRule(securityGroupId, protocol, startPort, endPort, icmpType, icmpCode, cidrList, groupList, SecurityRuleType.IngressRule); }
@Override public String getEventDescription() { StringBuilder sb = new StringBuilder(); if (getUserSecurityGroupList() != null) { sb.append("group list(group/account): "); Collection userGroupCollection = getUserSecurityGroupList().values(); Iterator iter = userGroupCollection.iterator(); HashMap userGroup = (HashMap)iter.next(); String group = (String)userGroup.get("group"); String authorizedAccountName = (String)userGroup.get("account"); sb.append(group + "/" + authorizedAccountName); while (iter.hasNext()) { userGroup = (HashMap)iter.next(); group = (String)userGroup.get("group"); authorizedAccountName = (String)userGroup.get("account"); sb.append(", " + group + "/" + authorizedAccountName); } } else if (getCidrList() != null) { sb.append("cidr list: "); sb.append(StringUtils.join(getCidrList(), ", ")); } else { sb.append("<error: no ingress parameters>"); } return "authorizing ingress to group: " + getSecurityGroupId() + " to " + sb.toString(); }
@Override public Long getInstanceId() { return getSecurityGroupId(); } }
public Long getSecurityGroupId() { if (securityGroupId != null && securityGroupName != null) { throw new InvalidParameterValueException("securityGroupId and securityGroupName parameters are mutually exclusive"); } if (securityGroupName != null) { securityGroupId = _responseGenerator.getSecurityGroupId(securityGroupName, getEntityOwnerId()); if (securityGroupId == null) { throw new InvalidParameterValueException("Unable to find security group " + securityGroupName + " for account id=" + getEntityOwnerId()); } securityGroupName = null; } if (securityGroupId == null) { throw new InvalidParameterValueException("Either securityGroupId or securityGroupName is required by authorizeSecurityGroupIngress command"); } return securityGroupId; }
@Override public void execute() { List<? extends SecurityRule> ingressRules = _securityGroupService.authorizeSecurityGroupIngress(this); if (ingressRules != null && !ingressRules.isEmpty()) { SecurityGroupResponse response = _responseGenerator.createSecurityGroupResponseFromSecurityGroupRule(ingressRules); setResponseObject(response); } else { throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to authorize security group ingress rule(s)"); } }