Search in sources :

Example 1 with LogicalOperator

use of org.zaproxy.zap.extension.authorization.BasicAuthorizationDetectionMethod.LogicalOperator in project zaproxy by zaproxy.

the class AuthorizationAPI method handleApiAction.

@Override
public ApiResponse handleApiAction(String name, JSONObject params) throws ApiException {
    log.debug("handleApiAction " + name + " " + params.toString());
    Context context;
    switch(name) {
        case ACTION_SET_AUTHORIZATION_METHOD:
            context = ApiUtils.getContextByParamId(params, PARAM_CONTEXT_ID);
            String headerRegex = params.optString(PARAM_HEADER_REGEX, null);
            String bodyRegex = params.optString(PARAM_BODY_REGEX, null);
            LogicalOperator logicalOperator = ApiUtils.getOptionalEnumParam(params, PARAM_LOGICAL_OPERATOR, LogicalOperator.class);
            if (logicalOperator == null) {
                logicalOperator = LogicalOperator.AND;
            }
            int statusCode = params.optInt(PARAM_STATUS_CODE, BasicAuthorizationDetectionMethod.NO_STATUS_CODE);
            if (log.isDebugEnabled()) {
                log.debug(String.format("Setting basic authorization detection to: %s / %s / %d / %s", headerRegex, bodyRegex, statusCode, logicalOperator));
            }
            BasicAuthorizationDetectionMethod method = new BasicAuthorizationDetectionMethod(statusCode, headerRegex, bodyRegex, logicalOperator);
            context.setAuthorizationDetectionMethod(method);
            return ApiResponseElement.OK;
        default:
            throw new ApiException(Type.BAD_ACTION);
    }
}
Also used : Context(org.zaproxy.zap.model.Context) LogicalOperator(org.zaproxy.zap.extension.authorization.BasicAuthorizationDetectionMethod.LogicalOperator) ApiException(org.zaproxy.zap.extension.api.ApiException)

Example 2 with LogicalOperator

use of org.zaproxy.zap.extension.authorization.BasicAuthorizationDetectionMethod.LogicalOperator in project zaproxy by zaproxy.

the class ContextAuthorizationPanel method saveMethod.

private void saveMethod() {
    Integer selectedStatusCode = (Integer) (statusCodeComboBox.getSelectedIndex() == 0 ? null : statusCodeComboBox.getSelectedItem());
    LogicalOperator selectedComposition = logicalOperatorComboBox.getSelectedItem().equals(FIELD_VALUE_AND_COMPOSITION) ? LogicalOperator.AND : LogicalOperator.OR;
    authorizationMethod = new BasicAuthorizationDetectionMethod(selectedStatusCode, headerPatternText.getText(), bodyPatternText.getText(), selectedComposition);
}
Also used : LogicalOperator(org.zaproxy.zap.extension.authorization.BasicAuthorizationDetectionMethod.LogicalOperator)

Aggregations

LogicalOperator (org.zaproxy.zap.extension.authorization.BasicAuthorizationDetectionMethod.LogicalOperator)2 ApiException (org.zaproxy.zap.extension.api.ApiException)1 Context (org.zaproxy.zap.model.Context)1