Search in sources :

Example 41 with ApiException

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;
}
Also used : ApiResponseElement(org.zaproxy.zap.extension.api.ApiResponseElement) ApiResponseList(org.zaproxy.zap.extension.api.ApiResponseList) HashMap(java.util.HashMap) ApiResponse(org.zaproxy.zap.extension.api.ApiResponse) ApiException(org.zaproxy.zap.extension.api.ApiException)

Example 42 with ApiException

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;
}
Also used : ApiResponseElement(org.zaproxy.zap.extension.api.ApiResponseElement) ApiResponseList(org.zaproxy.zap.extension.api.ApiResponseList) HashMap(java.util.HashMap) ApiResponse(org.zaproxy.zap.extension.api.ApiResponse) ApiException(org.zaproxy.zap.extension.api.ApiException)

Example 43 with ApiException

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);
    }
}
Also used : Message(org.zaproxy.zap.extension.httppanel.Message) HttpMessage(org.parosproxy.paros.network.HttpMessage) ApiResponseElement(org.zaproxy.zap.extension.api.ApiResponseElement) HttpMessage(org.parosproxy.paros.network.HttpMessage) ApiException(org.zaproxy.zap.extension.api.ApiException)

Example 44 with ApiException

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);
    }
}
Also used : Context(org.zaproxy.zap.model.Context) User(org.zaproxy.zap.users.User) ApiResponseElement(org.zaproxy.zap.extension.api.ApiResponseElement) ApiException(org.zaproxy.zap.extension.api.ApiException)

Aggregations

ApiException (org.zaproxy.zap.extension.api.ApiException)44 Context (org.zaproxy.zap.model.Context)18 ApiResponseElement (org.zaproxy.zap.extension.api.ApiResponseElement)12 ApiResponseList (org.zaproxy.zap.extension.api.ApiResponseList)12 JSONObject (net.sf.json.JSONObject)11 DatabaseException (org.parosproxy.paros.db.DatabaseException)10 User (org.zaproxy.zap.users.User)9 ApiDynamicActionImplementor (org.zaproxy.zap.extension.api.ApiDynamicActionImplementor)8 HashMap (java.util.HashMap)7 PatternSyntaxException (java.util.regex.PatternSyntaxException)6 JSONException (net.sf.json.JSONException)6 HttpMalformedHeaderException (org.parosproxy.paros.network.HttpMalformedHeaderException)6 ApiResponse (org.zaproxy.zap.extension.api.ApiResponse)6 GenericScanner2 (org.zaproxy.zap.model.GenericScanner2)6 ArrayList (java.util.ArrayList)5 ConfigurationException (org.apache.commons.configuration.ConfigurationException)5 ExtensionUserManagement (org.zaproxy.zap.extension.users.ExtensionUserManagement)5 URIException (org.apache.commons.httpclient.URIException)4 Plugin (org.parosproxy.paros.core.scanner.Plugin)4 Session (org.parosproxy.paros.model.Session)4