|
26 | 26 | import java.util.regex.Matcher; |
27 | 27 | import java.util.regex.Pattern; |
28 | 28 |
|
| 29 | +import org.apache.cloudstack.acl.RoleType; |
29 | 30 | import org.apache.cloudstack.api.ApiConstants; |
30 | 31 | import org.apache.cloudstack.api.BaseCmd; |
31 | 32 | import org.apache.cloudstack.api.ResponseObject; |
|
34 | 35 | import org.apache.cloudstack.api.response.ExceptionResponse; |
35 | 36 | import org.apache.cloudstack.api.response.ListResponse; |
36 | 37 | import org.apache.cloudstack.api.response.SuccessResponse; |
| 38 | +import org.apache.cloudstack.context.CallContext; |
37 | 39 | import org.apache.log4j.Logger; |
38 | 40 |
|
39 | 41 | import com.cloud.api.ApiDBUtils; |
40 | 42 | import com.cloud.api.ApiResponseGsonHelper; |
41 | 43 | import com.cloud.api.ApiServer; |
| 44 | +import com.cloud.serializer.Param; |
| 45 | +import com.cloud.user.Account; |
42 | 46 | import com.cloud.utils.encoding.URLEncoder; |
43 | 47 | import com.cloud.utils.exception.CloudRuntimeException; |
44 | 48 | import com.cloud.utils.exception.ExceptionProxyObject; |
@@ -189,11 +193,31 @@ private static void serializeResponseObjFieldsXML(StringBuilder sb, ResponseObje |
189 | 193 | continue; // skip transient fields |
190 | 194 | } |
191 | 195 |
|
| 196 | + |
192 | 197 | SerializedName serializedName = field.getAnnotation(SerializedName.class); |
193 | 198 | if (serializedName == null) { |
194 | 199 | continue; // skip fields w/o serialized name |
195 | 200 | } |
196 | 201 |
|
| 202 | + Param param = field.getAnnotation(Param.class); |
| 203 | + if (param != null) { |
| 204 | + RoleType[] allowedRoles = param.authorized(); |
| 205 | + if (allowedRoles.length > 0) { |
| 206 | + boolean permittedParameter = false; |
| 207 | + Account caller = CallContext.current().getCallingAccount(); |
| 208 | + for (RoleType allowedRole : allowedRoles) { |
| 209 | + if (allowedRole.getValue() == caller.getType()) { |
| 210 | + permittedParameter = true; |
| 211 | + break; |
| 212 | + } |
| 213 | + } |
| 214 | + if (!permittedParameter) { |
| 215 | + s_logger.trace("Ignoring paremeter " + param.name() + " as the caller is not authorized to see it"); |
| 216 | + continue; |
| 217 | + } |
| 218 | + } |
| 219 | + } |
| 220 | + |
197 | 221 | field.setAccessible(true); |
198 | 222 | Object fieldValue = null; |
199 | 223 | try { |
|
0 commit comments