use of org.zaproxy.zap.extension.api.ApiException in project zaproxy by zaproxy.
the class RuleConfigAPI method handleApiView.
@Override
public ApiResponse handleApiView(String name, JSONObject params) throws ApiException {
ApiResponse result;
switch(name) {
case VIEW_RULE_CONFIG_VALUE:
RuleConfig rc = extension.getRuleConfig(params.getString(PARAM_KEY));
if (rc != null) {
result = new ApiResponseElement(name, rc.getValue());
} else {
throw new ApiException(ApiException.Type.DOES_NOT_EXIST, PARAM_KEY);
}
break;
case VIEW_ALL_RULE_CONFIGS:
List<RuleConfig> allRules = extension.getAllRuleConfigs();
ApiResponseList resultList = new ApiResponseList(name);
for (RuleConfig rc2 : allRules) {
Map<String, String> map = new HashMap<>();
map.put("key", String.valueOf(rc2.getKey()));
map.put("defaultValue", rc2.getDefaultValue());
map.put("value", String.valueOf(rc2.getValue()));
if (Constant.messages.containsKey(rc2.getKey())) {
map.put("description", Constant.messages.getString(rc2.getKey()));
}
resultList.addItem(new ApiResponseSet<String>("ruleConfig", map));
}
result = resultList;
break;
default:
throw new ApiException(ApiException.Type.BAD_VIEW);
}
return result;
}
use of org.zaproxy.zap.extension.api.ApiException in project zaproxy by zaproxy.
the class PassiveScanAPI method handleApiView.
@Override
public ApiResponse handleApiView(String name, JSONObject params) throws ApiException {
ApiResponse result;
switch(name) {
case VIEW_SCAN_ONLY_IN_SCOPE:
result = new ApiResponseElement(name, Boolean.toString(extension.getPassiveScanParam().isScanOnlyInScope()));
break;
case VIEW_RECORDS_TO_SCAN:
result = new ApiResponseElement(name, String.valueOf(extension.getRecordsToScan()));
break;
case VIEW_SCANNERS:
List<PluginPassiveScanner> scanners = extension.getPluginPassiveScanners();
ApiResponseList resultList = new ApiResponseList(name);
for (PluginPassiveScanner scanner : scanners) {
Map<String, String> map = new HashMap<>();
map.put("id", String.valueOf(scanner.getPluginId()));
map.put("name", scanner.getName());
map.put("enabled", String.valueOf(scanner.isEnabled()));
map.put("alertThreshold", scanner.getLevel(true).name());
map.put("quality", scanner.getStatus().toString());
resultList.addItem(new ApiResponseSet<String>("scanner", map));
}
result = resultList;
break;
default:
throw new ApiException(ApiException.Type.BAD_VIEW);
}
return result;
}
use of org.zaproxy.zap.extension.api.ApiException in project zaproxy by zaproxy.
the class BreakAPI method handleApiView.
@Override
public ApiResponse handleApiView(String name, JSONObject params) throws ApiException {
if (VIEW_IS_BREAK_ALL.equals(name)) {
return new ApiResponseElement(name, Boolean.toString(extension.getBreakpointManagementInterface().isBreakAll()));
} else if (VIEW_IS_BREAK_REQUEST.equals(name)) {
return new ApiResponseElement(name, Boolean.toString(extension.getBreakpointManagementInterface().isBreakRequest()));
} else if (VIEW_IS_BREAK_RESPONSE.equals(name)) {
return new ApiResponseElement(name, Boolean.toString(extension.getBreakpointManagementInterface().isBreakResponse()));
} else if (VIEW_HTTP_MESSAGE.equals(name)) {
Message msg = extension.getBreakpointManagementInterface().getMessage();
if (msg == null) {
return new ApiResponseElement(name, "");
} else if (msg instanceof HttpMessage) {
HttpMessage httpMsg = (HttpMessage) msg;
StringBuilder sb = new StringBuilder();
if (extension.getBreakpointManagementInterface().isRequest()) {
sb.append(httpMsg.getRequestHeader().toString());
sb.append(httpMsg.getRequestBody().toString());
} else {
sb.append(httpMsg.getResponseHeader().toString());
sb.append(httpMsg.getResponseBody().toString());
}
return new ApiResponseElement(name, sb.toString());
}
throw new ApiException(ApiException.Type.BAD_TYPE);
} else {
throw new ApiException(ApiException.Type.BAD_VIEW);
}
}
use of org.zaproxy.zap.extension.api.ApiException in project zaproxy by zaproxy.
the class ForcedUserAPI method handleApiView.
@Override
public ApiResponse handleApiView(String name, JSONObject params) throws ApiException {
log.debug("handleApiView " + name + " " + params.toString());
switch(name) {
case VIEW_GET_FORCED_USER:
Context context = ApiUtils.getContextByParamId(params, PARAM_CONTEXT_ID);
User forcedUser = extension.getForcedUser(context.getIndex());
if (forcedUser != null)
return new ApiResponseElement("forcedUserId", Integer.toString(forcedUser.getId()));
else
return new ApiResponseElement("forcedUserId", "");
case VIEW_IS_FORCED_USER_MODE_ENABLED:
return new ApiResponseElement("forcedModeEnabled", Boolean.toString(extension.isForcedUserModeEnabled()));
default:
throw new ApiException(Type.BAD_VIEW);
}
}
Aggregations