|
44 | 44 | import com.cloud.utils.HttpUtils; |
45 | 45 | import com.cloud.utils.NumbersUtil; |
46 | 46 | import com.cloud.utils.Pair; |
| 47 | +import com.cloud.utils.ReflectUtil; |
47 | 48 | import com.cloud.utils.StringUtils; |
48 | 49 | import com.cloud.utils.component.ComponentContext; |
49 | 50 | import com.cloud.utils.component.ManagerBase; |
|
65 | 66 | import org.apache.cloudstack.api.BaseAsyncCreateCmd; |
66 | 67 | import org.apache.cloudstack.api.BaseCmd; |
67 | 68 | import org.apache.cloudstack.api.BaseListCmd; |
| 69 | +import org.apache.cloudstack.api.Parameter; |
68 | 70 | import org.apache.cloudstack.api.ResponseObject; |
69 | 71 | import org.apache.cloudstack.api.ResponseObject.ResponseView; |
70 | 72 | import org.apache.cloudstack.api.ServerApiException; |
|
150 | 152 | import java.io.IOException; |
151 | 153 | import java.io.InterruptedIOException; |
152 | 154 | import java.lang.reflect.Type; |
| 155 | +import java.lang.reflect.Field; |
153 | 156 | import java.net.InetAddress; |
154 | 157 | import java.net.ServerSocket; |
155 | 158 | import java.net.Socket; |
@@ -430,8 +433,27 @@ public void handle(final HttpRequest request, final HttpResponse response, final |
430 | 433 | if (!(responseType.equals(HttpUtils.RESPONSE_TYPE_JSON) || responseType.equals(HttpUtils.RESPONSE_TYPE_XML))) { |
431 | 434 | responseType = HttpUtils.RESPONSE_TYPE_XML; |
432 | 435 | } |
433 | | - |
434 | 436 | try { |
| 437 | + //verify that parameter is legit for passing via admin port |
| 438 | + String[] command = (String[]) parameterMap.get("command"); |
| 439 | + if (command != null) { |
| 440 | + Class<?> cmdClass = getCmdClass(command[0]); |
| 441 | + if (cmdClass != null) { |
| 442 | + List<Field> fields = ReflectUtil.getAllFieldsForClass(cmdClass, BaseCmd.class); |
| 443 | + for (Field field : fields) { |
| 444 | + Parameter parameterAnnotation = field.getAnnotation(Parameter.class); |
| 445 | + if ((parameterAnnotation == null) || !parameterAnnotation.expose()) { |
| 446 | + continue; |
| 447 | + } |
| 448 | + Object paramObj = parameterMap.get(parameterAnnotation.name()); |
| 449 | + if (paramObj != null) { |
| 450 | + if (!parameterAnnotation.acceptedOnAdminPort()) { |
| 451 | + throw new ServerApiException(ApiErrorCode.ACCOUNT_ERROR, "Parameter " + parameterAnnotation.name() + " can't be passed through the API integration port"); |
| 452 | + } |
| 453 | + } |
| 454 | + } |
| 455 | + } |
| 456 | + } |
435 | 457 | // always trust commands from API port, user context will always be UID_SYSTEM/ACCOUNT_ID_SYSTEM |
436 | 458 | CallContext.register(accountMgr.getSystemUser(), accountMgr.getSystemAccount()); |
437 | 459 | sb.insert(0, "(userId=" + User.UID_SYSTEM + " accountId=" + Account.ACCOUNT_ID_SYSTEM + " sessionId=" + null + ") "); |
|
0 commit comments