Adding payload validation for global proxy

revert-dabc3590
Madawa Soysa 6 years ago
parent 601f527fb5
commit f19ce5f8e1

@ -21,6 +21,7 @@ package org.wso2.carbon.mdm.services.android.bean;
import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiModelProperty;
import org.apache.commons.lang.StringUtils;
import java.io.Serializable; import java.io.Serializable;
@ -66,6 +67,22 @@ public class GlobalProxy extends AndroidOperation implements Serializable {
) )
private String proxyPacUrl; private String proxyPacUrl;
public boolean validateRequest() {
if (ProxyType.MANUAL.equals(this.proxyConfigType)) {
if (StringUtils.isEmpty(this.proxyHost)) {
return false;
}
if (this.proxyPort < 0 || this.proxyPort > 65535) {
return false;
}
} else if (ProxyType.AUTO.equals(this.proxyConfigType)) {
if (StringUtils.isEmpty(proxyPacUrl)) {
return false;
}
}
return false;
}
public ProxyType getProxyConfigType() { public ProxyType getProxyConfigType() {
return proxyConfigType; return proxyConfigType;
} }

@ -995,6 +995,7 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe
} }
GlobalProxy globalProxy = globalProxyBeanWrapper.getOperation(); GlobalProxy globalProxy = globalProxyBeanWrapper.getOperation();
if (globalProxy.validateRequest()) {
ProfileOperation operation = new ProfileOperation(); ProfileOperation operation = new ProfileOperation();
operation.setCode(AndroidConstants.OperationCodes.GLOBAL_PROXY); operation.setCode(AndroidConstants.OperationCodes.GLOBAL_PROXY);
operation.setType(Operation.Type.PROFILE); operation.setType(Operation.Type.PROFILE);
@ -1003,6 +1004,12 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe
Activity activity = AndroidDeviceUtils Activity activity = AndroidDeviceUtils
.getOperationResponse(globalProxyBeanWrapper.getDeviceIDs(), operation); .getOperationResponse(globalProxyBeanWrapper.getDeviceIDs(), operation);
return Response.status(Response.Status.CREATED).entity(activity).build(); return Response.status(Response.Status.CREATED).entity(activity).build();
} else {
String errorMessage = "The payload of the global proxy operation is incorrect";
log.error(errorMessage);
throw new BadRequestException(
new ErrorResponse.ErrorResponseBuilder().setCode(400L).setMessage(errorMessage).build());
}
} catch (InvalidDeviceException e) { } catch (InvalidDeviceException e) {
String errorMessage = "Invalid Device Identifiers found."; String errorMessage = "Invalid Device Identifiers found.";
log.error(errorMessage, e); log.error(errorMessage, e);

Loading…
Cancel
Save